This is an archive of the discontinued LLVM Phabricator instance.

[lld] [ELF] Fix linking when a regular object defines a symbol that is used in a DSO
ClosedPublic

Authored by rafaelauler on Sep 19 2014, 9:41 PM.

Details

Summary

When a shared lib has an undefined symbol that is defined in a regular object (the program), the final executable must export this symbol in the dynamic symbol table. However, in the current logic, lld only puts the symbol in the dynamic symbol table if the symbol is weak. This patch fixes lld to put the symbol in the dynamic symbol table regardless if it is weak or not.

This caused a problem in FreeBSD10, whose programs link against a crt1.o that defines the symbol __progname, which is, in turn, undefined in libc.so.7 and will only be resolved in runtime.

Diff Detail

Event Timeline

rafaelauler retitled this revision from to [lld] [ELF] Fix linking when a regular object defines a symbol that is used in a DSO.
rafaelauler updated this object.
rafaelauler edited the test plan for this revision. (Show Details)
rafaelauler added reviewers: ruiu, rafael, Bigcheese.
rafaelauler added a project: lld.
rafaelauler added a subscriber: Unknown Object (MLST).
shankarke accepted this revision.Sep 20 2014, 2:58 PM
shankarke added a reviewer: shankarke.
shankarke added a subscriber: shankarke.

LGTM.

This revision is now accepted and ready to land.Sep 20 2014, 2:58 PM
emaste added a subscriber: emaste.Sep 20 2014, 4:22 PM

Hi Shankar,

I don't have commit access, could you please commit it?

Thanks,
Rafael Auler

rafaelauler edited edge metadata.

Hi Rui,

I updated the patch to use obj2yaml and yaml2obj to avoid binary files. While I was able to do this to the simple defobj.o file, I was not able to convert the YAML form of libundef2.so to a .so file. The error I got was:

error: Unknown section referenced: '.dynsym' at YAML section '.hash'.

Then I investigated my libundef2.so yaml representation and noticed that it was really missing .dymsym. I looked obj2yaml's source code and found this:

// Dump sections
for (const Elf_Shdr &Sec : Obj.sections()) {
  switch (Sec.sh_type) {
  case ELF::SHT_NULL:
  case ELF::SHT_SYMTAB:
  case ELF::SHT_DYNSYM:
  case ELF::SHT_STRTAB:
    // Do not dump these sections.

...which suggested that the tool currently does not support dumping the dynamic symbol table.

Therefore, my new patch still depends on uploading the libundef2.so binary file. Is there any problem?

Best regards,
Rafael Auler

ruiu edited edge metadata.Sep 22 2014, 12:08 PM

If the tool does not support that and if it would take time to add the
feature, it's OK to check in binary files for now.

But your patch does not contain the .so file because diff does not compare
binary files. Please send me the file so that I can submit.

rafaelauler edited edge metadata.

I saw some examples from ELF/MIPS testing and updated my patch to generate the shared library on the fly, in this way we avoid the binary file.

rafaelauler closed this revision.Sep 29 2014, 3:48 PM