forked from OSchip/llvm-project
[lld][ELF] Handle multiple weak symbols
This handles multiple weak symbols which appear back to back. This fix is needed which otherwise will lead to symbols getting initialized to arbitrary values. There was a constructor/destructor test that really triggered this to be fixed on X86_64. Adds a test. llvm-svn: 190658
This commit is contained in:
parent
1bc22c12cb
commit
2a92c18ba3
|
@ -428,19 +428,18 @@ public:
|
|||
if (previousAtom)
|
||||
createEdge(anonAtom, previousAtom,
|
||||
lld::Reference::kindLayoutBefore);
|
||||
// If this is the last atom, lets not create a followon reference.
|
||||
if (anonAtom && (si + 1) != se) {
|
||||
anonFollowedBy = new (_readerStorage) ELFReference<ELFT>(
|
||||
lld::Reference::kindLayoutAfter);
|
||||
anonAtom->addReference(anonFollowedBy);
|
||||
}
|
||||
}
|
||||
|
||||
ELFDefinedAtom<ELFT> *newAtom = createDefinedAtomAndAssignRelocations(
|
||||
symbolName, *sectionName, &*symbol, section, symbolData);
|
||||
newAtom->setOrdinal(++_ordinal);
|
||||
|
||||
// If this is the last atom, lets not create a followon reference.
|
||||
if (anonAtom && (si + 1) != se) {
|
||||
anonFollowedBy = new (_readerStorage)
|
||||
ELFReference<ELFT>(lld::Reference::kindLayoutAfter);
|
||||
anonAtom->addReference(anonFollowedBy);
|
||||
}
|
||||
|
||||
// If the atom was a weak symbol, lets create a followon reference to
|
||||
// the anonymous atom that we created.
|
||||
if (anonAtom)
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,21 @@
|
|||
.file "weak.s"
|
||||
.text
|
||||
.p2align 4,,15
|
||||
.globl test
|
||||
.type test, @function
|
||||
test:
|
||||
ret
|
||||
.size test, .-test
|
||||
.weak myfn2
|
||||
.data
|
||||
.align 8
|
||||
.type myfn2, @object
|
||||
.size myfn2, 8
|
||||
myfn2:
|
||||
.quad test
|
||||
.weak myfn1
|
||||
.align 8
|
||||
.type myfn1, @object
|
||||
.size myfn1, 8
|
||||
myfn1:
|
||||
.quad test
|
|
@ -0,0 +1,46 @@
|
|||
# Test that we are able to layout multiple weak symbols
|
||||
# properly
|
||||
|
||||
RUN: lld -flavor gnu -target x86_64 %p/Inputs/multiweaksyms.o \
|
||||
RUN: --noinhibit-exec -static -emit-yaml -o %t
|
||||
RUN: FileCheck %s -check-prefix=WEAKSYMS < %t
|
||||
|
||||
WEAKSYMS: - ref-name: [[SYMA:[-a-zA-Z0-9_]+]]
|
||||
WEAKSYMS: type: data
|
||||
WEAKSYMS: references:
|
||||
WEAKSYMS: - kind: layout-after
|
||||
WEAKSYMS: target: [[SYMB:[-a-zA-Z0-9_]+]]
|
||||
WEAKSYMS: - name: myfn2
|
||||
WEAKSYMS: scope: global
|
||||
WEAKSYMS: type: data
|
||||
WEAKSYMS: merge: as-weak
|
||||
WEAKSYMS: references:
|
||||
WEAKSYMS: - kind: layout-after
|
||||
WEAKSYMS: target: [[SYMB]]
|
||||
WEAKSYMS: - ref-name: [[SYMB]]
|
||||
WEAKSYMS: scope: global
|
||||
WEAKSYMS: type: data
|
||||
WEAKSYMS: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
|
||||
WEAKSYMS: references:
|
||||
WEAKSYMS: - kind: R_X86_64_64
|
||||
WEAKSYMS: target: test
|
||||
WEAKSYMS: - kind: layout-before
|
||||
WEAKSYMS: target: [[SYMA]]
|
||||
WEAKSYMS: - kind: layout-after
|
||||
WEAKSYMS: target: [[SYMC:[-a-zA-Z0-9_]+]]
|
||||
WEAKSYMS: - name: myfn1
|
||||
WEAKSYMS: scope: global
|
||||
WEAKSYMS: type: data
|
||||
WEAKSYMS: merge: as-weak
|
||||
WEAKSYMS: references:
|
||||
WEAKSYMS: - kind: layout-after
|
||||
WEAKSYMS: target: [[SYMC]]
|
||||
WEAKSYMS: - ref-name: [[SYMC]]
|
||||
WEAKSYMS: scope: global
|
||||
WEAKSYMS: type: data
|
||||
WEAKSYMS: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
|
||||
WEAKSYMS: references:
|
||||
WEAKSYMS: - kind: R_X86_64_64
|
||||
WEAKSYMS: target: test
|
||||
WEAKSYMS: - kind: layout-before
|
||||
WEAKSYMS: target: [[SYMB]]
|
Loading…
Reference in New Issue