https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65252
Bug ID: 65252 Summary: Link time optimization breaks use of filenames in linker scripts Product: gcc Version: 4.8.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: goswin-v-b at web dot de CC: goswin-v-b at web dot de Host: x86_64-linux-gnu Target: x86_64-linux-gnu Build: arm-none-eabi I'm building a kernel for a Rapsberry Pi 2 with -flto. Most of the code will be linked to 0x8000xxxx. The kernel image will be loaded to 0x8000 and I have set up LMA and VMA in my linker script accordingly. But I have some bootstrap code (boot.S and early.cc) that needs to at the physical address. So I put the following in my linker script: ENTRY(_start) PHYS_TO_VIRT = 0x80000000; SECTIONS { . = 0x8000; .early : { boot.o(.*) early.o(.*) } /* rest of the code runs in higher half virtual address */ . = . + PHYS_TO_VIRT; .text : AT(ADDR(.text) - PHYS_TO_VIRT) { ... Using objdump -d I see the boot.o contents show up at 0x8000 exactly as it should. But all the code from early.o only appears later in the .text section and at the virtual adress. If I drop the -flto then everything works as expected. It would be nice if -flto could preserve which file each function and variable comes from so the linker can place them properly.