https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120515
Bug ID: 120515
Summary: darwin warning: ld: warning: -U option is redundant
when using -undefined dynamic_lookup
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: driver
Assignee: unassigned at gcc dot gnu.org
Reporter: peter at eisentraut dot org
Target Milestone: ---
I'm getting an undesirable linker warning when using gcc on macOS Homebrew. (I
know this is heavily patched, but my best guess is that this is an upstream
issue, see below.)
gcc-15 (Homebrew GCC 15.1.0) 15.1.0
Consider a simple source file test.c:
```
int foo(int x)
{
return x;
}
```
and also test.exports:
```
_foo
```
Compile:
gcc-15 -c -o test.o test.c
Link:
gcc-15 -o test.dylib -bundle test.o -Wl,-undefined,dynamic_lookup
-Wl,-exported_symbols_list,test.exports
This shows this warning:
ld: warning: -U option is redundant when using -undefined dynamic_lookup
Using -v shows what is being called underneath:
gcc-15 -v -o test.dylib -bundle test.o -Wl,-undefined,dynamic_lookup
-Wl,-exported_symbols_list,test.exports
/opt/homebrew/Cellar/gcc/15.1.0/bin/../libexec/gcc/aarch64-apple-darwin24/15/collect2
-demangle -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/
-dynamic -arch arm64 -macos_version_min 15.0.0 -o test.dylib
-L/opt/homebrew/Cellar/gcc/15.1.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/15
-L/opt/homebrew/Cellar/gcc/15.1.0/bin/../lib/gcc/current/gcc
-L/opt/homebrew/Cellar/gcc/15.1.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/15/../../..
-lemutls_w -lheapt_w test.o -undefined dynamic_lookup -exported_symbols_list
test.exports -bundle -lgcc -lSystem -U ___emutls_get_address -exported_symbol
___emutls_get_address -U ___emutls_register_common -exported_symbol
___emutls_register_common -U ___gcc_nested_func_ptr_created -exported_symbol
___gcc_nested_func_ptr_created -U ___gcc_nested_func_ptr_deleted
-exported_symbol ___gcc_nested_func_ptr_deleted -no_compact_unwind -rpath
@loader_path -rpath
/opt/homebrew/Cellar/gcc/15.1.0/lib/gcc/current/gcc/aarch64-apple-darwin24/15
-rpath /opt/homebrew/Cellar/gcc/15.1.0/lib/gcc/current/gcc -rpath
/opt/homebrew/Cellar/gcc/15.1.0/lib/gcc/current
So these internally added -U options should perhaps be skipped if -undefined
dynamic_lookup is used?
FWIW, documentation for these options:
-U symbol_name
Specified that it is ok for symbol_name to have no definition.
[...]
-undefined treatment
Specifies how undefined symbols are to be treated. Options are:
error, warning, suppress, or dynamic_lookup. The default is error. [...]
These -U options appear to come from gcc/config/darwin.h, but I don't dare
analyze what is going on in that file. ;-) Apparently, -exported_symbols_list
is necessary to trigger it; without it there is no warning.
I can reproduce this back to gcc-13 at least. That darwin.h file doesn't
appear to have changed in this respect.