[ELF] Fix problems with fabricateDefaultCommands() and --section-start
authorPeter Smith <peter.smith@linaro.org>
Wed, 3 May 2017 08:44:50 +0000 (08:44 +0000)
committerPeter Smith <peter.smith@linaro.org>
Wed, 3 May 2017 08:44:50 +0000 (08:44 +0000)
commitc60b4510ea6db9726fd4870381ca8486d862e9b8
tree342ef6f0e56a08254a16c94a5d9e846f68b4679d
parent99e1890e71b27fac5999a6cb7f78305b83f9cb1f
[ELF] Fix problems with fabricateDefaultCommands() and --section-start

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 with PageAlign is aligned to an address higher than the next
--section-start. The ld.bfd and ld.gold seem to be more consistent with this
approach 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.

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

llvm-svn: 302007
lld/ELF/LinkerScript.cpp
lld/ELF/Writer.cpp
lld/test/ELF/sectionstart-noallochdr.s [new file with mode: 0644]