-
Notifications
You must be signed in to change notification settings - Fork 155
Description
When invoking fbc with multiple -Wl flags, only the final -Wl flag is passed down to the linker.
To demonstrate the issue, I have run fbc in 4 different ways:
- no
-Wlflags - one
-Wlflag with two ld options (one defines symbol foo, other defines symbol bar) - two
-Wlflags each with one ld option (foo symbol definition first) - two
-Wlflags each with one ld option (bar symbol definition first)
After each compilation I run nm on the resulting executable and grep for either of the foo or bar symbols:
$ fbc -g foobar.bas && nm foobar | grep "foo\|bar"
$ fbc -g -Wl --defsym=foo=0,--defsym=bar=0 foobar.bas && nm foobar | grep "foo\|bar"
0000000000000000 A bar
0000000000000000 A foo
$ fbc -g -Wl --defsym=foo=0 -Wl --defsym=bar=0 foobar.bas && nm foobar | grep "foo\|bar"
0000000000000000 A bar
$ fbc -g -Wl --defsym=bar=0 -Wl --defsym=foo=0 foobar.bas && nm foobar | grep "foo\|bar"
0000000000000000 A foo
As can be seen from the tests, only the last -Wl flag is sent down to the linker program. The expected behavior is to pass down all linker options specified by all -Wl flags, and not simply the final one; this would match the behavior described by ld documentation:
Note---if the linker is being invoked indirectly, via a compiler driver (e.g. gcc) then all the linker command line options should be prefixed by -Wl, (or whatever is appropriate for the particular compiler driver) like this:
gcc -Wl,--start-group foo.o bar.o -Wl,--end-group
This is important, because otherwise the compiler driver program may silently drop the linker options, resulting in a bad link.