https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91299
--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> --- (In reply to Martin Liška from comment #5) > (In reply to Richard Biener from comment #4) > > You want to look at the output of the linker resolution file (compile with > > -v -save-temps and look for -fresolution=<filename>). The linker probably > > tells > > GCC that its "weak" foo() definition is prevailing. This either makes it > > a non-bug or a binutils bug then. > > $ cat weakdef.res > 1 > weakdef.o 2 > 199 b48787268b6fb34e PREEMPTED_REG foo > 202 b48787268b6fb34e PREVAILING_DEF main -O0 and -O1 work. -O2 and above fail. It looks like a GCC bug.