[all-commits] [llvm/llvm-project] acb66b: [ELF] --oformat=binary: use LMA to compute file of...

Fangrui Song via All-commits all-commits at lists.llvm.org
Wed Aug 5 09:10:57 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: acb66b9111ba793509b5468a58107108317b7cf5
      https://github.com/llvm/llvm-project/commit/acb66b9111ba793509b5468a58107108317b7cf5
  Author: Fangrui Song <i at maskray.me>
  Date:   2020-08-05 (Wed, 05 Aug 2020)

  Changed paths:
    M lld/ELF/Writer.cpp
    M lld/test/ELF/oformat-binary-ttext.s
    M lld/test/ELF/oformat-binary.s

  Log Message:
  -----------
  [ELF] --oformat=binary: use LMA to compute file offsets

--oformat=binary is rare (used in a few places in FreeBSD, see `stand/i386/mbr/Makefile` `LDFLAGS_BIN`)
The result should be identical to a normal output transformed by `objcopy -O binary`.

The current implementation ignores addresses and lays out sections by
respecting output section alignments. It can fail when an output section
address is specified, e.g. `.rodata ALIGN(16) :` (PR33651).

Fix PR33651 by respecting LMA. The code is similar to
`tools/llvm-objcop/ELF/Object.cpp` BinaryWriter::finalize after D71035 and D79229.
Unforunately for an output section without PT_LOAD, we assume its LMA is equal
to its VMA. So the result is still incorrect when an output section LMA
(`AT(...)`) is specified

Also drop `alignTo(off, config->wordsize)`. GNU ld does not round up the file size.

Differential Revision: https://reviews.llvm.org/D85086




More information about the All-commits mailing list