This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj] Simplify p_filesz/p_memsz computing
ClosedPublic

Authored by MaskRay on Sep 5 2019, 11:35 PM.

Details

Summary

This fixes a bug as well. When "FileSize:" (p_filesz) is specified and
different from the actual value, the following code probably should not
use PHeader.p_filesz:

if (SHeader->sh_offset == PHeader.p_offset + PHeader.p_filesz)
  PHeader.p_memsz += SHeader->sh_size;

Diff Detail

Repository
rL LLVM

Event Timeline

MaskRay created this revision.Sep 5 2019, 11:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2019, 11:35 PM
grimar added a comment.Sep 6 2019, 2:26 AM

This looks good. Would be nice if someone else also take a look.

lib/ObjectYAML/ELFEmitter.cpp
630 ↗(On Diff #219031)

When I first saw FileEnd I thought it is somehow related to the end of file.
Maybe FileOffset vs MemOffset is better? (Or some different better names)

MaskRay updated this revision to Diff 219054.Sep 6 2019, 3:03 AM

Support multiple trailing SHT_NOBITS.

lld/ELF/Writer.cpp does not use the trick (two or more SHT_NOBITS are tricky and IIRC, when more than 1 SHF_TLS SHT_NOBITS sections are used, ld.bfd can get addresses wrong). However, since I can do it with 1 fewer line here :) Let me do it.

MaskRay updated this revision to Diff 219055.Sep 6 2019, 3:05 AM
MaskRay marked an inline comment as done.

FileEnd -> FileOffset
MemEnd -> MemOffset

jhenderson accepted this revision.Sep 9 2019, 8:29 AM

LGTM, I think.

This revision is now accepted and ready to land.Sep 9 2019, 8:29 AM
This revision was automatically updated to reflect the committed changes.