From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5158 invoked from network); 16 Jul 2021 09:16:44 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 16 Jul 2021 09:16:44 -0000 Received: (qmail 32626 invoked by uid 550); 16 Jul 2021 09:16:41 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 32596 invoked from network); 16 Jul 2021 09:16:41 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version; bh=S/x4o5rK7IlfNnzN5Dc+k7GmufPkpeZ5nlTAEN2kPJ8=; b=KIlgJDASWsIQ+rBfUcRvjBe+tnlrSCiA+FSuD4wHQrce4AQGFHiyqRSuJnFJaIuWcC pqxRUyfYclhul5xoWfMcqwdvAMyLl/VJLxt6dbyno9N2t4uQWR2MsKTsslyMuFo1IZtK bPZFj8Ydw5XOZgLexnUjEVm1b2sIIGjCG4zREAPElyWFitsRN4lq5M7k+P1ZpA2A/DN3 Tjrcou3Yj0T+kXs4kRr7S54a4fZB6CfT1obBCxoR3Tx41wuLC5VZV2g67nbKO+WPh0/f SCSII/UdOMP1blic4Kw2OEdkaqmc7Aeyf/RIB9TsoaqFqm7K1B7w+w7ab5pScjEVqX6D 0A4g== X-Gm-Message-State: AOAM5336t0todnK4n3rnNX868q13gQJc9uSWSOcgPDQsuTgbvBSBG79Q LuioXiRpVv8mqrUsTSwYocWmY47QyPc= X-Google-Smtp-Source: ABdhPJz0Ruz4qi4LaxHLHaElqAIQjv2ofk2WSFCgQqoFhyxd6be/ITYhoV9J4MXNgXjtr8OfSOIHjA== X-Received: by 2002:a2e:a44f:: with SMTP id v15mr8056497ljn.301.1626426989342; Fri, 16 Jul 2021 02:16:29 -0700 (PDT) Date: Fri, 16 Jul 2021 12:16:25 +0300 From: Timo Teras To: musl@lists.openwall.com Message-ID: <20210716121625.38409b91@vostro> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.28; x86_64-alpine-linux-musl) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/Smdm/r=_5VstEOgTf.SuNcK" Subject: [musl] option to enable eh_frame --MP_/Smdm/r=_5VstEOgTf.SuNcK Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, This has been discussed few times, and I know there are arguments also not to do this. But at this time we at Alpine think the reasons to keep eh_frame outweight the reasons to not include it. Main arguments against .eh_frame being: 1) Having .eh_frame makes it seem like C++ exception throwing works through C-library functions (e.g. throwing exception form qsort callback to return over qsort back to application). Counter arguments: - C++ exceptions is just one way to jump through musl functions. E.g. setjmp/longjmp can do that just fine even without .eh_frame 2) Having application unwind itself for backtrace printing purposes especially in signal handler is bad. This is agreed, but there's still other cases when unwinding is good for debugging, and other reasons. The fix for this root cause is to remove the unwinding from signal handlers. Arguments to have .eh_frame: - It allows debugging things even if musl-dbg is not or cannot be installed for some reason (e.g. gdb, valgrind), or is no longer available - libunwind/libexecinfo will start to work and give meaningful backtraces - Continuous kernel based profiling (e.g. perf record -g dwarf) will work Given that the main arguments against are either making UB crash, or not the best fix, and keeping eh_frame enables useful features to work, I think it would make sense to allow enabling it. Please consider the the attached patch to make it a configure option to enable keeping eh_frame (defaulting still to not keeping it). Thanks, Timo --MP_/Smdm/r=_5VstEOgTf.SuNcK Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=eh-frame.patch >From b2d24e3cc6015aa6a4b01b1fdbad1e68b6fccb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Fri, 9 Jul 2021 10:57:20 +0300 Subject: add configure option to enable .eh_frame generation Add --enable-eh-frame to enable .eh_frame generation. This adds about 80kB to ELF size on x86_64. This is useful to run continuous profilers, gdb, valgrind and other debugging utilities to generate backtrace information without having to install the full musl-dbg package. As side effect, this might seem to make exception handling work through C-library fuctions when they are calling a callback (e.g. qsort), but this continues to be UB and is not supported. This actually is the case on ARM where .ARM.exidx is used for unwind info which is present always on the musl DSO. --- Makefile | 4 ++-- configure | 30 ++++++++++++++++++++++-------- tools/add-cfi.i386.awk | 2 +- tools/add-cfi.x86_64.awk | 2 +- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index e8cc4436..2b501c25 100644 --- a/Makefile +++ b/Makefile @@ -134,8 +134,8 @@ $(LOBJS) $(LDSO_OBJS): CFLAGS_ALL += -fPIC CC_CMD = $(CC) $(CFLAGS_ALL) -c -o $@ $< # Choose invocation of assembler to be used -ifeq ($(ADD_CFI),yes) - AS_CMD = LC_ALL=C awk -f $(srcdir)/tools/add-cfi.common.awk -f $(srcdir)/tools/add-cfi.$(ARCH).awk $< | $(CC) $(CFLAGS_ALL) -x assembler -c -o $@ - +ifneq ($(ADD_CFI),no) + AS_CMD = LC_ALL=C awk -v CFI_SECTIONS="$(ADD_CFI)" -f $(srcdir)/tools/add-cfi.common.awk -f $(srcdir)/tools/add-cfi.$(ARCH).awk $< | $(CC) $(CFLAGS_ALL) -x assembler -c -o $@ - else AS_CMD = $(CC_CMD) endif diff --git a/configure b/configure index a5231a0e..eea16e6c 100755 --- a/configure +++ b/configure @@ -30,6 +30,7 @@ System types: Optional features: --enable-optimize=... optimize listed components for speed over size [auto] --enable-debug build with debugging information [disabled] + --enable-eh-frame keep .eh_frame on main binary [disabled] --disable-warnings build with recommended warnings flags [enabled] --enable-wrapper=... build given musl toolchain wrapper [auto] --disable-shared inhibit building shared library [enabled] @@ -142,6 +143,7 @@ static=yes wrapper=auto gcc_wrapper=no clang_wrapper=no +eh_frame=no malloc_dir=mallocng for arg ; do @@ -172,6 +174,8 @@ case "$arg" in --disable-wrapper|--enable-wrapper=no) wrapper=no ;; --enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ; gcc_wrapper=yes ;; --disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;; +--enable-eh-frame|--enable-eh-frame=yes) eh_frame=yes ;; +--disable-eh-frame|--enable-eh-frame=no) eh_frame=no ;; --with-malloc=*) malloc_dir=${arg#*=} ;; --enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;; --host=*|--target=*) target=${arg#*=} ;; @@ -407,14 +411,22 @@ test "$debug" = yes && CFLAGS_AUTO=-g # enabled, our assembler supports the needed directives, and the # preprocessing script has been written for our architecture. # -printf "checking whether we should preprocess assembly to add debugging information... " -if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" && - test -f "tools/add-cfi.$ARCH.awk" && +printf "checking whether we should preprocess assembly to add unwind information... " + +ADD_CFI="no" +if test -f "tools/add-cfi.$ARCH.awk" && printf ".file 1 \"srcfile.s\"\n.line 1\n.cfi_startproc\n.cfi_endproc" | $CC -g -x assembler -c -o /dev/null 2>/dev/null - then - ADD_CFI=yes -else - ADD_CFI=no + if test "$eh_frame" = "yes" && fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" + then + ADD_CFI=".eh_frame, .debug_frame" + elif test "$eh_frame" = "yes" + then + ADD_CFI=".eh_frame" + elif fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" + then + ADD_CFI=".debug_frame" + fi fi printf "%s\n" "$ADD_CFI" @@ -478,8 +490,10 @@ fi # unstrippable. These options force them back to debug sections (and # cause them not to get generated at all if debugging is off). # -tryflag CFLAGS_AUTO -fno-unwind-tables -tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables +if test "$eh_frame" = "no"; then + tryflag CFLAGS_AUTO -fno-unwind-tables + tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables +fi # # Attempt to put each function and each data object in its own diff --git a/tools/add-cfi.i386.awk b/tools/add-cfi.i386.awk index d05037de..f758acec 100644 --- a/tools/add-cfi.i386.awk +++ b/tools/add-cfi.i386.awk @@ -9,7 +9,7 @@ BEGIN { # don't put CFI data in the .eh_frame ELF section (which we don't keep) - print ".cfi_sections .debug_frame" + print ".cfi_sections " CFI_SECTIONS # only emit CFI directives inside a function in_function = 0 diff --git a/tools/add-cfi.x86_64.awk b/tools/add-cfi.x86_64.awk index 7e1513d6..4a2ae029 100644 --- a/tools/add-cfi.x86_64.awk +++ b/tools/add-cfi.x86_64.awk @@ -2,7 +2,7 @@ BEGIN { # don't put CFI data in the .eh_frame ELF section (which we don't keep) - print ".cfi_sections .debug_frame" + print ".cfi_sections " CFI_SECTIONS # only emit CFI directives inside a function in_function = 0 -- 2.32.0 --MP_/Smdm/r=_5VstEOgTf.SuNcK--