HomePhabricator

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

Authored by MaskRay on Aug 5 2020, 9:04 AM.

Description

[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

Details

Committed
MaskRayAug 5 2020, 9:10 AM
Differential Revision
D85086: [ELF] --oformat=binary: use LMA to compute file offsets
Parents
rG98d91aecb26a: Add libFuzzer shared object build output
Branches
Unknown
Tags
Unknown