This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF] Fix problems with fabricateDefaultCommands() and --section-start
ClosedPublic

Authored by peter.smith on May 2 2017, 7:16 AM.

Details

Summary

The --section-start <name>=<address> needs to be translated into equivalent linker script commands. There are a couple of problems with the existing implementation:

  • The --section-start with the lowest address is assumed to be at the start of the map. This assumption is incorrect, we have to iterate through the SectionStartMap to find the lowest address.
  • The addresses in --section-start were being over-aligned when the sections were marked as PageAlign. This is inconsistent with the use of SectionStartMap in fixHeaders(), and can cause problems when the PageAlign causes an "unable to move location counter backward" error when the --section-start section with PageAlign is aligned to an address higher than the next --section-start without PageAlign. The ld.bfd and ld.gold seem to be more consistent with this interpretation but this is not a well specified area.

This change fixes the problems above and also corrects a typo in which fabricateDefaultCommands() is called with the wrong parameter, it should be called with AllocateHeader not Config->MaxPageSize.

The problems were found while investigating dmikulin's comments in D31888 , however I don't think that these changes are directly related.

Diff Detail

Repository
rL LLVM

Event Timeline

peter.smith created this revision.May 2 2017, 7:16 AM
ruiu accepted this revision.May 2 2017, 3:43 PM

LGTM

ELF/LinkerScript.cpp
431–433 ↗(On Diff #97445)

Can you add full stops to this comment?

434 ↗(On Diff #97445)

You don't need to check if it is empty, as the following for-loop loops 0 times if it is empty.

This revision is now accepted and ready to land.May 2 2017, 3:43 PM
This revision was automatically updated to reflect the committed changes.