Turn resolution.s into an exhaustive testcase.

Now that we print a symbol table and all symbol kinds are at least declared,
we can test all combinations that don't produce an error.

This also includes a few fixes to keep the test passing:

* Keep the strong symbol in a weak X strong pair
* Handle common symbols.

The common X common case will be finished in a followup patch.

llvm-svn: 246401
This commit is contained in:
Rafael Espindola 2015-08-30 23:17:30 +00:00
parent a2cdbce661
commit 30e1797b38
5 changed files with 534 additions and 25 deletions

View File

@ -20,8 +20,8 @@ using namespace lld::elf2;
// Returns 1, 0 or -1 if this symbol should take precedence
// over the Other, tie or lose, respectively.
int SymbolBody::compare(SymbolBody *Other) {
std::pair<bool, bool> L(isDefined(), isWeak());
std::pair<bool, bool> R(Other->isDefined(), Other->isWeak());
std::pair<bool, bool> L(isDefined(), !isWeak());
std::pair<bool, bool> R(Other->isDefined(), !Other->isWeak());
// Normalize
if (L > R)
@ -30,7 +30,14 @@ int SymbolBody::compare(SymbolBody *Other) {
if (L != R)
return -1;
if (L.first && !L.second)
if (L.first && L.second) {
// FIXME: In the case where both are common we need to pick the largest
// and remember the alignment restriction.
if (isCommon())
return -1;
if (Other->isCommon())
return 1;
return 0;
}
return 1;
}

View File

@ -53,7 +53,8 @@ public:
return SymbolKind == UndefinedKind || SymbolKind == UndefinedSyntheticKind;
}
bool isDefined() const { return !isUndefined(); }
bool isStrongUndefined() { return !IsWeak && isUndefined(); }
bool isStrongUndefined() const { return !IsWeak && isUndefined(); }
bool isCommon() const { return SymbolKind == DefinedCommonKind; }
// Returns the symbol name.
StringRef getName() const { return Name; }

View File

@ -245,11 +245,9 @@ template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) {
SymbolBody *Body = File->getSymbolBody(SymIndex);
if (!Body)
continue;
// Skip undefined weak for now.
if (isa<Undefined<ELFT>>(Body) && Body->isWeak())
continue;
// Skip unsupported for now.
if (!isa<DefinedRegular<ELFT>>(Body))
error(Twine("Can't relocate symbol ") + Body->getName());
continue;
uintX_t Offset = RI.r_offset;
uint32_t Type = RI.getType(EObj->isMips64EL());
uintX_t P = this->getVA() + C->getOutputSectionOff();

View File

@ -1,13 +1,107 @@
local:
.weak foo
foo:
.weak RegularWeak_with_RegularWeak
.size RegularWeak_with_RegularWeak, 32
RegularWeak_with_RegularWeak:
.weak _start
_start:
.global RegularWeak_with_RegularStrong
.size RegularWeak_with_RegularStrong, 33
RegularWeak_with_RegularStrong:
.weak bar
bar:
.weak RegularStrong_with_RegularWeak
.size RegularStrong_with_RegularWeak, 34
RegularStrong_with_RegularWeak:
.weak abs
abs = 123
.weak RegularWeak_with_UndefWeak
.size RegularWeak_with_UndefWeak, 35
.quad RegularWeak_with_UndefWeak
.size RegularWeak_with_UndefStrong, 36
.quad RegularWeak_with_UndefStrong
.weak RegularStrong_with_UndefWeak
.size RegularStrong_with_UndefWeak, 37
.quad RegularStrong_with_UndefWeak
.size RegularStrong_with_UndefStrong, 38
.quad RegularStrong_with_UndefStrong
.weak RegularWeak_with_CommonWeak
.comm RegularWeak_with_CommonWeak,39,4
.comm RegularWeak_with_CommonStrong,40,4
.weak RegularStrong_with_CommonWeak
.comm RegularStrong_with_CommonWeak,41,4
.comm RegularStrong_with_CommonStrong,42,4
.weak UndefWeak_with_RegularWeak
.size UndefWeak_with_RegularWeak, 43
UndefWeak_with_RegularWeak:
.global UndefWeak_with_RegularStrong
.size UndefWeak_with_RegularStrong, 44
UndefWeak_with_RegularStrong:
.weak UndefStrong_with_RegularWeak
.size UndefStrong_with_RegularWeak, 45
UndefStrong_with_RegularWeak:
.global UndefStrong_with_RegularStrong
.size UndefStrong_with_RegularStrong, 46
UndefStrong_with_RegularStrong:
.weak UndefWeak_with_UndefWeak
.size UndefWeak_with_UndefWeak, 47
.quad UndefWeak_with_UndefWeak
.weak UndefWeak_with_CommonWeak
.comm UndefWeak_with_CommonWeak,48,4
.comm UndefWeak_with_CommonStrong,49,4
.weak UndefStrong_with_CommonWeak
.comm UndefStrong_with_CommonWeak,50,4
.comm UndefStrong_with_CommonStrong,51,4
.weak CommonWeak_with_RegularWeak
.size CommonWeak_with_RegularWeak, 52
CommonWeak_with_RegularWeak:
.global CommonWeak_with_RegularStrong
.size CommonWeak_with_RegularStrong, 53
CommonWeak_with_RegularStrong:
.weak CommonStrong_with_RegularWeak
.size CommonStrong_with_RegularWeak, 54
CommonStrong_with_RegularWeak:
.global CommonStrong_with_RegularStrong
.size CommonStrong_with_RegularStrong, 55
CommonStrong_with_RegularStrong:
.weak CommonWeak_with_UndefWeak
.size CommonWeak_with_UndefWeak, 56
.quad CommonWeak_with_UndefWeak
.size CommonWeak_with_UndefStrong, 57
.quad CommonWeak_with_UndefStrong
.weak CommonStrong_with_UndefWeak
.size CommonStrong_with_UndefWeak, 58
.quad CommonStrong_with_UndefWeak
.size CommonStrong_with_UndefStrong, 59
.quad CommonStrong_with_UndefStrong
.weak CommonWeak_with_CommonWeak
.comm CommonWeak_with_CommonWeak,60,4
.comm CommonWeak_with_CommonStrong,61,4
.weak CommonStrong_with_CommonWeak
.comm CommonStrong_with_CommonWeak,62,4
.comm CommonStrong_with_CommonStrong,63,4

View File

@ -1,21 +1,430 @@
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/Inputs/resolution.s -o %t2
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/resolution.s -o %t2
// RUN: lld -flavor gnu2 %t %t2 -o %t3
// RUN: llvm-readobj -t %t3 | FileCheck %s
// REQUIRES: x86
// This is an exhaustive test for checking which symbol is kept when two
// have the same name. Each symbol has a different size which is used
// to see which one was chosen.
// CHECK: Symbols [
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: (0)
// CHECK-NEXT: Value: 0x0
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local (0x0)
// CHECK-NEXT: Type: None (0x0)
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: Undefined (0x0)
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: _start
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: RegularWeak_with_RegularWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonWeak_with_RegularWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 20
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: UndefWeak_with_RegularWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 43
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: RegularStrong_with_RegularWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 2
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonStrong_with_RegularWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 22
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: UndefStrong_with_RegularWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 45
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: RegularWeak_with_CommonWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 7
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonWeak_with_CommonWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 28
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: UndefWeak_with_CommonWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 48
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: RegularStrong_with_CommonWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 9
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonStrong_with_CommonWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 30
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: UndefStrong_with_CommonWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 50
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: RegularWeak_with_UndefWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 3
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonWeak_with_UndefWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 24
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: UndefWeak_with_UndefWeak
// CHECK-NEXT: Value: 0x0
// CHECK-NEXT: Size: 15
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: Undefined
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: RegularStrong_with_UndefWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 5
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonStrong_with_UndefWeak
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 26
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: RegularWeak_with_RegularStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 33
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonWeak_with_RegularStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 53
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: UndefWeak_with_RegularStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 44
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonStrong_with_RegularStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 55
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: UndefStrong_with_RegularStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 46
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: RegularWeak_with_CommonStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 40
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonWeak_with_CommonStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 61
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: UndefWeak_with_CommonStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 49
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: RegularStrong_with_CommonStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 10
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonStrong_with_CommonStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 63
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: UndefStrong_with_CommonStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 51
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: RegularWeak_with_UndefStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 4
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonWeak_with_UndefStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 25
// CHECK-NEXT: Binding: Weak
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: RegularStrong_with_UndefStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 6
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: CommonStrong_with_UndefStrong
// CHECK-NEXT: Value:
// CHECK-NEXT: Size: 27
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: ]
.globl _start
_start:
nop
local:
.weak foo
foo:
.weak RegularWeak_with_RegularWeak
.size RegularWeak_with_RegularWeak, 0
RegularWeak_with_RegularWeak:
.long bar
.weak RegularWeak_with_RegularStrong
.size RegularWeak_with_RegularStrong, 1
RegularWeak_with_RegularStrong:
.weak zed
.long zed
.global RegularStrong_with_RegularWeak
.size RegularStrong_with_RegularWeak, 2
RegularStrong_with_RegularWeak:
.global abs
abs = 123
.weak RegularWeak_with_UndefWeak
.size RegularWeak_with_UndefWeak, 3
RegularWeak_with_UndefWeak:
.weak RegularWeak_with_UndefStrong
.size RegularWeak_with_UndefStrong, 4
RegularWeak_with_UndefStrong:
.global RegularStrong_with_UndefWeak
.size RegularStrong_with_UndefWeak, 5
RegularStrong_with_UndefWeak:
.global RegularStrong_with_UndefStrong
.size RegularStrong_with_UndefStrong, 6
RegularStrong_with_UndefStrong:
.weak RegularWeak_with_CommonWeak
.size RegularWeak_with_CommonWeak, 7
RegularWeak_with_CommonWeak:
.weak RegularWeak_with_CommonStrong
.size RegularWeak_with_CommonStrong, 8
RegularWeak_with_CommonStrong:
.global RegularStrong_with_CommonWeak
.size RegularStrong_with_CommonWeak, 9
RegularStrong_with_CommonWeak:
.global RegularStrong_with_CommonStrong
.size RegularStrong_with_CommonStrong, 10
RegularStrong_with_CommonStrong:
.weak UndefWeak_with_RegularWeak
.size UndefWeak_with_RegularWeak, 11
.quad UndefWeak_with_RegularWeak
.weak UndefWeak_with_RegularStrong
.size UndefWeak_with_RegularStrong, 12
.quad UndefWeak_with_RegularStrong
.size UndefStrong_with_RegularWeak, 13
.quad UndefStrong_with_RegularWeak
.size UndefStrong_with_RegularStrong, 14
.quad UndefStrong_with_RegularStrong
.weak UndefWeak_with_UndefWeak
.size UndefWeak_with_UndefWeak, 15
.quad UndefWeak_with_UndefWeak
.weak UndefWeak_with_CommonWeak
.size UndefWeak_with_CommonWeak, 16
.quad UndefWeak_with_CommonWeak
.weak UndefWeak_with_CommonStrong
.size UndefWeak_with_CommonStrong, 17
.quad UndefWeak_with_CommonStrong
.size UndefStrong_with_CommonWeak, 18
.quad UndefStrong_with_CommonWeak
.size UndefStrong_with_CommonStrong, 19
.quad UndefStrong_with_CommonStrong
.weak CommonWeak_with_RegularWeak
.comm CommonWeak_with_RegularWeak,20,4
.weak CommonWeak_with_RegularStrong
.comm CommonWeak_with_RegularStrong,21,4
.comm CommonStrong_with_RegularWeak,22,4
.comm CommonStrong_with_RegularStrong,23,4
.weak CommonWeak_with_UndefWeak
.comm CommonWeak_with_UndefWeak,24,4
.weak CommonWeak_with_UndefStrong
.comm CommonWeak_with_UndefStrong,25,4
.comm CommonStrong_with_UndefWeak,26,4
.comm CommonStrong_with_UndefStrong,27,4
.weak CommonWeak_with_CommonWeak
.comm CommonWeak_with_CommonWeak,28,4
.weak CommonWeak_with_CommonStrong
.comm CommonWeak_with_CommonStrong,29,4
.comm CommonStrong_with_CommonWeak,30,4
.comm CommonStrong_with_CommonStrong,31,4