This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Ignore non-absolute R_386_GOTPC relocation in debug sections.
ClosedPublic

Authored by grimar on Oct 6 2017, 7:01 AM.

Details

Summary

This is PR34852.

Looks gcc has a bug and produce R_386_GOTPC relocation in '.rel.debug_info':
Only i386 target and all gcc versions atm are affected it seems.
ld.bfd behavior is to silently resolve the relocation. Given the code we have, I think we can try to ignore it in LLD.

Diff Detail

Event Timeline

grimar created this revision.Oct 6 2017, 7:01 AM
ruiu edited edge metadata.Oct 6 2017, 12:32 PM

Where is the bug for gcc, and what was a response from gcc develoeprs?

grimar added a comment.Oct 7 2017, 6:16 AM
In D38625#890908, @ruiu wrote:

Where is the bug for gcc, and what was a response from gcc develoeprs?

I did not find bug report page or something like that, but gcc-5.4 produce section that is not readable by
dwarfdump tool for me:
dwarfdump ERROR: dwarf_get_loclist_from_expr_a: DW_DLE_LOC_EXPR_BAD (128)

And this section has PC relocation, while other compilers or versions of gcc does not do that and produce
correctly readable section. I assume it is a bug of gcc.

ruiu added a comment.Oct 9 2017, 1:24 PM

Please report a bug to gcc first.

grimar updated this revision to Diff 119637.Oct 20 2017, 1:54 AM
grimar edited the summary of this revision. (Show Details)
  • Addressed review comments, updated comment.
grimar accepted this revision.Oct 24 2017, 12:47 AM

Accepted by Rafael in mail list.
Rui, are you OK to land this one ?

This revision is now accepted and ready to land.Oct 24 2017, 12:47 AM
ruiu added inline comments.Oct 24 2017, 1:52 PM
ELF/InputSection.cpp
686–690

// GCC 8.0 or earlier have a bug that it emits R_386_GOTPC relocations against _GLOBAL_OFFSET_TABLE for .debug_info. The bug seems to have been fixed in 2017 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82630), but we need to keep this bug-compatible code for a while.

Also, you should be more explicit on what you are doing. Specifically, you should avoid calling getRelExpr.

ruiu requested changes to this revision.Oct 24 2017, 1:52 PM
This revision now requires changes to proceed.Oct 24 2017, 1:52 PM
grimar added inline comments.Oct 25 2017, 2:36 AM
ELF/InputSection.cpp
686–690

Maximal explicit way I think would be to check exact target specific relocation and a symbol name here.
Do you prefer to check for R_386_GOTPC or both R_386_GOTPC and _GLOBAL_OFFSET_TABLE_ symbol name here ?

ruiu added inline comments.Oct 25 2017, 2:45 PM
ELF/InputSection.cpp
686–690

Config->EMachine == EM_386 && Type == R_386_GOTPC should suffice.

grimar updated this revision to Diff 120393.Oct 26 2017, 4:08 AM
grimar edited edge metadata.
  • Addressed review comments.
ruiu accepted this revision.Oct 26 2017, 10:59 AM

LGTM

test/ELF/i386-debug-noabs.test
8–9

This is for https://bugs.llvm.org//show_bug.cgi?id=34852. GCC 8.0 or earlier have a bug which creates non-absolute R_386_GOTPC relocations in non-allocated sections. It is illegal, but we want to make sure that lld skips them instead of reporting errors.

This revision is now accepted and ready to land.Oct 26 2017, 10:59 AM
This revision was automatically updated to reflect the committed changes.