This is an archive of the discontinued LLVM Phabricator instance.

Change which input sections we concatenate
Needs ReviewPublic

Authored by espindola on Jan 4 2017, 1:31 PM.

Details

Summary

After Mark's patch I was wondering what was the rationale for the ELF spec requiring us to merge only sections with matching flags and types. I tried emailing https://groups.google.com/forum/#!forum/generic-abi, but looks like my emails are not being posted (the list is probably moderated). I emailed Cary Coutant instead.

Cary pointed out that the section was a late addition and didn't got the scrutiny it deserved. Given that and the problems found by implementing the letter of the standard, I propose changing lld to merge all sections with the same name and issue errors if the types or some critical flags are different.

This should allow an unmodified firefox linked with lld to run.

This also merges some code with the linkerscript path.

Diff Detail

Event Timeline

rafael updated this revision to Diff 83114.Jan 4 2017, 1:31 PM
rafael retitled this revision from to Change which input sections we concatenate.
rafael updated this object.
rafael added reviewers: ruiu, emaste, kettenis.
rafael added a subscriber: llvm-commits.
ruiu edited edge metadata.Jan 4 2017, 8:51 PM

LGTM with a nit.

ELF/OutputSections.cpp
546

It -> it

kettenis edited edge metadata.Jan 5 2017, 8:56 AM

FWIW, the Solaris linker doesn't merge sections purely on based on name, but the GNU linker does so there probably is plenty of code that depends on this "feature".

emaste edited edge metadata.Jan 12 2017, 8:40 AM

FreeBSD EFI loader build now fails with:

--- all_subdir_sys ---
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name copy.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name devicename.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name main.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name smbios.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name zfs.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name elf64_freebsd.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name trap.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name comconsole.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name boot.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name interp.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name interp_parse.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name module.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name load_elf32.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name load_elf64.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name disk.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name bcache.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name libefi.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name efipart.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name efinet.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: Section has different type from others with the same name efi_console.o:(.bss)
/tank/emaste/obj/tank/emaste/src/freebsd-xlld/tmp/usr/bin/ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** [loader.sym.full] Error code 1

Although the EFI loader worked prior to this change, the error is presumably identifying something we need to to fix in the loader.

Could we perhaps indicate the conflicting type in the error message?

espindola commandeered this revision.Mar 15 2018, 8:55 AM
espindola added a reviewer: rafael.