This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Linkerscript: do not define _edata,_end,_etext if SECTIONS is used.
ClosedPublic

Authored by grimar on Aug 5 2016, 7:42 AM.

Details

Summary

I faced that when tried to link FreeBSD kernel. It was "duplicate symbol: _edata in (internal) and (internal)" error.
_data was a shared symbol that came from hack.so. At first it was replaced with DefinedRegular by the code
disabled in this patch and later when script tried to define the same symbol - the error was shown.

I think when SECTIONS command is used we should not define these symbols automatically.
In the same situation (as given in testcase) ld defines them as UND. gold defines as ABS with zero value.
I suggest just do not do anything in this case and let script handle everything.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 66947.Aug 5 2016, 7:42 AM
grimar retitled this revision from to [ELF] - Linkerscript: do not define _edata,_end,_etext if SECTIONS is used..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, davide and 2 others.
grimar added a comment.Aug 5 2016, 8:22 AM

With this + D23201, + D23165 + D22683 + slightly modified kernel linker script I was able to link FreeBSD kernel.
Though I am observing other problems now:

objcopy --only-keep-debug kernel.debug kernel.symbols
BFD: kernel.symbols: section `.eh_frame' can't be allocated in segment 3
objcopy: kernel.symbols: Bad value
Investigating it.

btw difference between my script and latest available is:

  1. It does not contain AT(). Actually that what is currently commited in FreeBSD release 10.3 head I think.
  2. Assignment to symbols inside output sections declarations (in *bss for example) I moved outside.

After that I verified that kernel works fine when linked with ld.

That's great news )

grimar added a comment.Aug 5 2016, 8:28 AM

That's great news )

But link != it works. Just means lld did not crash :)

ruiu accepted this revision.Aug 5 2016, 2:13 PM
ruiu edited edge metadata.

LGTM

ELF/Writer.cpp
602 ↗(On Diff #66947)

Can you inline this function? I think it is already well factored out, so we don't need to split it even more.

This revision is now accepted and ready to land.Aug 5 2016, 2:13 PM
This revision was automatically updated to reflect the committed changes.