Skip to content

Commit

Permalink
[ELF][test] Improve llvm-objdump -t tests
Browse files Browse the repository at this point in the history
In many cases, llvm-nm or llvm-readelf is more suitable.
  • Loading branch information
MaskRay committed Mar 4, 2020
1 parent 38e5322 commit 1044ee8
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 160 deletions.
6 changes: 3 additions & 3 deletions lld/test/ELF/end.s
Expand Up @@ -23,9 +23,9 @@
// DEFAULT-NEXT: Value: 0x202161
// DEFAULT: ]

// RUN: ld.lld -r %t.o -o %t2
// RUN: llvm-objdump -t %t2 | FileCheck %s --check-prefix=RELOCATABLE
// RELOCATABLE: 0000000000000000 *UND* 00000000 _end
// RUN: ld.lld -r %t.o -o %t
// RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=RELOCATABLE
// RELOCATABLE: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _end

.global _start,_end
.text
Expand Down
9 changes: 6 additions & 3 deletions lld/test/ELF/gnu-ifunc-empty.s
Expand Up @@ -5,10 +5,13 @@

// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: ld.lld -static %t.o -o %t.exe
// RUN: llvm-objdump -syms %t.exe | FileCheck %s
// RUN: llvm-readelf -S -s %t.exe | FileCheck %s

// CHECK: 0000000000200000 .text 00000000 .hidden __rela_iplt_end
// CHECK: 0000000000200000 .text 00000000 .hidden __rela_iplt_start
// CHECK: Name Type Address Off
// CHECK: .text PROGBITS 0000000000201120 000120
// CHECK: Value Size Type Bind Vis Ndx Name
// CHECK: 0000000000200000 0 NOTYPE LOCAL HIDDEN 1 __rela_iplt_end
// CHECK: 0000000000200000 0 NOTYPE LOCAL HIDDEN 1 __rela_iplt_start

.globl _start
_start:
Expand Down
16 changes: 8 additions & 8 deletions lld/test/ELF/linkerscript/alignof.test
@@ -1,11 +1,11 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/alignof.s -o %t
# RUN: ld.lld -o %t1 --script %s %t
# RUN: llvm-objdump -t %t1 | FileCheck %s
# CHECK: SYMBOL TABLE:
# CHECK: 0000000000000008 *ABS* 00000000 _aaa
# CHECK-NEXT: 0000000000000010 *ABS* 00000000 _bbb
# CHECK-NEXT: 0000000000000020 *ABS* 00000000 _ccc
# RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/alignof.s -o %t.o
# RUN: ld.lld -o %t --script %s %t.o
# RUN: llvm-readelf -s %t | FileCheck %s
# CHECK: Value Size Type Bind Vis Ndx Name
# CHECK: 0000000000000008 0 NOTYPE GLOBAL DEFAULT ABS _aaa
# CHECK-NEXT: 0000000000000010 0 NOTYPE GLOBAL DEFAULT ABS _bbb
# CHECK-NEXT: 0000000000000020 0 NOTYPE GLOBAL DEFAULT ABS _ccc

SECTIONS {
.aaa : { *(.aaa) }
Expand All @@ -19,6 +19,6 @@ SECTIONS {
## Check that we error out if trying to get alignment of
## section that does not exist.
# RUN: echo "SECTIONS { _aaa = ALIGNOF(.foo); }" > %t.script
# RUN: not ld.lld -o /dev/null --script %t.script %t 2>&1 \
# RUN: not ld.lld -o /dev/null --script %t.script %t.o 2>&1 \
# RUN: | FileCheck -check-prefix=ERR %s
# ERR: {{.*}}.script:1: undefined section .foo
16 changes: 8 additions & 8 deletions lld/test/ELF/linkerscript/early-assign-symbol.s
Expand Up @@ -6,25 +6,25 @@

# RUN: echo "SECTIONS { aaa = foo | 1; .text : { *(.text*) } }" > %t3.script
# RUN: ld.lld -o %t --script %t3.script %t.o
# RUN: llvm-objdump -t %t | FileCheck --check-prefix=VAL1 %s
# RUN: llvm-nm -p %t | FileCheck --check-prefix=VAL1 %s

# VAL1: 0000000000000000 .text 00000000 foo
# VAL1: 0000000000000001 .text 00000000 aaa
# VAL1: 0000000000000000 T foo
# VAL1: 0000000000000001 T aaa

# RUN: echo "SECTIONS { aaa = ABSOLUTE(foo - 1) + 1; .text : { *(.text*) } }" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-objdump -t %t | FileCheck --check-prefix=VAL %s
# RUN: llvm-nm -p %t | FileCheck --check-prefix=VAL %s

# RUN: echo "SECTIONS { aaa = 1 + ABSOLUTE(foo - 1); .text : { *(.text*) } }" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-objdump -t %t | FileCheck --check-prefix=VAL %s
# RUN: llvm-nm -p %t | FileCheck --check-prefix=VAL %s

# RUN: echo "SECTIONS { aaa = ABSOLUTE(foo); .text : { *(.text*) } }" > %t4.script
# RUN: ld.lld -o %t --script %t4.script %t.o
# RUN: llvm-objdump -t %t | FileCheck --check-prefix=VAL %s
# RUN: llvm-nm -p %t | FileCheck --check-prefix=VAL %s

# VAL: 0000000000000000 .text 00000000 foo
# VAL: 0000000000000000 *ABS* 00000000 aaa
# VAL: 0000000000000000 T foo
# VAL: 0000000000000000 A aaa

.section .text
.globl foo
Expand Down
17 changes: 9 additions & 8 deletions lld/test/ELF/linkerscript/expr-sections.test
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o
# RUN: ld.lld -o %t.so --script %s %t.o -shared
# RUN: llvm-objdump -t -h %t.so | FileCheck %s
# RUN: llvm-readelf -S -s %t.so | FileCheck %s

SECTIONS {
. = . + 4;
Expand All @@ -13,11 +13,12 @@ SECTIONS {
}
};

# CHECK: 5 .text 00000000 000000000000014c
# CHECK: [ 5] .text PROGBITS 000000000000014c

# CHECK: 000000000000014d .text 00000000 foo1
# CHECK: 000000000000014d .text 00000000 bar1
# CHECK: 0000000000000000 .text 00000000 foo2
# CHECK: 0000000000000000 .text 00000000 bar2
# CHECK: 000000000000014d .text 00000000 foo3
# CHECK: 000000000000014d .text 00000000 bar3
# CHECK: Value Size Type Bind Vis Ndx Name
# CHECK: 000000000000014d 0 NOTYPE GLOBAL DEFAULT 5 foo1
# CHECK: 000000000000014d 0 NOTYPE GLOBAL DEFAULT 5 bar1
# CHECK: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 5 foo2
# CHECK: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 5 bar2
# CHECK: 000000000000014d 0 NOTYPE GLOBAL DEFAULT 5 foo3
# CHECK: 000000000000014d 0 NOTYPE GLOBAL DEFAULT 5 bar3
11 changes: 3 additions & 8 deletions lld/test/ELF/linkerscript/non-absolute2.test
@@ -1,17 +1,12 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux /dev/null -o %t1.o
# RUN: ld.lld -shared %t1.o --script %s -o %t
# RUN: llvm-objdump -section-headers -t %t | FileCheck %s
# RUN: llvm-readelf -s %t | FileCheck %s

SECTIONS {
A = . + 0x1;
. += 0x1000;
}

# CHECK: Sections:
# CHECK-NEXT: Idx Name Size VMA
# CHECK-NEXT: 0 00000000 0000000000000000
# CHECK-NEXT: 1 .dynsym 00000030 0000000000001000
# CHECK: 5 .text 00000000 000000000000106c

# CHECK: 0000000000000001 .dynsym 00000000 A
# CHECK: Value Size Type Bind Vis Ndx Name
# CHECK: 0000000000000001 0 NOTYPE GLOBAL DEFAULT 1 A
96 changes: 48 additions & 48 deletions lld/test/ELF/linkerscript/operators.test
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t
# RUN: ld.lld %t --script %s -o %t2
# RUN: llvm-objdump -t %t2 | FileCheck %s
# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o %t.o
# RUN: ld.lld %t.o -T %s -o %t
# RUN: llvm-nm -p %t | FileCheck %s

SECTIONS {
_start = .;
Expand Down Expand Up @@ -48,83 +48,83 @@ SECTIONS {
logicalor4 = 1 || 1;
}

# CHECK: 00000000000006 *ABS* 00000000 plus
# CHECK: 00000000000004 *ABS* 00000000 minus
# CHECK: 00000000000003 *ABS* 00000000 div
# CHECK: 00000000000006 *ABS* 00000000 mod
# CHECK: 00000000000007 *ABS* 00000000 mul
# CHECK: 00000000000005 *ABS* 00000000 nospace
# CHECK: 00000000000015 *ABS* 00000000 braces
# CHECK: 000000000000aa *ABS* 00000000 and
# CHECK: 00000000000001 *ABS* 00000000 ternary1
# CHECK: 00000000000002 *ABS* 00000000 ternary2
# CHECK: 00000000000002 *ABS* 00000000 less
# CHECK: 00000000000001 *ABS* 00000000 lesseq
# CHECK: 00000000000002 *ABS* 00000000 greater
# CHECK: 00000000000001 *ABS* 00000000 greatereq
# CHECK: 00000000000001 *ABS* 00000000 eq
# CHECK: 00000000000002 *ABS* 00000000 neq
# CHECK: 00000000000003 *ABS* 00000000 plusassign
# CHECK: 00000000000002 *ABS* 00000000 unary
# CHECK: 00000000000020 *ABS* 00000000 lshift
# CHECK: 0000000000001f *ABS* 00000000 rshift
# CHECK: 00000000000009 *ABS* 00000000 precedence1
# CHECK: 00000000000009 *ABS* 00000000 precedence2
# CHECK: 00000000001000 *ABS* 00000000 maxpagesize
# CHECK: 00000000001000 *ABS* 00000000 commonpagesize
# CHECK: 0000000000ffff *ABS* 00000000 datasegmentalign
# CHECK: 0000000000fff0 *ABS* 00000000 datasegmentalign2
# CHECK: 0000000000ffe0 .text 00000000 minus_rel
# CHECK: 0000000000fff0 *ABS* 00000000 minus_abs
# CHECK: 00000000000016 *ABS* 00000000 max
# CHECK: 0000000000000b *ABS* 00000000 min
# CHECK: 00000000000000 *ABS* 00000000 logicaland1
# CHECK: 00000000000000 *ABS* 00000000 logicaland2
# CHECK: 00000000000000 *ABS* 00000000 logicaland3
# CHECK: 00000000000001 *ABS* 00000000 logicaland4
# CHECK: 00000000000000 *ABS* 00000000 logicalor1
# CHECK: 00000000000001 *ABS* 00000000 logicalor2
# CHECK: 00000000000001 *ABS* 00000000 logicalor3
# CHECK: 00000000000001 *ABS* 00000000 logicalor4
# CHECK: 00000000000006 A plus
# CHECK-NEXT: 00000000000004 A minus
# CHECK-NEXT: 00000000000003 A div
# CHECK-NEXT: 00000000000006 A mod
# CHECK-NEXT: 00000000000007 A mul
# CHECK-NEXT: 00000000000005 A nospace
# CHECK-NEXT: 00000000000015 A braces
# CHECK-NEXT: 000000000000aa A and
# CHECK-NEXT: 00000000000001 A ternary1
# CHECK-NEXT: 00000000000002 A ternary2
# CHECK-NEXT: 00000000000002 A less
# CHECK-NEXT: 00000000000001 A lesseq
# CHECK-NEXT: 00000000000002 A greater
# CHECK-NEXT: 00000000000001 A greatereq
# CHECK-NEXT: 00000000000001 A eq
# CHECK-NEXT: 00000000000002 A neq
# CHECK-NEXT: 00000000000003 A plusassign
# CHECK-NEXT: 00000000000002 A unary
# CHECK-NEXT: 00000000000020 A lshift
# CHECK-NEXT: 0000000000001f A rshift
# CHECK-NEXT: 00000000000009 A precedence1
# CHECK-NEXT: 00000000000009 A precedence2
# CHECK-NEXT: 00000000001000 A maxpagesize
# CHECK-NEXT: 00000000001000 A commonpagesize
# CHECK-NEXT: 0000000000ffff A datasegmentalign
# CHECK-NEXT: 0000000000fff0 A datasegmentalign2
# CHECK-NEXT: 0000000000ffe0 T minus_rel
# CHECK-NEXT: 0000000000fff0 A minus_abs
# CHECK-NEXT: 00000000000016 A max
# CHECK-NEXT: 0000000000000b A min
# CHECK-NEXT: 00000000000000 A logicaland1
# CHECK-NEXT: 00000000000000 A logicaland2
# CHECK-NEXT: 00000000000000 A logicaland3
# CHECK-NEXT: 00000000000001 A logicaland4
# CHECK-NEXT: 00000000000000 A logicalor1
# CHECK-NEXT: 00000000000001 A logicalor2
# CHECK-NEXT: 00000000000001 A logicalor3
# CHECK-NEXT: 00000000000001 A logicalor4

## Mailformed number error.
# RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script
# RUN: not ld.lld %t --script %t.script -o /dev/null 2>&1 | \
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=NUMERR %s
# NUMERR: malformed number: 0x12Q41

## Missing closing bracket.
# RUN: echo "SECTIONS { . = (1; }" > %t.script
# RUN: not ld.lld %t --script %t.script -o /dev/null 2>&1 | \
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=BRACKETERR %s
# BRACKETERR: ) expected, but got ;

## Missing opening bracket.
# RUN: echo "SECTIONS { . = 1); }" > %t.script
# RUN: not ld.lld %t --script %t.script -o /dev/null 2>&1 | \
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=BRACKETERR2 %s
# BRACKETERR2: ; expected, but got )

## Empty expression.
# RUN: echo "SECTIONS { . = ; }" > %t.script
# RUN: not ld.lld %t --script %t.script -o /dev/null 2>&1 | \
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=ERREXPR %s
# ERREXPR: malformed number: ;

## Div by zero error.
# RUN: echo "SECTIONS { . = 1 / 0; }" > %t.script
# RUN: not ld.lld %t --script %t.script -o /dev/null 2>&1 | \
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=DIVZERO %s
# DIVZERO: {{.*}}.script:1: division by zero

## Mod by zero error.
# RUN: echo "SECTIONS { . = 1 % 0; }" > %t.script
# RUN: not ld.lld %t --script %t.script -o /dev/null 2>&1 | \
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=MODZERO %s
# MODZERO: {{.*}}.script:1: modulo by zero

## Broken ternary operator expression.
# RUN: echo "SECTIONS { . = 1 ? 2; }" > %t.script
# RUN: not ld.lld %t --script %t.script -o /dev/null 2>&1 | \
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | \
# RUN: FileCheck --check-prefix=TERNERR %s
# TERNERR: : expected, but got ;
4 changes: 2 additions & 2 deletions lld/test/ELF/linkerscript/page-size.s
Expand Up @@ -46,9 +46,9 @@

# RUN: echo "SECTIONS { symbol = CONSTANT(MAXPAGESIZE); }" > %t.script
# RUN: ld.lld -z max-page-size=0x4000 -o %t1 --script %t.script %t
# RUN: llvm-objdump -t %t1 | FileCheck -check-prefix CHECK-SCRIPT %s
# RUN: llvm-readelf -s %t1 | FileCheck -check-prefix CHECK-SCRIPT %s

# CHECK-SCRIPT: 0000000000004000 *ABS* 00000000 symbol
# CHECK-SCRIPT: 0000000000004000 0 NOTYPE GLOBAL DEFAULT ABS symbol

# RUN: not ld.lld -z max-page-size=0x1001 -o /dev/null --script %t.script %t 2>&1 \
# RUN: | FileCheck -check-prefix=ERR1 %s
Expand Down
4 changes: 2 additions & 2 deletions lld/test/ELF/linkerscript/provide-shared.s
Expand Up @@ -4,9 +4,9 @@
# RUN: ld.lld %t2.o -o %t2.so -shared
# RUN: echo "SECTIONS { . = . + SIZEOF_HEADERS; PROVIDE(foo = 42);}" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o %t2.so
# RUN: llvm-objdump -t %t | FileCheck %s
# RUN: llvm-readelf -s %t | FileCheck %s

# CHECK: 000000000000002a *ABS* 00000000 foo
# CHECK: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS foo

.global _start
_start:
Expand Down
38 changes: 14 additions & 24 deletions lld/test/ELF/linkerscript/sizeof.s
@@ -1,5 +1,5 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o

# RUN: echo "SECTIONS { \
# RUN: .aaa : { *(.aaa) } \
Expand All @@ -8,32 +8,22 @@
# RUN: _aaa = SIZEOF(.aaa); \
# RUN: _bbb = SIZEOF(.bbb); \
# RUN: _ccc = SIZEOF(.ccc); \
# RUN: _ddd = SIZEOF(.not_exist); \
# RUN: }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -t -section-headers %t1 | FileCheck %s
# CHECK: Sections:
# CHECK-NEXT: Idx Name Size
# CHECK-NEXT: 0 00000000
# CHECK-NEXT: 1 .aaa 00000008
# CHECK-NEXT: 2 .bbb 00000010
# CHECK-NEXT: 3 .ccc 00000018
# CHECK: SYMBOL TABLE:
# CHECK-NEXT: .text 00000000 _start
# CHECK-NEXT: 0000000000000008 *ABS* 00000000 _aaa
# CHECK-NEXT: 0000000000000010 *ABS* 00000000 _bbb
# CHECK-NEXT: 0000000000000018 *ABS* 00000000 _ccc
# RUN: ld.lld -T %t.script %t.o -o %t
# RUN: llvm-readelf -S -s %t | FileCheck %s

## SIZEOF(.nonexistent_section) should return 0.
# RUN: echo "SECTIONS { \
# RUN: .aaa : { *(.aaa) } \
# RUN: .bbb : { *(.bbb) } \
# RUN: .ccc : { *(.ccc) } \
# RUN: _aaa = SIZEOF(.foo); \
# RUN: }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -t -section-headers %t1 | FileCheck -check-prefix=CHECK2 %s
# CHECK: Name Type Address Off Size
# CHECK: .aaa PROGBITS 0000000000000000 001000 000008
# CHECK-NEXT: .bbb PROGBITS 0000000000000008 001008 000010
# CHECK-NEXT: .ccc PROGBITS 0000000000000018 001018 000018

# CHECK2: 0000000000000000 *ABS* 00000000 _aaa
# CHECK: Value Size Type Bind Vis Ndx Name
# CHECK: 0000000000000008 0 NOTYPE GLOBAL DEFAULT ABS _aaa
# CHECK-NEXT: 0000000000000010 0 NOTYPE GLOBAL DEFAULT ABS _bbb
# CHECK-NEXT: 0000000000000018 0 NOTYPE GLOBAL DEFAULT ABS _ccc
## SIZEOF(.not_exist) has a value of 0.
# CHECK-NEXT: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS _ddd

.global _start
_start:
Expand Down
12 changes: 6 additions & 6 deletions lld/test/ELF/linkerscript/sizeofheaders.s
@@ -1,16 +1,16 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
# RUN: echo " SECTIONS { \
# RUN: . = SIZEOF_HEADERS; \
# RUN: _size = SIZEOF_HEADERS; \
# RUN: .text : {*(.text*)} \
# RUN: }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -t %t1 | FileCheck %s
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-readelf -s %t | FileCheck %s

#CHECK: SYMBOL TABLE:
#CHECK-NEXT: 00000000000000e8 .text 00000000 _start
#CHECK-NEXT: 00000000000000e8 *ABS* 00000000 _size
# CHECK: Value Size Type Bind Vis Ndx Name
# CHECK: 00000000000000e8 0 NOTYPE GLOBAL DEFAULT 1 _start
# CHECK-NEXT: 00000000000000e8 0 NOTYPE GLOBAL DEFAULT ABS _size

.global _start
_start:
Expand Down

0 comments on commit 1044ee8

Please sign in to comment.