public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Adhemerval Zanella <azanella@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc/azanella/clang] elf: Fix _startup_fatal on clang Date: Tue, 10 May 2022 18:36:22 +0000 (GMT) [thread overview] Message-ID: <20220510183622.5F4C03857822@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=bd03225ffbbeab70a08d594cfb8d480d0771756f commit bd03225ffbbeab70a08d594cfb8d480d0771756f Author: Adhemerval Zanella <adhemerval.zanella@linaro.org> Date: Tue May 10 15:34:42 2022 -0300 elf: Fix _startup_fatal on clang clang can not see that the input string is a constant one, so __builtin_constant_p fails and a strlen might be issue. Instead change TLS_INIT_TP to return the string size. Fixed only for x86_64 and aarch64. Diff: --- csu/libc-tls.c | 8 +++++--- elf/rtld.c | 6 ++++-- sysdeps/aarch64/nptl/tls.h | 4 ++-- sysdeps/unix/sysv/linux/startup.h | 10 ++-------- sysdeps/x86_64/nptl/tls.h | 6 ++++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/csu/libc-tls.c b/csu/libc-tls.c index bef92a7568..915b016bf5 100644 --- a/csu/libc-tls.c +++ b/csu/libc-tls.c @@ -183,18 +183,20 @@ __libc_setup_tls (void) /* Install the pointer to the dtv. */ /* Initialize the thread pointer. */ + size_t lossagelen; #if TLS_TCB_AT_TP INSTALL_DTV ((char *) tlsblock + tcb_offset, _dl_static_dtv); - const char *lossage = TLS_INIT_TP ((char *) tlsblock + tcb_offset); + const char *lossage = TLS_INIT_TP ((char *) tlsblock + tcb_offset, + lossagelen); #elif TLS_DTV_AT_TP INSTALL_DTV (tlsblock, _dl_static_dtv); - const char *lossage = TLS_INIT_TP (tlsblock); + const char *lossage = TLS_INIT_TP (tlsblock, lossagelen); #else # error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined" #endif if (__builtin_expect (lossage != NULL, 0)) - _startup_fatal (lossage); + _startup_fatal (lossage, lossagelen); __tls_init_tp (); /* Update the executable's link map with enough information to make diff --git a/elf/rtld.c b/elf/rtld.c index 3d53107504..a549afc233 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -809,7 +809,8 @@ cannot allocate TLS data structures for initial thread\n"); GL(dl_initial_dtv) = GET_DTV (tcbp); /* And finally install it for the main thread. */ - const char *lossage = TLS_INIT_TP (tcbp); + size_t lossagelen __attribute_maybe_unused__; + const char *lossage = TLS_INIT_TP (tcbp, lossagelen); if (__glibc_unlikely (lossage != NULL)) _dl_fatal_printf ("cannot set up thread-local storage: %s\n", lossage); __tls_init_tp (); @@ -2317,7 +2318,8 @@ dl_main (const ElfW(Phdr) *phdr, /* And finally install it for the main thread. */ if (! tls_init_tp_called) { - const char *lossage = TLS_INIT_TP (tcbp); + size_t lossagelen __attribute_maybe_unused__; + const char *lossage = TLS_INIT_TP (tcbp, lossagelen); if (__glibc_unlikely (lossage != NULL)) _dl_fatal_printf ("cannot set up thread-local storage: %s\n", lossage); diff --git a/sysdeps/aarch64/nptl/tls.h b/sysdeps/aarch64/nptl/tls.h index 8d62b31e23..2f8cf50b89 100644 --- a/sysdeps/aarch64/nptl/tls.h +++ b/sysdeps/aarch64/nptl/tls.h @@ -71,8 +71,8 @@ typedef struct /* Code to initially initialize the thread pointer. This might need special attention since 'errno' is not yet available and if the operation can cause a failure 'errno' must not be touched. */ -# define TLS_INIT_TP(tcbp) \ - ({ __asm __volatile ("msr tpidr_el0, %0" : : "r" (tcbp)); NULL; }) +# define TLS_INIT_TP(tcbp, l) \ + ({ __asm __volatile ("msr tpidr_el0, %0" : : "r" (tcbp)); l = 0, NULL; }) /* Value passed to 'clone' for initialization of the thread register. */ # define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) + 1 diff --git a/sysdeps/unix/sysv/linux/startup.h b/sysdeps/unix/sysv/linux/startup.h index 39859b404a..6f9931106a 100644 --- a/sysdeps/unix/sysv/linux/startup.h +++ b/sysdeps/unix/sysv/linux/startup.h @@ -22,17 +22,11 @@ # include <sysdep.h> /* Avoid a run-time invocation of strlen. */ -#define _startup_fatal(message) \ +#define _startup_fatal(message, message_length) \ do \ { \ - size_t __message_length = __builtin_strlen (message); \ - if (! __builtin_constant_p (__message_length)) \ - { \ - extern void _startup_fatal_not_constant (void); \ - _startup_fatal_not_constant (); \ - } \ INTERNAL_SYSCALL_CALL (write, STDERR_FILENO, (message), \ - __message_length); \ + (message_length)); \ INTERNAL_SYSCALL_CALL (exit_group, 127); \ } \ while (0) diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h index 75f8020975..57f85e78ba 100644 --- a/sysdeps/x86_64/nptl/tls.h +++ b/sysdeps/x86_64/nptl/tls.h @@ -132,6 +132,8 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 0x80, # define GET_DTV(descr) \ (((tcbhead_t *) (descr))->dtv) +# define TLS_INIT_TP_ERR_MSG \ + "cannot set %fs base address for thread-local storage" /* Code to initially initialize the thread pointer. This might need special attention since 'errno' is not yet available and if the @@ -139,7 +141,7 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 0x80, We have to make the syscall for both uses of the macro since the address might be (and probably is) different. */ -# define TLS_INIT_TP(thrdescr) \ +# define TLS_INIT_TP(thrdescr, l) \ ({ void *_thrdescr = (thrdescr); \ tcbhead_t *_head = _thrdescr; \ int _result; \ @@ -156,7 +158,7 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 0x80, "S" (_thrdescr) \ : "memory", "cc", "r11", "cx"); \ \ - _result ? "cannot set %fs base address for thread-local storage" : 0; \ + _result ? l = sizeof (TLS_INIT_TP_ERR_MSG) - 1, TLS_INIT_TP_ERR_MSG : 0; \ }) # define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd)
next reply other threads:[~2022-05-10 18:36 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-10 18:36 Adhemerval Zanella [this message] 2022-05-12 19:40 Adhemerval Zanella 2022-05-13 14:26 Adhemerval Zanella 2022-06-03 14:12 Adhemerval Zanella 2022-06-09 13:23 Adhemerval Zanella 2022-06-09 21:26 Adhemerval Zanella 2022-10-04 12:59 Adhemerval Zanella 2022-10-28 17:41 Adhemerval Zanella
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220510183622.5F4C03857822@sourceware.org \ --to=azanella@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).