This is an archive of the discontinued LLVM Phabricator instance.

Omit PT_NOTE for SHT_NOTE without SHF_ALLOC
ClosedPublic

Authored by emaste on May 8 2018, 7:41 PM.

Details

Summary

A non-alloc note section should not have a PT_NOTE program header.

Found while linking ghc (Haskell compiler) with lld on FreeBSD. Haskell emits a .debug-ghc-link-info note section (as the name suggests, it contains link info) as a SHT_NOTE section without SHF_ALLOC set.

For this case ld.bfd does not emit a PT_NOTE segment for .debug-ghc-link-info. lld previously emitted a PT_NOTE with p_vaddr = 0 and FreeBSD's rtld segfaulted when trying to parse a note at address 0.

llvm.org/pr37361
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=226872

Diff Detail

Repository
rL LLVM

Event Timeline

emaste created this revision.May 8 2018, 7:41 PM
emaste added a comment.May 8 2018, 7:53 PM

@arichardson @dim I'm also looking for approval to commit the change to FreeBSD (perhaps in advance of committing upstream), with a bump of the FreeBSD-specific version to LLD_REVISION_STRING "326565-1200002" - I might as well solicit that via this review.

dim accepted this revision.May 9 2018, 3:44 AM

I'm fine with this, and also with committing it into FreeBSD's copy of lld, but I'd like to see the opinion of @ruiu and/or @grimar too. (I take it @espindola is no longer being monitored...)

This revision is now accepted and ready to land.May 9 2018, 3:44 AM
emaste added a comment.May 9 2018, 4:03 AM

Yeah, @espindola was added by a Herald rule.

emaste added a comment.May 9 2018, 4:19 AM

Committed to FreeBSD in r333401

ruiu added a comment.May 9 2018, 10:53 AM

I have a few questions:

  1. what is the content of .debug-ghc-link-info? If the section contains an optional, human-readable string, they might have just used .comment instead.
  2. Does this patch work when we have a .debug-ghc-link-info and we also need to create a PT_NOTE section for other .note section?
  1. what is the content of .debug-ghc-link-info? If the section contains an optional, human-readable string, they might have just used .comment instead.

I think it's the link invocation command line. It is human-readable, and I agree they could probably use .comment, but this is what they're producing today. I think they used this so strip will strip it as a .debug section.

  1. Does this patch work when we have a .debug-ghc-link-info and we also need to create a PT_NOTE section for other .note section?

It does, this is actually the case in FreeBSD - we had one PT_NOTE containing our ABI tag and one containing the .debug-ghc-link-info content; with the patch we have just the ABI tag PT_NOTE. I think the test could be extended to confirm but I guess it's probably not necessary.

ruiu added a comment.May 9 2018, 11:18 AM
  1. Does this patch work when we have a .debug-ghc-link-info and we also need to create a PT_NOTE section for other .note section?

It does, this is actually the case in FreeBSD - we had one PT_NOTE containing our ABI tag and one containing the .debug-ghc-link-info content; with the patch we have just the ABI tag PT_NOTE. I think the test could be extended to confirm but I guess it's probably not necessary.

I think that the test would be useful because it covers the most common use case. Other than that, this change looks good.

emaste updated this revision to Diff 146057.May 9 2018, 8:22 PM
emaste removed a reviewer: espindola.
ruiu accepted this revision.May 9 2018, 8:29 PM

LGTM

This revision was automatically updated to reflect the committed changes.

This LGTM too.
I would add/change the test cases for notes though. Will post a patch for review.