Skip to content

Final -Wl flag takes precedence over previous #137

@ghost

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 -Wl flags
  • one -Wl flag with two ld options (one defines symbol foo, other defines symbol bar)
  • two -Wl flags each with one ld option (foo symbol definition first)
  • two -Wl flags 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions