public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/7] ELF: Omit section header on ELF objects
@ 2020-03-10  0:12 H.J. Lu
  2020-03-10  0:12 ` [PATCH 1/7] ELF: Omit section header in " H.J. Lu
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: H.J. Lu @ 2020-03-10  0:12 UTC (permalink / raw)
  To: binutils

Section header isn't mandatory on ELF executable nor shared library.
This patch adds a new linker option, -z nosectionheader, to omit ELF
section header when building an executable or shared library, an
objcopy and strip option, --remove-section-header, to remove ELF
section header from an executable or shared library.

When there is no section header in an executable or shared library, we
reconstruct dynamic symbol table from the PT_DYNAMIC segment, which
contains DT_HASH/DT_GNU_HASH/DT_MIPS_XHASH, DT_STRTAB, DT_SYMTAB,
DT_STRSZ and DT_SYMENT entries, to improve nm and objdump.

H.J. Lu (5):
  bfd: Improve nm and objdump without section header
  readelf: Compute dynamic symbol table size from hash table
  binutils: Add --remove-section-header tests
  ld: Add tests for -z nosectionheader and --remove-section-header
  ld: Add -z nosectionheader test to bootstrap.exp

Kaylee Blake (2):
  ELF: Omit section header in ELF objects
  ld: Add a simple test for -z nosectionheader

 bfd/bfd-in2.h                                 |   8 +-
 bfd/bfd.c                                     |   8 +-
 bfd/elf-bfd.h                                 |  10 +
 bfd/elf.c                                     | 497 ++++++++++++++++++
 bfd/elfcode.h                                 |  83 ++-
 bfd/elflink.c                                 |  12 +
 bfd/elfxx-target.h                            |   6 +-
 binutils/NEWS                                 |   3 +
 binutils/doc/binutils.texi                    |  12 +
 binutils/objcopy.c                            |  54 +-
 binutils/readelf.c                            | 226 ++++----
 binutils/testsuite/binutils-all/objcopy.exp   |  13 +
 .../testsuite/binutils-all/remove-header-1.d  |   8 +
 ld/NEWS                                       |   3 +
 ld/emultempl/elf.em                           |   4 +
 ld/ld.h                                       |   3 +
 ld/ld.texi                                    |   6 +
 ld/ldlang.c                                   |   4 +
 ld/lexsup.c                                   |  12 +
 ld/testsuite/ld-bootstrap/bootstrap.exp       |  10 +-
 ld/testsuite/ld-elf/hash.d                    |   8 +-
 ld/testsuite/ld-elf/no-section-header.exp     | 374 +++++++++++++
 ld/testsuite/ld-elf/nosectionheader.d         |  12 +
 ld/testsuite/ld-elf/pr13195.d                 |   2 +-
 ld/testsuite/ld-elf/pr25617-1-no-sec-hdr.nd   |   3 +
 ld/testsuite/ld-elf/pr25617-1-no-sec-hdr.rd   |  20 +
 .../ld-elf/pr25617-1-static-no-sec-hdr.rd     |  12 +
 ld/testsuite/ld-elf/pr25617-1a-no-sec-hdr.nd  |   3 +
 ld/testsuite/ld-elf/pr25617-1a-no-sec-hdr.rd  |  20 +
 ld/testsuite/ld-elf/pr25617-1a-sec-hdr.rd     |  19 +
 ld/testsuite/ld-elf/pr25617-1a.c              |  11 +
 ld/testsuite/ld-elf/pr25617-1b.c              |  15 +
 ld/testsuite/ld-elf/start-noheader.rd         |  11 +
 .../ld-elf/start-shared-noheader-gnu.rd       |  22 +
 .../ld-elf/start-shared-noheader-sysv.rd      |  22 +
 ld/testsuite/ld-elf/start-shared-noheader.nd  |   5 +
 ld/testsuite/ld-elfvsb/hidden2.d              |   2 +-
 ld/testsuite/ld-mips-elf/hash2.d              |   8 +-
 38 files changed, 1406 insertions(+), 145 deletions(-)
 create mode 100644 binutils/testsuite/binutils-all/remove-header-1.d
 create mode 100644 ld/testsuite/ld-elf/no-section-header.exp
 create mode 100644 ld/testsuite/ld-elf/nosectionheader.d
 create mode 100644 ld/testsuite/ld-elf/pr25617-1-no-sec-hdr.nd
 create mode 100644 ld/testsuite/ld-elf/pr25617-1-no-sec-hdr.rd
 create mode 100644 ld/testsuite/ld-elf/pr25617-1-static-no-sec-hdr.rd
 create mode 100644 ld/testsuite/ld-elf/pr25617-1a-no-sec-hdr.nd
 create mode 100644 ld/testsuite/ld-elf/pr25617-1a-no-sec-hdr.rd
 create mode 100644 ld/testsuite/ld-elf/pr25617-1a-sec-hdr.rd
 create mode 100644 ld/testsuite/ld-elf/pr25617-1a.c
 create mode 100644 ld/testsuite/ld-elf/pr25617-1b.c
 create mode 100644 ld/testsuite/ld-elf/start-noheader.rd
 create mode 100644 ld/testsuite/ld-elf/start-shared-noheader-gnu.rd
 create mode 100644 ld/testsuite/ld-elf/start-shared-noheader-sysv.rd
 create mode 100644 ld/testsuite/ld-elf/start-shared-noheader.nd

-- 
2.24.1


^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH 0/7] ELF: Don't require section header on ELF objects
@ 2020-03-08 23:42 H.J. Lu
  2020-03-08 23:42 ` [PATCH 3/7] readelf: Compute dynamic symbol table size from hash table H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-03-08 23:42 UTC (permalink / raw)
  To: binutils

Section header isn't mandatory on ELF executable nor shared library.
This patch set adds a new linker option, -z nosectionheader, to omit
ELF section header when building an executable or shared library, an
objcopy and strip option, --remove-section-header, to remove ELF
section header from an executable or shared library.

The PT_DYNAMIC segment contains DT_HASH/DT_GNU_HASH/DT_MIPS_XHASH,
DT_STRTAB, DT_SYMTAB, DT_STRSZ and DT_SYMENT entries, which can be
used to reconstruct dynamic symbol table when section header isn't
available.  For DT_HASH, the number of dynamic symbol table entries
equals the number of chains.  For DT_GNU_HASH/DT_MIPS_XHASH, only
defined symbols with non-STB_LOCAL indings are in hash table.  Since
in dynamic symbol table, all symbols with STB_LOCAL binding are placed
before symbols with other bindings and all undefined symbols are placed
before defined ones, the highest symbol index in DT_GNU_HASH and
DT_MIPS_XHASH is the highest dynamic symbol table index.


H.J. Lu (5):
  bfd: Reconstruct dynamic symbol table from PT_DYNAMIC segment
  readelf: Compute dynamic symbol table size from hash table
  binutils: Add --remove-section-header tests
  ld: Add tests for -z nosectionheader and --remove-section-header
  ld: Add -z nosectionheader test to bootstrap.exp

Kaylee Blake (2):
  ELF: Don't require section header on ELF objects
  ld: Add a simple test for -z nosectionheader

 bfd/bfd-in2.h                                 |   8 +-
 bfd/bfd.c                                     |   8 +-
 bfd/elf-bfd.h                                 |   8 +
 bfd/elf.c                                     | 443 ++++++++++++++++++
 bfd/elfcode.h                                 | 174 ++++++-
 bfd/elflink.c                                 | 148 ++++--
 bfd/elfxx-target.h                            |   6 +-
 binutils/NEWS                                 |   3 +
 binutils/doc/binutils.texi                    |  12 +
 binutils/objcopy.c                            |  54 ++-
 binutils/readelf.c                            | 226 ++++-----
 binutils/testsuite/binutils-all/objcopy.exp   |  13 +
 .../testsuite/binutils-all/remove-header-1.d  |   8 +
 ld/NEWS                                       |   3 +
 ld/emultempl/elf.em                           |   4 +
 ld/ld.h                                       |   3 +
 ld/ld.texi                                    |   6 +
 ld/ldlang.c                                   |   4 +
 ld/lexsup.c                                   |  12 +
 ld/testsuite/ld-bootstrap/bootstrap.exp       |  10 +-
 ld/testsuite/ld-elf/hash.d                    |   8 +-
 ld/testsuite/ld-elf/no-section-header.exp     | 336 +++++++++++++
 ld/testsuite/ld-elf/nosectionheader.d         |  12 +
 ld/testsuite/ld-elf/pr13195.d                 |   2 +-
 ld/testsuite/ld-elf/pr22393-2a-no-sec-hdr.nd  |   3 +
 ld/testsuite/ld-elf/pr22393-2a-no-sec-hdr.rd  |  20 +
 ld/testsuite/ld-elf/pr22393-2a-sec-hdr.rd     |  19 +
 ld/testsuite/ld-elf/pr22393-2b-no-sec-hdr.nd  |   3 +
 ld/testsuite/ld-elf/pr22393-2b-no-sec-hdr.rd  |  20 +
 .../ld-elf/pr22393-2b-static-no-sec-hdr.rd    |  12 +
 ld/testsuite/ld-elf/start-noheader.rd         |  11 +
 .../ld-elf/start-shared-noheader-gnu.rd       |  22 +
 .../ld-elf/start-shared-noheader-sysv.rd      |  22 +
 ld/testsuite/ld-elf/start-shared-noheader.nd  |   5 +
 ld/testsuite/ld-elfvsb/hidden2.d              |   2 +-
 ld/testsuite/ld-mips-elf/hash2.d              |   8 +-
 36 files changed, 1458 insertions(+), 200 deletions(-)
 create mode 100644 binutils/testsuite/binutils-all/remove-header-1.d
 create mode 100644 ld/testsuite/ld-elf/no-section-header.exp
 create mode 100644 ld/testsuite/ld-elf/nosectionheader.d
 create mode 100644 ld/testsuite/ld-elf/pr22393-2a-no-sec-hdr.nd
 create mode 100644 ld/testsuite/ld-elf/pr22393-2a-no-sec-hdr.rd
 create mode 100644 ld/testsuite/ld-elf/pr22393-2a-sec-hdr.rd
 create mode 100644 ld/testsuite/ld-elf/pr22393-2b-no-sec-hdr.nd
 create mode 100644 ld/testsuite/ld-elf/pr22393-2b-no-sec-hdr.rd
 create mode 100644 ld/testsuite/ld-elf/pr22393-2b-static-no-sec-hdr.rd
 create mode 100644 ld/testsuite/ld-elf/start-noheader.rd
 create mode 100644 ld/testsuite/ld-elf/start-shared-noheader-gnu.rd
 create mode 100644 ld/testsuite/ld-elf/start-shared-noheader-sysv.rd
 create mode 100644 ld/testsuite/ld-elf/start-shared-noheader.nd

-- 
2.24.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-03-20  7:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-10  0:12 [PATCH 0/7] ELF: Omit section header on ELF objects H.J. Lu
2020-03-10  0:12 ` [PATCH 1/7] ELF: Omit section header in " H.J. Lu
2020-03-10  0:12 ` [PATCH 1/7] ELF: Omit section header on " H.J. Lu
2020-03-20  7:11   ` Alan Modra
2020-03-10  0:12 ` [PATCH 2/7] bfd: Improve nm and objdump without section header H.J. Lu
2020-03-12  3:11   ` Fangrui Song
2020-03-10  0:12 ` [PATCH 3/7] readelf: Compute dynamic symbol table size from hash table H.J. Lu
2020-03-10  0:12 ` [PATCH 4/7] ld: Add a simple test for -z nosectionheader H.J. Lu
2020-03-10  0:12 ` [PATCH 5/7] binutils: Add --remove-section-header tests H.J. Lu
2020-03-10  0:12 ` [PATCH 6/7] ld: Add tests for -z nosectionheader and --remove-section-header H.J. Lu
2020-03-10  0:12 ` [PATCH 7/7] ld: Add -z nosectionheader test to bootstrap.exp H.J. Lu
  -- strict thread matches above, loose matches on Subject: below --
2020-03-08 23:42 [PATCH 0/7] ELF: Don't require section header on ELF objects H.J. Lu
2020-03-08 23:42 ` [PATCH 3/7] readelf: Compute dynamic symbol table size from hash table H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).