* [Bug sanitizer/101111] Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
@ 2021-06-17 22:17 ` mose at gnu dot org
2021-06-18 19:42 ` [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions mose at gnu dot org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: mose at gnu dot org @ 2021-06-17 22:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
--- Comment #1 from Mosè Giordano <mose at gnu dot org> ---
To add more information, the real problem seems to be that xgcc can't generate
weak symbols:
sandbox:${WORKSPACE}/srcdir/gcc_build # x86_64-apple-darwin14-nm
x86_64-apple-darwin14/libsanitizer/lsan/.libs/lsan_common.o | grep '___lsan'
00000000000018c0 T ___lsan_default_options
U ___lsan_default_suppressions
00000000000018a0 T ___lsan_disable
0000000000003440 T ___lsan_do_leak_check
0000000000003460 T ___lsan_do_recoverable_leak_check
00000000000018b0 T ___lsan_enable
00000000000014c0 T ___lsan_ignore_object
U ___lsan_default_suppressions
0000000000001580 T ___lsan_register_root_region
00000000000017c0 T ___lsan_unregister_root_region
___lsan_default_suppressions and ___lsan_default_suppressions should be weak,
instead they're undefined. I can reproduce the same issue with this simpler
example:
sandbox:${WORKSPACE}/srcdir/gcc_build # /workspace/srcdir/gcc_build/./gcc/xgcc
-B/workspace/srcdir/gcc_build/./gcc -x c - << EOF
#include <stdio.h>
int __attribute__((weak)) func(int);
#if 0
int func(int a) { return 2 * a; }
#endif
int main() {
if (&func) {
printf("Func implemented: %d\n", func(10));
} else {
printf("Func not implemented\n");
}
return 0;
}
EOF
Undefined symbols for architecture x86_64:
"_func", referenced from:
_main in ccMDdanO.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
2021-06-17 22:17 ` [Bug sanitizer/101111] " mose at gnu dot org
@ 2021-06-18 19:42 ` mose at gnu dot org
2021-06-18 19:50 ` pinskia at gcc dot gnu.org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: mose at gnu dot org @ 2021-06-18 19:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
--- Comment #2 from Mosè Giordano <mose at gnu dot org> ---
I've gathered some more information. In LLVM, libsanitizer uses
-Wl,-U,<symbol-name> to allow the macOS linker accept undefined symbols and
mimic ELF weak symbols, see
<https://github.com/llvm/llvm-project/blob/cbfb12469ba312c8ff513397b29bef470f151caa/compiler-rt/cmake/Modules/SanitizerUtils.cmake#L71>,
and
<https://github.com/llvm/llvm-project/blob/cbfb12469ba312c8ff513397b29bef470f151caa/compiler-rt/lib/lsan/weak_symbols.txt>
for the list of weak symbols in lsan.
GCC uses libtool checks to set these flags:
<https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libsanitizer/configure;h=1d9ae59be6798555b7020a66e0f622ff8bf752cc;hb=50bc9185c2821350f0b785d6e23a6e9dcde58466#l8839>.
This is a check on `$host_cpu-$host_os`, however I'm compiling a
cross-compiler (`build == host == x86_64-linux-musl`, `target ==
x86_64-apple-darwin`, I may have been inaccurate before), so shouldn't this
check use `$target_cpu-$target_os` instead?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
2021-06-17 22:17 ` [Bug sanitizer/101111] " mose at gnu dot org
2021-06-18 19:42 ` [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions mose at gnu dot org
@ 2021-06-18 19:50 ` pinskia at gcc dot gnu.org
2021-06-18 22:46 ` mose at gnu dot org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-18 19:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Mosè Giordano from comment #2)
> GCC uses libtool checks to set these flags:
> <https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libsanitizer/configure;
> h=1d9ae59be6798555b7020a66e0f622ff8bf752cc;
> hb=50bc9185c2821350f0b785d6e23a6e9dcde58466#l8839>. This is a check on
> `$host_cpu-$host_os`, however I'm compiling a cross-compiler (`build == host
> == x86_64-linux-musl`, `target == x86_64-apple-darwin`, I may have been
> inaccurate before), so shouldn't this check use `$target_cpu-$target_os`
> instead?
No host usage here is correct. This is a (target) library which means the host
(and target) are set x86_64-apple-darwin and the build is set to
x86_64-linux-musl.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
` (2 preceding siblings ...)
2021-06-18 19:50 ` pinskia at gcc dot gnu.org
@ 2021-06-18 22:46 ` mose at gnu dot org
2021-06-18 23:24 ` mose at gnu dot org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: mose at gnu dot org @ 2021-06-18 22:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
--- Comment #4 from Mosè Giordano <mose at gnu dot org> ---
You're right, in `x86_64-apple-darwin14/libsanitizer/config.log` I can see that
`build == x86_64-linux-musl` and `host == target == x86_64-apple-darwin`, but
still, in `x86_64-apple-darwin14/libsanitizer` I don't see any reference to
linker flags like `-undefined dynamic_lookup`, `-U <symbol-name>`, `-undefined
suppress` or anything like that. Maybe libsanitizer should use something
similar to `GCC_CHECK_ELF_STYLE_WEAKREF`
(<https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=config/weakref.m4;h=ecb85672805882b330cac43e0fc12e7fe96aeec9;hb=HEAD>)
to actually use any these flags? The undefined functions mentioned in the
error message use ELF-style weak symbols, but without appropriate flags the
macOS linker will complain.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
` (3 preceding siblings ...)
2021-06-18 22:46 ` mose at gnu dot org
@ 2021-06-18 23:24 ` mose at gnu dot org
2021-06-18 23:53 ` mose at gnu dot org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: mose at gnu dot org @ 2021-06-18 23:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
--- Comment #5 from Mosè Giordano <mose at gnu dot org> ---
Ok, I finally found the culprit: `libsanitizer` does already have a way to add
`-Wl,-undefined,dynamic_lookup` to CXXFLAGS, but it uses a bashism:
<https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libsanitizer/configure.tgt;h=0ca5d9fd92464110d99a5da86b8de4378384e944;hb=HEAD#l68>.
On Alpine Linux, the system where I'm doing the compilation, sh isn't bash and
appending to a string variable with += isn't valid. Scavenging the compilation
log I found
/workspace/srcdir/gcc-11.1.0/libsanitizer/configure:
/workspace/srcdir/gcc-11.1.0/libsanitizer/configure.tgt: line 68:
EXTRA_CXXFLAGS+=-Wl,-undefined,dynamic_lookup: not found
If I replace
EXTRA_CXXFLAGS+="-Wl,-undefined,dynamic_lookup"
with
EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS} -Wl,-undefined,dynamic_lookup"
compilation of GCC is finally successful.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
` (4 preceding siblings ...)
2021-06-18 23:24 ` mose at gnu dot org
@ 2021-06-18 23:53 ` mose at gnu dot org
2021-07-19 20:33 ` mose at gnu dot org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: mose at gnu dot org @ 2021-06-18 23:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
--- Comment #6 from Mosè Giordano <mose at gnu dot org> ---
Created attachment 51038
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51038&action=edit
Patch to fix the reported issue
Please find attached a patch to fix the reported issue. I replaced the bashism
+= with simple string interpolation, to make it complaint with strict POSIX
shells.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
` (5 preceding siblings ...)
2021-06-18 23:53 ` mose at gnu dot org
@ 2021-07-19 20:33 ` mose at gnu dot org
2021-07-22 18:06 ` marxin at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: mose at gnu dot org @ 2021-07-19 20:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
--- Comment #7 from Mosè Giordano <mose at gnu dot org> ---
Bump. Is there any chance someone can review a one-line patch? :)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
` (6 preceding siblings ...)
2021-07-19 20:33 ` mose at gnu dot org
@ 2021-07-22 18:06 ` marxin at gcc dot gnu.org
2021-07-22 19:01 ` iains at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-07-22 18:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |marxin at gcc dot gnu.org
CC| |iains at gcc dot gnu.org
Last reconfirmed| |2021-07-22
--- Comment #8 from Martin Liška <marxin at gcc dot gnu.org> ---
Sure, but I would like to first speak Iain who added the code.
What do you think about the patch?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
` (7 preceding siblings ...)
2021-07-22 18:06 ` marxin at gcc dot gnu.org
@ 2021-07-22 19:01 ` iains at gcc dot gnu.org
2021-07-25 10:54 ` iains at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: iains at gcc dot gnu.org @ 2021-07-22 19:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
--- Comment #9 from Iain Sandoe <iains at gcc dot gnu.org> ---
(In reply to Martin Liška from comment #8)
> Sure, but I would like to first speak Iain who added the code.
> What do you think about the patch?
hm, sorry for introducing the bash-ism, the change LGTM but I would like to
bootstrap it on a native Darwin installation - should be able to fit that in in
the next day or do.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
` (8 preceding siblings ...)
2021-07-22 19:01 ` iains at gcc dot gnu.org
@ 2021-07-25 10:54 ` iains at gcc dot gnu.org
2021-07-25 10:56 ` mose at gnu dot org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: iains at gcc dot gnu.org @ 2021-07-25 10:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
--- Comment #10 from Iain Sandoe <iains at gcc dot gnu.org> ---
(In reply to Mosè Giordano from comment #6)
> Created attachment 51038 [details]
> Patch to fix the reported issue
>
> Please find attached a patch to fix the reported issue. I replaced the
> bashism += with simple string interpolation, to make it complaint with
> strict POSIX shells.
This is OK for master and back-ports from the Darwin perspective (I guess
Martin plans to deal with this since he has assigned the PR, but if he does not
have time, I can apply this for you if you don't have write access).
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
` (9 preceding siblings ...)
2021-07-25 10:54 ` iains at gcc dot gnu.org
@ 2021-07-25 10:56 ` mose at gnu dot org
2021-08-03 11:25 ` cvs-commit at gcc dot gnu.org
2021-08-03 11:25 ` marxin at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: mose at gnu dot org @ 2021-07-25 10:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
--- Comment #11 from Mosè Giordano <mose at gnu dot org> ---
> This is OK for master and back-ports from the Darwin perspective
Thanks for the review and confirmation!
> (I guess Martin plans to deal with this since he has assigned the PR, but if he does not have time, I can apply this for you if you don't have write access).
Yes, I don't have write access, so someone else will need to apply the patch
:-)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
` (10 preceding siblings ...)
2021-07-25 10:56 ` mose at gnu dot org
@ 2021-08-03 11:25 ` cvs-commit at gcc dot gnu.org
2021-08-03 11:25 ` marxin at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-03 11:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:
https://gcc.gnu.org/g:759f3854f0fdb4add2961bfafd1ee793f392f70a
commit r12-2686-g759f3854f0fdb4add2961bfafd1ee793f392f70a
Author: Mosè Giordano <mose@gnu.org>
Date: Fri Jun 18 23:46:44 2021 +0000
Fix bashism in `libsanitizer/configure.tgt'
Appending to a string variable with `+=' is a bashism and does not work in
strict POSIX shells like dash. This results in the extra compilation flags
not
to be set correctly. This patch replaces the `+=' syntax with a simple
string
interpolation to append to the `EXTRA_CXXFLAGS' variable.
libsanitizer/ChangeLog
PR sanitizer/101111
* configure.tgt: Fix bashism in setting of `EXTRA_CXXFLAGS'.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug sanitizer/101111] xgcc cross-compiler for x86_64-apple-darwin in GCC 11.1 doesn't generate weak symbols, resulting in undefined reference to ___lsan_default_suppressions
2021-06-17 19:01 [Bug sanitizer/101111] New: Undefined reference to ___lsan_default_suppressions when compiling GCC 11.1 for x86_64 macOS mose at gnu dot org
` (11 preceding siblings ...)
2021-08-03 11:25 ` cvs-commit at gcc dot gnu.org
@ 2021-08-03 11:25 ` marxin at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-03 11:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101111
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #13 from Martin Liška <marxin at gcc dot gnu.org> ---
Thanks Iaian for testing, I've just pushed the commit.
^ permalink raw reply [flat|nested] 14+ messages in thread