Project

General

Profile

Actions

Bug #15361

closed

ld doesn't fill out PT_DYNAMIC sufficiently for binutils 2.40

Added by Rich Lowe over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
tools - gate/build tools
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
External Bug:

Description

Since time immemorial, and probably the introduction of dynamic linking and ELF, we have not initialized the full set of fields in the PT_DYNAMIC phdr. Most especially, p_memsz has been left as 0.
This is wrong, but, again, has been this way forever.

Unfortunately, GNU binutils 2.40 introduced a change that relies on this information and utterly destroys any binary where this is the case.

We should fix the link-editor to initialize this information from the .dynamic section (and similarly, make sure we do this right for other similar things like PT_INTERP/.interp, PT_SUNW_UNWIND/.eh_frame_hdr, PT_SUNWCAP/SHT_SUNW_cap, etc.).
While doing this, we should make elfdump complain if this stuff is wrong, both for our own edification and such that we can tell people "if elfdump complains about an object, don't strip it!"

Actions #1

Updated by Rich Lowe over 1 year ago

I have tested this by building illumos and stripping some of our binaries, by editing a previously broken binary to contain a correct PT_DYNAMIC and checking gstrip now worked where previously it destroyed the binary.

I have tested elfdump by dumping every object I could find on my system and checking that the diagnostic output reflected reality (and by editing some objects to break them more, and checking elfdump noticed).

Actions #2

Updated by Electric Monk over 1 year ago

  • Gerrit CR set to 2620
Actions #3

Updated by Rich Lowe over 1 year ago

bulk build by andyf, I believe using the bad binutils version to be extra sure

Actions #4

Updated by Andy Fiddaman over 1 year ago

Yes, I have built a patched omnios bloody with this change in it, along with binutils 2.40, and done a bulk build, onu to DEBUG bits and then another bulk build. Everything appears fine, the second build exercised a great deal of things.

Actions #5

Updated by Electric Monk over 1 year ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100

git commit 9ef500b048240cd587d6751be934d070480b7124

commit  9ef500b048240cd587d6751be934d070480b7124
Author: Richard Lowe <richlowe@richlowe.net>
Date:   2023-02-17T19:05:18.000Z

    15361 ld doesn't fill out PT_DYNAMIC sufficiently for binutils 2.40
    Reviewed by: Andy Fiddaman <illumos@fiddaman.net>
    Reviewed by: Toomas Soome <tsoome@me.com>
    Reviewed by: Robert Mustacchi <rm+illumos@fingolfin.org>
    Approved by: Dan McDonald <danmcd@mnx.io>

Actions

Also available in: Atom PDF