https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118975

            Bug ID: 118975
           Summary: -undef is passed to the linker
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: driver
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nate at thatsmathematics dot com
  Target Milestone: ---

When the `-undef` option is given to gcc for a command that involves linking,
the option is passed to the linker as well as the compiler.  This makes no
sense as `-undef` should only affect preprocessing, and it causes the linker to
misbehave.

When running `gcc -undef -v m.c` for a file `m.c` containing only `int
main(void) { }` in my test, the linker command line is:

/usr/libexec/gcc/aarch64-unknown-linux-gnu/14/collect2 [...] -undef .../Scrt1.o
[...] 

GNU ld parses this as equivalent to `--undefined=.../Scrt1.o`, so the path
`.../Scrt1.o` is treated as a symbol to be undefined, rather than as a file to
be linked.  I get a message about the `_start` entry point being undefined, and
the resulting executable doesn't work.

Tested locally with Gentoo's ebuild of 14.2.1_p20241221 p7 on arm64, but also
reproducible with all recent versions on godbolt, e.g.
https://godbolt.org/z/3s6qGex8o

Reply via email to