1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

Disable SFrame support by default

And add extra checks to enable for binutils 2.45 and if the architecture
explicitly enables it.  When SFrame is disabled, all the related code
is also not enabled for backtrace() and _dl_find_object(), so SFrame
backtracking is not used even if the binary has the SFrame segment.

This patch also adds some other related fixes:

  * Fixed an issue with AC_CHECK_PROG_VER, where the READELF_SFRAME
    usage prevented specifying a different readelf through READELF
    environment variable at configure time.

  * Add an extra arch-specific internal definition,
    libc_cv_support_sframe, to disable --enable-sframe on architectures
    that have binutils but not glibc support (s390x).

  * Renamed the tests without the .sframe segment and move the
    tst-backtrace1 from pthread to debug.

  * Use the built compiler strip to remove the .sframe segment,
    instead of the system one (which might not support SFrame).

Checked on x86_64-linux-gnu and aarch64-linux-gnu.

Reviewed-by: Sam James <sam@gentoo.org>
This commit is contained in:
Adhemerval Zanella
2025-07-23 10:47:23 -03:00
committed by Andreas K. Hüttel
parent ce488f7c16
commit a12d72019e
17 changed files with 141 additions and 88 deletions

View File

@@ -286,14 +286,17 @@ LDFLAGS-tst-backtrace4 = -rdynamic
LDFLAGS-tst-backtrace5 = -rdynamic
LDFLAGS-tst-backtrace6 = -rdynamic
$(objpfx)tst-backtrace1: $(shared-thread-library)
# When SFrame is enabled, make sure the dwarf unwinder is also exercised.
ifeq ($(enable-gsframe),yes)
dw_unwind_pair := \
tst-backtrace7:tst-backtrace2 \
tst-backtrace8:tst-backtrace3 \
tst-backtrace9:tst-backtrace4 \
tst-backtrace10:tst-backtrace5 \
tst-backtrace11:tst-backtrace6
tst-backtrace1-nosframe:tst-backtrace1 \
tst-backtrace2-nosframe:tst-backtrace2 \
tst-backtrace3-nosframe:tst-backtrace3 \
tst-backtrace4-nosframe:tst-backtrace4 \
tst-backtrace5-nosframe:tst-backtrace5 \
tst-backtrace6-nosframe:tst-backtrace6
first_column = $(foreach pair,$(dw_unwind_pair),$(word 1,$(subst :, ,$(pair))))
tests-dw-unwind = $(patsubst %,$(objpfx)%.out,$(first_column))
@@ -302,7 +305,7 @@ endif
define make-strip-rule
$(objpfx)$(word 1,$(subst :, ,$(1))): $(objpfx)$(word 2,$(subst :, ,$(1)))
strip --remove-section=.sframe $$< -o $$@
$(STRIP) --remove-section=.sframe $$< -o $$@
endef
$(foreach pair,$(dw_unwind_pair),$(eval $(call make-strip-rule,$(pair))))
@@ -325,6 +328,7 @@ tests = \
backtrace-tst \
test-stpcpy_chk \
test-strcpy_chk \
tst-backtrace1 \
tst-backtrace2 \
tst-backtrace3 \
tst-backtrace4 \

View File

@@ -20,7 +20,9 @@
#include <stdlib.h>
#include <unwind.h>
#include <unwind-link.h>
#if ENABLE_SFRAME
#include <sframe.h>
#endif
struct trace_arg
{
@@ -31,6 +33,7 @@ struct trace_arg
int size;
};
#if ENABLE_SFRAME
/* Initialize the SFrame backtrace routine and attempt to backtrace
the current stack using SFrame information. For the SFrame
backtrace to be considered valid, the tracer must return more than
@@ -64,6 +67,7 @@ do_sframe_backtrace (void **array, int size)
frame.fp = (_Unwind_Ptr) __builtin_frame_address (0);
return __stacktrace_sframe (array, size, &frame);
}
#endif
static _Unwind_Reason_Code
backtrace_helper (struct _Unwind_Context *ctx, void *a)
@@ -110,10 +114,12 @@ __backtrace (void **array, int size)
if (size <= 0)
return 0;
#if ENABLE_SFRAME
/* Try first the SFrame backtracer. */
int cnt = do_sframe_backtrace (array, size);
if (cnt > 1)
return cnt;
#endif
/* Try the dwarf unwinder. */
if (arg.unwind_link == NULL)

84
debug/tst-backtrace1.c Normal file
View File

@@ -0,0 +1,84 @@
/* Copyright (C) 2004-2025 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <execinfo.h>
#include <pthread.h>
#include <stdio.h>
#define BT_SIZE 64
void *bt_array[BT_SIZE];
int bt_cnt;
int
do_bt (void)
{
bt_cnt = backtrace (bt_array, BT_SIZE);
return 56;
}
int
call_do_bt (void)
{
return do_bt () + 1;
}
void *
tf (void *arg)
{
if (call_do_bt () != 57)
return (void *) 1L;
return NULL;
}
int
do_test (void)
{
pthread_t th;
if (pthread_create (&th, NULL, tf, NULL))
{
puts ("create failed");
return 1;
}
void *res;
if (pthread_join (th, &res))
{
puts ("join failed");
return 1;
}
if (res != NULL)
{
puts ("thread failed");
return 1;
}
char **text = backtrace_symbols (bt_array, bt_cnt);
if (text == NULL)
{
puts ("backtrace_symbols failed");
return 1;
}
for (int i = 0; i < bt_cnt; ++i)
puts (text[i]);
return 0;
}
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"