| Issue |
244638
|
| Summary |
[Clang] asm label on a redeclared library function is ignored for __builtin_* calls and terminate landing pads
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
shalseth
|
When a library function is redeclared with an asm label, clang uses the label for direct calls. It doesn't use it for calls it makes itself. That covers calls through the matching `__builtin_*`, and the `abort` call in the terminate landing pad clang adds for a `cleanup` attribute under `-fexceptions`. GCC uses the label for the builtins, and it doesn't add a terminate pad in C.
```c
extern char *stpcpy (char *, const char *) __asm__ ("__GI_stpcpy");
extern void abort (void) __asm__ ("__GI_abort") __attribute__ ((noreturn));
extern void unlock (int *);
extern void work (void);
char *f (char *d, const char *s) { return __builtin_stpcpy (d, s); }
char *g (char *d, const char *s) { return stpcpy (d, s); }
void h (int x) { if (x) __builtin_abort (); }
void k (void) { int lock __attribute__ ((cleanup (unlock))) = 0; work (); }
```
```
$ clang -O2 -fexceptions -S t.c -o - | grep -E '^[a-z]:|call'
f: ! @f
call stpcpy
g: ! @g
call __GI_stpcpy
h: ! @h
call abort
k: ! @k
call work
call unlock
call unlock
call _Unwind_Resume
call abort
$ gcc -O2 -fexceptions -S t.c -o - | grep -E '^[a-z]:|call'
f:
call __GI_stpcpy, 0
g:
call __GI_stpcpy, 0
h:
call __GI_abort, 0
k:
call work, 0
call unlock, 0
call unlock, 0
call __stack_chk_fail, 0
call _Unwind_Resume, 0
```
The x86_64 IR is the same (`call ptr @stpcpy`, `call void @abort`). This isn't SPARC specific.
glibc relies on these labels to keep libc's internal calls off the PLT. include/string.h maps `__stpcpy` to `__builtin_stpcpy` and redirects `stpcpy` to the hidden `__GI_stpcpy`. `abort` is redirected to `__GI_abort` the same way. A clang-built libc.so has PLT calls to `stpcpy` and `abort`. The `abort` calls come from the `_IO_acquire_lock` cleanups in libio and similar places. glibc's elf/check-localplt test fails because of them (https://github.com/sparclinux/issues/issues/96). glibc already works around the `abort` case for ld.so (commit 50000da305).
LLVM main 1ed0efd70af1, SPARC M7, Linux sparc64.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs