This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Fix for: error "invalid section index: xxx" when linking FreeBSD kernel.
ClosedPublic

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

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 66932.Aug 5 2016, 5:42 AM
grimar retitled this revision from to [ELF] - Fix for: error "invalid section index: xxx" when linking FreeBSD kernel..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
grimar added a subscriber: davide.Aug 5 2016, 7:27 AM
grimar added a comment.EditedAug 8 2016, 3:32 AM

testcase?

hpt27xx_lib.o file used in bug is prebuilt and has about 1.1mb size. I do not know way to reduce it or to produce
smaller sample. Should I use it or we can just rely on the fact that the change works for linking it in BSD world ?

testcase?

hpt27xx_lib.o file used in bug is prebuilt and has about 1.1mb size. I do not know way to reduce it or to produce
smaller sample. Should I use it or we can just rely on the fact that the change works for linking it in BSD world ?

No. Not quite. We don't have a FreeBSD buildbot that does CI and even if we had it this code can break at any time and it will require somebody (likely me or Ed Maste) to ask for a revert. Please take the time to reduce this test case.

ruiu edited edge metadata.Aug 8 2016, 3:01 PM

As Davide pointed out, it needs a testcase. This is a subtle change, and I'm not sure if this is a bug of LLD.

grimar added a comment.Aug 9 2016, 1:09 AM
In D23201#509124, @ruiu wrote:

As Davide pointed out, it needs a testcase. This is a subtle change, and I'm not sure if this is a bug of LLD.

I think it is definely not an issue of lld. But since that file was precompiled in the wild and ld works fine here, I think we also should
support this case, right ?
I`ll try to reduce it and prepare testcase, though I have no idea now how to do that since as I mentioned it is precompiled.

davide added a comment.Aug 9 2016, 1:14 AM
In D23201#509124, @ruiu wrote:

As Davide pointed out, it needs a testcase. This is a subtle change, and I'm not sure if this is a bug of LLD.

I think it is definely not an issue of lld. But since that file was precompiled in the wild and ld works fine here, I think we also should
support this case, right ?
I`ll try to reduce it and prepare testcase, though I have no idea now how to do that since as I mentioned it is precompiled.

You can probably localize the issue is and create a llvm-mc testcase which reproduces it.
If you can't you can check in a small binary (modified with hexedit or something similar) or use yaml2obj to craft an object of this kind.

grimar updated this revision to Diff 67308.Aug 9 2016, 3:01 AM
grimar edited edge metadata.
  • Created testcase.
ruiu added a comment.Aug 9 2016, 11:04 AM

Now that I understand what kind of file you are trying to handle. This seems pretty weird. How does this happen? Do you know who created that file?

ELF/InputFiles.cpp
345 ↗(On Diff #67308)

This is not a good place to fix it. Set InputSectionBase<ELFT>::Discarded to REL/RELA sections instead.

emaste added a subscriber: emaste.Aug 9 2016, 1:13 PM
In D23201#510172, @ruiu wrote:

Now that I understand what kind of file you are trying to handle. This seems pretty weird. How does this happen? Do you know who created that file?

I am not certain about hpt27xx_lib.o, but a similar case in FreeBSD was due to the outdated GNU binutils 2.17.50 that we have, and has now been fixed by https://svnweb.freebsd.org/base?view=revision&revision=303158

ruiu added a comment.Aug 9 2016, 2:26 PM

Ed, do you happen to know the ld version number that produced wrong object files? I think we are fine with this change, but I'd like to add that information as the comment.

davide added a comment.Aug 9 2016, 2:27 PM
In D23201#510474, @ruiu wrote:

Ed, do you happen to know the ld version number that produced wrong object files? I think we are fine with this change, but I'd like to add that information as the comment.

davide@freefall:~ % ld --version
GNU ld 2.17.50 [FreeBSD] 2007-07-03
Copyright 2007 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.
davide added a comment.Aug 9 2016, 2:28 PM
In D23201#510474, @ruiu wrote:

Ed, do you happen to know the ld version number that produced wrong object files? I think we are fine with this change, but I'd like to add that information as the comment.

Actually, I think you might want the version of as(1). It's the same.

% as --version
GNU assembler 2.17.50 [FreeBSD] 2007-07-03
Copyright 2007 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.
This assembler was configured for a target of `x86_64-unknown-freebsd'.
ruiu added a comment.Aug 9 2016, 2:30 PM

Thanks, Davide. George, please include that information to this patch.

grimar updated this revision to Diff 67487.Aug 10 2016, 2:12 AM
  • Addressed review comments.
grimar added inline comments.Aug 10 2016, 2:17 AM
ELF/InputFiles.cpp
345 ↗(On Diff #67308)

Ok, BTW, it also touches .shstrtab, .symtab, .strtab sections in originall issue.
I updated testcase and code.

ruiu added inline comments.Aug 10 2016, 11:13 AM
ELF/InputFiles.cpp
279–280 ↗(On Diff #67487)

Hmm, why did you add more conditions?

ELF/Writer.cpp
100–101 ↗(On Diff #67487)

Why did you have to make a change to this code?

grimar added inline comments.Aug 11 2016, 1:18 AM
ELF/InputFiles.cpp
279–280 ↗(On Diff #67487)

Because hpt27xx_lib.o which initially was the reason to fix all of that
contains section symbols associated with
.rela.text, .rela.rodata, .rela.data, .rela.eh_frame, .shstrtab, .symtab, .strtab
See https://llvm.org/bugs/show_bug.cgi?id=28868

Testcase also has them:

  • Type: STT_SECTION Section: .rela.text
  • Type: STT_SECTION Section: .shstrtab
  • Type: STT_SECTION Section: .symtab
  • Type: STT_SECTION Section: .strtab
ELF/Writer.cpp
100–101 ↗(On Diff #67487)

Because since these sections are mo more nullptr, but discarded, the code below is executed
and it is not possible to call IS->getFile()->getName() when IS is InputSection<ELFT>::Discarded,
because File member is null.

By the way, I have to notice that initial version of the patch has only 2 lines of code changed.
May be we can go with it ?

ruiu added a comment.Aug 11 2016, 2:57 PM

OK, please revert to the original patch. But please keep the comment. Comments to describe why you needed these changes are as important as the code that does them.

grimar updated this revision to Diff 67809.Aug 12 2016, 2:40 AM
  • Reverted code to initial diff.
ruiu accepted this revision.Aug 12 2016, 10:58 AM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Aug 12 2016, 10:58 AM
This revision was automatically updated to reflect the committed changes.