Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#11022 closed bug (fixed)

Invalid ELF "note" section format

Reported by: hsyl20 Owned by:
Priority: normal Milestone: 8.0.1
Component: Driver Version: 7.10.2
Keywords: Cc:
Operating System: POSIX Architecture: Unknown/Multiple
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D1375
Wiki Page:

Description

GHC adds a section called ".debug-ghc-link-info" to ELF binaries (see compiler/main/DriverPipeline.hs:1660). The section type is "note" (SHT_NOTE) but the format is not compliant with the ELF specification (see http://refspecs.linuxbase.org/elf/elf.pdf section 2 "Note section"). It makes tools reading sections with "note" type fail.

I think we should change the section type to "progbits". Is there any problem with that?

Attachments (1)

0001-driver-use-PROGBITS-type-for-.debug-ghc-link-info-se.patch (1.7 KB) - added by hsyl20 2 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 2 years ago by bgamari

Milestone: 8.0.1

Sounds like the right thing to do. Are you offering a patch?

comment:2 Changed 2 years ago by hsyl20

Status: newpatch

comment:3 Changed 2 years ago by bgamari

Differential Rev(s): Phab:D1375

I've pushed this patch up to Phabricator as Phab:D1375 and written a bit more descriptive commit message.

comment:4 Changed 2 years ago by Ben Gamari <ben@…>

In f78b477b/ghc:

driver: use PROGBITS type for .debug-ghc-link-info section

Previously the `.debug-ghc-link-info` section was of type `SHT_NOTE` but
this is not compliant with the ELF specification, which requires that
`NOTE` sections are in a particular record-based format. We mark this
section as `PROGBITS` instead, which is defined as implying no
particular format.

Fixes #11022.

Reviewers: bgamari, austin

Reviewed By: bgamari, austin

Subscribers: thomie, hsyl20

Differential Revision: https://phabricator.haskell.org/D1375

GHC Trac Issues: #11022

comment:5 Changed 2 years ago by bgamari

Resolution: fixed
Status: patchclosed

Fixed. Thanks hsyl20!

comment:6 Changed 2 years ago by Ben Gamari <ben@…>

In 109d7ce/ghc:

Systools: read ELF section without calling readelf

This patch tackles two issues:

1) GHC stores a "link info" string into a ELF section. Initially a
section with type "note" was used but GHC didn't follow the ELF
specification which specifies a record-based format for these sections.
With D1375 we switched to a "progbits" section type for which there
isn't any format constraint. This is an issue for D1242 which use GCC's
--gc-sections which collects "unused" sections, such as our section
containing link info... In this patch, we fall back to a section with
type "note" but we respect the specified format.

2) Reading back the ELF section was done by parsing the result of a
call to "readelf". Calling readelf is problematic because the program
may not be available or it may be renamed on some platforms (see
D1326). Moreover we have no garanty that its output layout will stay
the same in future releases of readelf. Finally we would need to fix
the parsing to support  "note" sections because of 1. Instead, this
patch proposes to use Data.Binary.Get to directly read the "link info"
note into its section. ELF has a specification, hence it should work on
every conforming platform.

This patch "reverts" D1375, hence it supersedes D1432. It makes D1326
not necessary anymore.

Test Plan:
- recomp011 should pass (test that relinking is avoided when both "link
info" match)
- we should add a test for ELF objects with more than 0xff00 sections
=> added test "recomp015"
- we should check that GAS generates 32-bit words with .int on every
supported platform using ELF (or find a place where this is
documented). harbomaster and I (@hsyl20) only tested on x86-64. On
platforms where it is not true, it should make recomp011 fail. =>
tested to work on Linux/amd64, Solaris/i386 and OpenBSD/amd64

Reviewers: olsner, ony, thomie, kgardas, austin, bgamari

Reviewed By: thomie, bgamari

Subscribers: kgardas, rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D1381

GHC Trac Issues: #10974, #11022

comment:7 Changed 2 years ago by Ben Gamari <ben@…>

In ceaf0f46/ghc:

testsuite: Only run recomp015 on ELF-based platforms

It fails on OS X with hundreds of messages of the form,
```
ManySections.s:196576:10: error:
     error: mach-o section specifier uses an unknown section type
.section s65525,"",@progbits
         ^

ManySections.s:196579:10: error:
     error: mach-o section specifier uses an unknown section type
.section s65526,"",@progbits
```

It fails on Windows with messages of the form,
```
ManySections.s:196579:10: error:
     Error: junk at the end of line, first unrecognized character is ','
```

Test Plan: Validate

Reviewers: hsyl20, thomie, austin

Reviewed By: thomie, austin

Differential Revision: https://phabricator.haskell.org/D1601

GHC Trac Issues: #11022

comment:8 Changed 2 years ago by bgamari

I've also had to disable this test on ARM due to differences in the assembly syntax.

comment:9 Changed 2 years ago by Ben Gamari <ben@…>

In e2e24f2/ghc:

Disable recomp015 on ARM

Due to differences in assembly syntax. See #11022.
Note: See TracTickets for help on using tickets.