[lld][LayoutPass] An earlier commit moved the functionality so that Atoms would

be laid out by their ordinal overrides first, there was a bug that two atoms may 
get the same override index due to which atoms were not ordered properly. This
commit fixes the problem.

Now the atoms are ordered by 

- Section Position hints
- Atom override (Using layout-after/layout-before/in-group)
- Content Permissions
- Content Type
- File Ordinal

This also fixes the problem of running c++ static executables that 
was broken by an earlier patch.

llvm-svn: 182494
This commit is contained in:
Shankar Easwaran 2013-05-22 17:41:04 +00:00
parent ef5f065f88
commit d8da989e78
6 changed files with 93 additions and 93 deletions

View File

@ -31,6 +31,20 @@ bool LayoutPass::CompareAtoms::operator()(const DefinedAtom *left,
if (left == right)
return false;
// Sort by section position preference.
DefinedAtom::SectionPosition leftPos = left->sectionPosition();
DefinedAtom::SectionPosition rightPos = right->sectionPosition();
DEBUG(llvm::dbgs() << "Sorting by sectionPos"
<< "(" << leftPos << "," << rightPos << ")\n");
bool leftSpecialPos = (leftPos != DefinedAtom::sectionPositionAny);
bool rightSpecialPos = (rightPos != DefinedAtom::sectionPositionAny);
if (leftSpecialPos || rightSpecialPos) {
if (leftPos != rightPos)
return leftPos < rightPos;
}
DEBUG(llvm::dbgs() << "Sorting by override\n");
AtomToOrdinalT::const_iterator lPos = _layout._ordinalOverrideMap.find(left);
@ -77,20 +91,6 @@ bool LayoutPass::CompareAtoms::operator()(const DefinedAtom *left,
// TO DO: Sort atoms in customs sections together.
// Sort by section position preference.
DefinedAtom::SectionPosition leftPos = left->sectionPosition();
DefinedAtom::SectionPosition rightPos = right->sectionPosition();
DEBUG(llvm::dbgs() << "Sorting by sectionPos"
<< "(" << leftPos << "," << rightPos << ")\n");
bool leftSpecialPos = (leftPos != DefinedAtom::sectionPositionAny);
bool rightSpecialPos = (rightPos != DefinedAtom::sectionPositionAny);
if (leftSpecialPos || rightSpecialPos) {
if (leftPos != rightPos)
return leftPos < rightPos;
}
// Sort by .o order.
const File *leftFile = &left->file();
const File *rightFile = &right->file();
@ -392,7 +392,7 @@ void LayoutPass::buildOrdinalOverrideMap(MutableFile::DefinedAtomRange &range) {
}
}
} else {
_ordinalOverrideMap[atom] = index;
_ordinalOverrideMap[atom] = index++;
}
}
}

View File

@ -82,6 +82,62 @@ CHECKGOTPLT: offset: 8
CHECKGOTPLT: - kind: R_HEX_B22_PCREL
CHECKGOTPLT: offset: 12
target: __plt_fn2
- name: .PLT0
CHECKGOTPLT: type: stub
CHECKGOTPLT: content: [ 00, 40, 00, 00, 1C, C0, 49, 6A, 0E, 42, 9C, E2,
CHECKGOTPLT: 4F, 40, 9C, 91, 3C, C0, 9C, 91, 0E, 42, 0E, 8C,
CHECKGOTPLT: 00, C0, 9C, 52 ]
CHECKGOTPLT: alignment: 2^4
CHECKGOTPLT: section-name: .plt
CHECKGOTPLT: references:
CHECKGOTPLT: - kind: R_HEX_B32_PCREL_X
CHECKGOTPLT: offset: 0
target: __got0
CHECKGOTPLT: - kind: R_HEX_6_PCREL_X
CHECKGOTPLT: offset: 4
target: __got0
- name: __plt_fn
CHECKGOTPLT: type: stub
CHECKGOTPLT: content: [ 00, 40, 00, 00, 0E, C0, 49, 6A, 1C, C0, 8E, 91,
CHECKGOTPLT: 00, C0, 9C, 52 ]
CHECKGOTPLT: alignment: 2^4
CHECKGOTPLT: section-name: .plt
CHECKGOTPLT: references:
CHECKGOTPLT: - kind: R_HEX_B32_PCREL_X
CHECKGOTPLT: offset: 0
target: __got_fn
CHECKGOTPLT: - kind: R_HEX_6_PCREL_X
CHECKGOTPLT: offset: 4
target: __got_fn
CHECKGOTPLT: addend: 4
- name: __plt_fn1
CHECKGOTPLT: type: stub
CHECKGOTPLT: content: [ 00, 40, 00, 00, 0E, C0, 49, 6A, 1C, C0, 8E, 91,
CHECKGOTPLT: 00, C0, 9C, 52 ]
CHECKGOTPLT: alignment: 2^4
CHECKGOTPLT: section-name: .plt
CHECKGOTPLT: references:
CHECKGOTPLT: - kind: R_HEX_B32_PCREL_X
CHECKGOTPLT: offset: 0
target: __got_fn1
CHECKGOTPLT: - kind: R_HEX_6_PCREL_X
CHECKGOTPLT: offset: 4
target: __got_fn1
CHECKGOTPLT: addend: 4
- name: __plt_fn2
CHECKGOTPLT: type: stub
CHECKGOTPLT: content: [ 00, 40, 00, 00, 0E, C0, 49, 6A, 1C, C0, 8E, 91,
CHECKGOTPLT: 00, C0, 9C, 52 ]
CHECKGOTPLT: alignment: 2^4
CHECKGOTPLT: section-name: .plt
CHECKGOTPLT: references:
CHECKGOTPLT: - kind: R_HEX_B32_PCREL_X
CHECKGOTPLT: offset: 0
target: __got_fn2
CHECKGOTPLT: - kind: R_HEX_6_PCREL_X
CHECKGOTPLT: offset: 4
target: __got_fn2
CHECKGOTPLT: addend: 4
- name: __got0
CHECKGOTPLT: type: got
CHECKGOTPLT: content: [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,
@ -147,59 +203,3 @@ CHECKGOTPLT: target: fn2
CHECKGOTPLT: - kind: R_HEX_32
CHECKGOTPLT: offset: 0
target: .PLT0
- name: .PLT0
CHECKGOTPLT: type: stub
CHECKGOTPLT: content: [ 00, 40, 00, 00, 1C, C0, 49, 6A, 0E, 42, 9C, E2,
CHECKGOTPLT: 4F, 40, 9C, 91, 3C, C0, 9C, 91, 0E, 42, 0E, 8C,
CHECKGOTPLT: 00, C0, 9C, 52 ]
CHECKGOTPLT: alignment: 2^4
CHECKGOTPLT: section-name: .plt
CHECKGOTPLT: references:
CHECKGOTPLT: - kind: R_HEX_B32_PCREL_X
CHECKGOTPLT: offset: 0
target: __got0
CHECKGOTPLT: - kind: R_HEX_6_PCREL_X
CHECKGOTPLT: offset: 4
target: __got0
- name: __plt_fn
CHECKGOTPLT: type: stub
CHECKGOTPLT: content: [ 00, 40, 00, 00, 0E, C0, 49, 6A, 1C, C0, 8E, 91,
CHECKGOTPLT: 00, C0, 9C, 52 ]
CHECKGOTPLT: alignment: 2^4
CHECKGOTPLT: section-name: .plt
CHECKGOTPLT: references:
CHECKGOTPLT: - kind: R_HEX_B32_PCREL_X
CHECKGOTPLT: offset: 0
target: __got_fn
CHECKGOTPLT: - kind: R_HEX_6_PCREL_X
CHECKGOTPLT: offset: 4
target: __got_fn
CHECKGOTPLT: addend: 4
- name: __plt_fn1
CHECKGOTPLT: type: stub
CHECKGOTPLT: content: [ 00, 40, 00, 00, 0E, C0, 49, 6A, 1C, C0, 8E, 91,
CHECKGOTPLT: 00, C0, 9C, 52 ]
CHECKGOTPLT: alignment: 2^4
CHECKGOTPLT: section-name: .plt
CHECKGOTPLT: references:
CHECKGOTPLT: - kind: R_HEX_B32_PCREL_X
CHECKGOTPLT: offset: 0
target: __got_fn1
CHECKGOTPLT: - kind: R_HEX_6_PCREL_X
CHECKGOTPLT: offset: 4
target: __got_fn1
CHECKGOTPLT: addend: 4
- name: __plt_fn2
CHECKGOTPLT: type: stub
CHECKGOTPLT: content: [ 00, 40, 00, 00, 0E, C0, 49, 6A, 1C, C0, 8E, 91,
CHECKGOTPLT: 00, C0, 9C, 52 ]
CHECKGOTPLT: alignment: 2^4
CHECKGOTPLT: section-name: .plt
CHECKGOTPLT: references:
CHECKGOTPLT: - kind: R_HEX_B32_PCREL_X
CHECKGOTPLT: offset: 0
target: __got_fn2
CHECKGOTPLT: - kind: R_HEX_6_PCREL_X
CHECKGOTPLT: offset: 4
target: __got_fn2
CHECKGOTPLT: addend: 4

View File

@ -13,13 +13,13 @@ CHECK: kind: R_X86_64_PC32
CHECK: offset: 18
CHECK: target: [[PLTNAME:[-a-zA-Z0-9_]+]]
CHECK: name: [[PLTNAME]]
CHECK: type: stub
CHECK: type: got
CHECK: references:
CHECK: kind: R_X86_64_JUMP_SLOT
CHECK: name: [[PLTNAME]]
CHECK: type: stub
CHECK: shared-library-atoms:
CHECK: name: foo
CHECK: load-name: shared.so-x86-64

View File

@ -30,12 +30,6 @@ PLT: references:
PLT: kind: R_X86_64_PC32
PLT: target: [[PLTNAME]]
// Make sure there's a got entry with a IRELATIVE relocation.
PLT: type: got
PLT: references:
PLT: kind: R_X86_64_IRELATIVE
PLT: target: hey
// Make sure the target of main's relocation is a stub with a PC32 relocation.
// This relocation is to the got atom, but you can't really write that check in
// FileCheck.
@ -44,6 +38,12 @@ PLT: type: stub
PLT: references
PLT: kind: R_X86_64_PC32
// Make sure there's a got entry with a IRELATIVE relocation.
PLT: type: got
PLT: references:
PLT: kind: R_X86_64_IRELATIVE
PLT: target: hey
CHECK: name: hey
CHECK: scope: global
CHECK: type: resolver

View File

@ -4,6 +4,6 @@ RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=i386 %s
RUN: lld -flavor gnu -target hexagon -o %t2 %p/Inputs/rodata-test.hexagon --noinhibit-exec
RUN: llvm-objdump -section-headers %t2 | FileCheck -check-prefix=hexagon %s
i386: .rodata 00000004 0000000000000111 DATA
i386: .rodata 00000004 0000000000000114 DATA
hexagon: .rodata 00000004 0000000000000111 DATA
hexagon: .rodata 00000004 0000000000000114 DATA

View File

@ -18,17 +18,6 @@ CHECK: offset: 25
CHECK: target: [[GOTNAME:[-a-zA-Z0-9_]+]]
CHECK: addend: -4
CHECK: name: [[GOTNAME]]
CHECK: type: got
CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
CHECK: section-choice: custom-required
CHECK: section-name: .got.dyn
CHECK: permissions: rw-
CHECK: references:
CHECK: - kind: R_X86_64_GLOB_DAT
CHECK: offset: 0
CHECK: target: i
- name: .PLT0
CHECK: type: stub
CHECK: content: [ FF, 35, 00, 00, 00, 00, FF, 25, 00, 00, 00, 00,
@ -64,6 +53,17 @@ CHECK: - kind: R_X86_64_PC32
CHECK: offset: 12
target: .PLT0
CHECK: addend: -4
CHECK: name: [[GOTNAME]]
CHECK: type: got
CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
CHECK: section-choice: custom-required
CHECK: section-name: .got.dyn
CHECK: permissions: rw-
CHECK: references:
CHECK: - kind: R_X86_64_GLOB_DAT
CHECK: offset: 0
CHECK: target: i
CHECK:shared-library-atoms: