diff options
Diffstat (limited to 'test')
806 files changed, 41845 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 000000000000..e29f5f4c5a90 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,47 @@ +set(LLVM_SOURCE_DIR "${LLVM_MAIN_SRC_DIR}") +set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}") +set(LLVM_BUILD_MODE "%(build_mode)s") +set(LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}/%(build_config)s") +set(LLVM_LIBS_DIR "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/%(build_config)s") +set(CLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..") +set(CLANG_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/..") +if(BUILD_SHARED_LIBS) + set(ENABLE_SHARED 1) +else() + set(ENABLE_SHARED 0) +endif(BUILD_SHARED_LIBS) + +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg) +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg + ) + +set(LLD_TEST_DEPS + FileCheck not llvm-nm + lld llvm-config llvm-objdump llvm-readobj yaml2obj obj2yaml + linker-script-test macho-dump llvm-mc llvm-nm + ) +if (LLVM_INCLUDE_TESTS) + set(LLD_TEST_DEPS ${LLD_TEST_DEPS} LLDUnitTests) +endif() + +set(LLD_TEST_PARAMS + lld_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg + ) + +add_lit_testsuite(check-lld "Running lld test suite" + ${CMAKE_CURRENT_BINARY_DIR} + PARAMS lld_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg + lld_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg + DEPENDS ${LLD_TEST_DEPS} + ) + +set_target_properties(check-lld PROPERTIES FOLDER "lld tests") + +# Add a legacy target spelling: lld-test +add_custom_target(lld-test) +add_dependencies(lld-test check-lld) +set_target_properties(lld-test PROPERTIES FOLDER "lld tests") diff --git a/test/Driver/Inputs/libtest.a b/test/Driver/Inputs/libtest.a new file mode 100644 index 000000000000..8b277f0dd5dc --- /dev/null +++ b/test/Driver/Inputs/libtest.a @@ -0,0 +1 @@ +!<arch> diff --git a/test/Driver/Inputs/usr/lib/i386/libtest.a b/test/Driver/Inputs/usr/lib/i386/libtest.a new file mode 100644 index 000000000000..8b277f0dd5dc --- /dev/null +++ b/test/Driver/Inputs/usr/lib/i386/libtest.a @@ -0,0 +1 @@ +!<arch> diff --git a/test/Driver/Inputs/usr/lib/libtest.a b/test/Driver/Inputs/usr/lib/libtest.a new file mode 100644 index 000000000000..8b277f0dd5dc --- /dev/null +++ b/test/Driver/Inputs/usr/lib/libtest.a @@ -0,0 +1 @@ +!<arch> diff --git a/test/Driver/def-lib-search.test b/test/Driver/def-lib-search.test new file mode 100644 index 000000000000..818cbfe6ad61 --- /dev/null +++ b/test/Driver/def-lib-search.test @@ -0,0 +1,8 @@ +# Check that search paths explicitly provided by the -L option +# are used in search before default paths. + +RUN: not lld -flavor gnu -target x86_64 -t -ltest \ +RUN: --sysroot=%p/Inputs -L%p/Inputs 2> %t +RUN: FileCheck %s < %t + +CHECK: {{[^ ]+}}{{[\\/]}}Inputs{{[\\/]}}libtest.a diff --git a/test/Driver/flavor-option.test b/test/Driver/flavor-option.test new file mode 100644 index 000000000000..2ca3b410cbe2 --- /dev/null +++ b/test/Driver/flavor-option.test @@ -0,0 +1,8 @@ +# a) the -flavor option is position independent and does not need to be the 1st +# argument in the command line (bug 20975); +# b) UniversalDriver correctly removes -flavor along with its value and the +# underlying linker does not get a corrupted command line (bug 20977). +RUN: lld --help -flavor gnu | FileCheck %s + +CHECK: --noinhibit-exec +CHECK: --output-filetype diff --git a/test/Driver/lib-search.test b/test/Driver/lib-search.test new file mode 100644 index 000000000000..9d3666f63c36 --- /dev/null +++ b/test/Driver/lib-search.test @@ -0,0 +1,24 @@ +RUN: not lld -flavor gnu -t -ltest -L%p/Inputs 2> %t.err +RUN: FileCheck %s < %t.err + +RUN: not lld -flavor gnu -target x86_64--netbsd -t -ltest \ +RUN: --sysroot=%p/Inputs 2> %t2 +RUN: FileCheck -check-prefix=NETBSD-AMD64 %s < %t2 +RUN: not lld -flavor gnu -target x86_64--netbsd -nostdlib -t -ltest \ +RUN: --sysroot=%p/Inputs 2> %t3 +RUN: FileCheck -check-prefix=NETBSD-AMD64-NS %s < %t3 +RUN: not lld -flavor gnu -target i386--netbsd -t -ltest \ +RUN: --sysroot=%p/Inputs 2> %t4 +RUN: FileCheck -check-prefix=NETBSD-I386 %s < %t4 +RUN: not lld -flavor gnu -target x86_64--netbsd -m elf_i386 -t -ltest \ +RUN: --sysroot=%p/Inputs 2> %t5 +RUN: FileCheck -check-prefix=NETBSD-AMD64_32 %s < %t5 + +# run linker with -t mode to dump full paths to input files + +CHECK: {{[^ ]+[\\/]}}Inputs{{[\\/]}}libtest.a + +NETBSD-AMD64: {{[^ ]+}}{{[\\/]}}Inputs{{[\\/]}}usr{{[\\/]}}lib{{[\\/]}}libtest.a +NETBSD-AMD64-NS-NOT: {{[^ ]+}}{{[\\/]}}Inputs{{[\\/]}}usr{{[\\/]}}lib{{[\\/]}}libtest.a +NETBSD-I386: {{[^ ]+}}{{[\\/]}}Inputs{{[\\/]}}usr{{[\\/]}}lib{{[\\/]}}libtest.a +NETBSD-AMD64_32: {{[^ ]+}}{{[\\/]}}Inputs{{[\\/]}}usr{{[\\/]}}lib{{[\\/]}}i386{{[\\/]}}libtest.a diff --git a/test/Driver/so-whole-archive.test b/test/Driver/so-whole-archive.test new file mode 100644 index 000000000000..0732c35a7a92 --- /dev/null +++ b/test/Driver/so-whole-archive.test @@ -0,0 +1,63 @@ +# Check that LLD does not show any error if the --whole-archive +# is around non-archive. + +# RUN: yaml2obj -format=elf -docnum=1 %s > %t-so.o +# RUN: yaml2obj -format=elf -docnum=2 %s > %t-exe.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: lld -flavor gnu -target mipsel -o %t.exe %t-exe.o --whole-archive %t.so + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x04 +Symbols: + Global: + - Name: foo + Type: STT_FUNC + Section: .text + Size: 0x04 + +# exe.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x04 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: foo + Type: R_MIPS_26 + +Symbols: + Global: + - Name: __start + Type: STT_FUNC + Section: .text + Size: 0x04 + - Name: foo +... diff --git a/test/Driver/trivial-driver.test b/test/Driver/trivial-driver.test new file mode 100644 index 000000000000..196d6cfa9d4d --- /dev/null +++ b/test/Driver/trivial-driver.test @@ -0,0 +1,5 @@ +# This test, tests the Gnu lld option --help +RUN: lld -flavor gnu --help | FileCheck %s + +CHECK: --noinhibit-exec +CHECK: --output-filetype diff --git a/test/Driver/undef-basic.objtxt b/test/Driver/undef-basic.objtxt new file mode 100644 index 000000000000..f942d5c8e904 --- /dev/null +++ b/test/Driver/undef-basic.objtxt @@ -0,0 +1,22 @@ +# RUN: lld -flavor gnu -u undefinedsymbol -e entrysymbol %s \ +# RUN: --output-filetype=yaml --noinhibit-exec | FileCheck %s + +# +# Test that we are able to add undefined atoms from the command line +# + +--- +absolute-atoms: + - name: putchar + value: 0xFFFF0040 + + - name: reset + value: 0xFFFF0080 + +... + + +# CHECK: undefined-atoms: +# CHECK: - name: entrysymbol +# CHECK: - name: undefinedsymbol +# CHECK: can-be-null: at-buildtime diff --git a/test/LinkerScript/expr-precedence.test b/test/LinkerScript/expr-precedence.test new file mode 100644 index 000000000000..5170e34ba4b3 --- /dev/null +++ b/test/LinkerScript/expr-precedence.test @@ -0,0 +1,34 @@ +/* + RUN: linker-script-test %s | FileCheck %s +*/ +SECTIONS { + . = foo >= bar + 1 ? bar : 1- - - -1; +} + +/* +CHECK: kw_sections: SECTIONS +CHECK: l_brace: { +CHECK: identifier: . +CHECK: equal: = +CHECK: identifier: foo +CHECK: greaterequal: >= +CHECK: identifier: bar +CHECK: plus: + +CHECK: number: 1 +CHECK: question: ? +CHECK: identifier: bar +CHECK: colon: : +CHECK: number: 1 +CHECK: minus: - +CHECK: minus: - +CHECK: minus: - +CHECK: minus: - +CHECK: number: 1 +CHECK: semicolon: ; +CHECK: r_brace: } +CHECK: eof: +CHECK: SECTIONS +CHECK: { +CHECK: . = (foo >= (bar + 1)) ? bar : (1 - (-(-(-1)))) +CHECK: } +*/ diff --git a/test/LinkerScript/extern-bad-symbol.test b/test/LinkerScript/extern-bad-symbol.test new file mode 100644 index 000000000000..279a7cc20567 --- /dev/null +++ b/test/LinkerScript/extern-bad-symbol.test @@ -0,0 +1,22 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ + + +EXTERN(a b 3) +/* +CHECK-ERR: [[@LINE-2]]:12: error: expected symbol in EXTERN. +CHECK-ERR-NEXT: {{^EXTERN\(a b 3\)}} +CHECK-ERR-NEXT: {{^ \^}} +*/ + +/* +CHECK: kw_extern: EXTERN +CHECK: l_paren: ( +CHECK: identifier: a +CHECK: identifier: b +CHECK: number: 3 +CHECK: r_paren: ) +CHECK: eof: +*/ diff --git a/test/LinkerScript/extern-empty.test b/test/LinkerScript/extern-empty.test new file mode 100644 index 000000000000..a5e1ece084d9 --- /dev/null +++ b/test/LinkerScript/extern-empty.test @@ -0,0 +1,19 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ + + +EXTERN() +/* +CHECK-ERR: [[@LINE-2]]:8: error: expected one or more symbols in EXTERN. +CHECK-ERR-NEXT: {{^EXTERN()}} +CHECK-ERR-NEXT: {{^ \^}} +*/ + +/* +CHECK: kw_extern: EXTERN +CHECK: l_paren: ( +CHECK: r_paren: ) +CHECK: eof: +*/ diff --git a/test/LinkerScript/extern-valid.test b/test/LinkerScript/extern-valid.test new file mode 100644 index 000000000000..764b4668a34f --- /dev/null +++ b/test/LinkerScript/extern-valid.test @@ -0,0 +1,29 @@ +/* + RUN: linker-script-test %s | FileCheck %s +*/ + +EXTERN(a) +EXTERN(a b) +EXTERN(_foo _bar _baz) + +/* +CHECK: kw_extern: EXTERN +CHECK: l_paren: ( +CHECK: identifier: a +CHECK: r_paren: ) +CHECK: kw_extern: EXTERN +CHECK: l_paren: ( +CHECK: identifier: a +CHECK: identifier: b +CHECK: r_paren: ) +CHECK: kw_extern: EXTERN +CHECK: l_paren: ( +CHECK: identifier: _foo +CHECK: identifier: _bar +CHECK: identifier: _baz +CHECK: r_paren: ) +CHECK: eof: +CHECK: EXTERN(a) +CHECK: EXTERN(a b) +CHECK: EXTERN(_foo _bar _baz) +*/ diff --git a/test/LinkerScript/incomplete-ternary.test b/test/LinkerScript/incomplete-ternary.test new file mode 100644 index 000000000000..fae30537d2de --- /dev/null +++ b/test/LinkerScript/incomplete-ternary.test @@ -0,0 +1,25 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ +SECTIONS { + . = foo ? bar; +/* +CHECK-ERR: [[@LINE-2]]:18: error: expected : +CHECK-ERR-NEXT: {{^ \. = foo \? bar;}} +CHECK-ERR-NEXT: {{^ \^}} +*/ +} + +/* +CHECK: kw_sections: SECTIONS +CHECK: l_brace: { +CHECK: identifier: . +CHECK: equal: = +CHECK: identifier: foo +CHECK: question: ? +CHECK: identifier: bar +CHECK: semicolon: ; +CHECK: r_brace: } +CHECK: eof: +*/ diff --git a/test/LinkerScript/libname-err-1.test b/test/LinkerScript/libname-err-1.test new file mode 100644 index 000000000000..451a469336bd --- /dev/null +++ b/test/LinkerScript/libname-err-1.test @@ -0,0 +1,11 @@ +/* RUN: linker-script-test %s 2>&1 | FileCheck %s +*/ + +OUTPUT_ARCH(i386:x86_64) +OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") +GROUP( -l### ) +ENTRY(init) + +/* +CHECK: libname-err-1.test:6:10: error: expected ) +*/ diff --git a/test/LinkerScript/libname-err-2.test b/test/LinkerScript/libname-err-2.test new file mode 100644 index 000000000000..f1d96d718151 --- /dev/null +++ b/test/LinkerScript/libname-err-2.test @@ -0,0 +1,11 @@ +/* RUN: linker-script-test %s 2>&1 | FileCheck %s +*/ + +OUTPUT_ARCH(i386:x86_64) +OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") +GROUP( -l ) +ENTRY(init) + +/* +CHECK: libname-err-2.test:6:10: error: expected ) +*/ diff --git a/test/LinkerScript/linker-script-outputformat.test b/test/LinkerScript/linker-script-outputformat.test new file mode 100644 index 000000000000..b47bb38ad8d8 --- /dev/null +++ b/test/LinkerScript/linker-script-outputformat.test @@ -0,0 +1,12 @@ +/* RUN: linker-script-test %s | FileCheck %s +*/ + +OUTPUT_FORMAT(elf64-x86-64) + +/* +CHECK: kw_output_format: OUTPUT_FORMAT +CHECK: l_paren: ( +CHECK: identifier: elf64-x86-64 +CHECK: r_paren: ) +CHECK: OUTPUT_FORMAT("elf64-x86-64") +*/ diff --git a/test/LinkerScript/linker-script.test b/test/LinkerScript/linker-script.test new file mode 100644 index 000000000000..421493666e84 --- /dev/null +++ b/test/LinkerScript/linker-script.test @@ -0,0 +1,46 @@ +/* RUN: linker-script-test %s | FileCheck %s +*/ + +OUTPUT_ARCH(i386:x86_64) +OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") +OUTPUT("/out/foo") +GROUP ( /lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libc_nonshared.a AS_NEEDED ( /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ) -lm -l:libgcc.a ) +ENTRY(init) + +/* +CHECK: kw_output_arch: OUTPUT_ARCH +CHECK: l_paren: ( +CHECK: identifier: i386:x86_64 +CHECK: r_paren: ) +CHECK: kw_output_format: OUTPUT_FORMAT +CHECK: l_paren: ( +CHECK: identifier: elf64-x86-64 +CHECK: comma: , +CHECK: identifier: elf64-x86-64 +CHECK: comma: , +CHECK: identifier: elf64-x86-64 +CHECK: r_paren: ) +CHECK: kw_output: OUTPUT +CHECK: l_paren: ( +CHECK: identifier: /out/foo +CHECK: r_paren: ) +CHECK: kw_group: GROUP +CHECK: l_paren: ( +CHECK: identifier: /lib/x86_64-linux-gnu/libc.so.6 +CHECK: identifier: /usr/lib/x86_64-linux-gnu/libc_nonshared.a +CHECK: kw_as_needed: AS_NEEDED +CHECK: l_paren: ( +CHECK: identifier: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 +CHECK: r_paren: ) +CHECK: libname: m +CHECK: libname: :libgcc.a +CHECK: r_paren: ) +CHECK: kw_entry: ENTRY +CHECK: l_paren: ( +CHECK: identifier: init +CHECK: r_paren: ) +CHECK: eof: +CHECK: OUTPUT_FORMAT("elf64-x86-64","elf64-x86-64","elf64-x86-64") +CHECK: GROUP(/lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libc_nonshared.a AS_NEEDED(/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) -lm -l:libgcc.a) +CHECK: ENTRY(init) +*/ diff --git a/test/LinkerScript/memory-empty.test b/test/LinkerScript/memory-empty.test new file mode 100644 index 000000000000..b71022afdff3 --- /dev/null +++ b/test/LinkerScript/memory-empty.test @@ -0,0 +1,17 @@ +/* + RUN: linker-script-test %s | FileCheck %s +*/ + +MEMORY +{ +} + +/* +CHECK: kw_memory: MEMORY +CHECK: l_brace: { +CHECK: r_brace: } +CHECK: eof: +CHECK: MEMORY +CHECK: { +CHECK: } +*/ diff --git a/test/LinkerScript/memory-missing-attrs.test b/test/LinkerScript/memory-missing-attrs.test new file mode 100644 index 000000000000..fbbf38b76514 --- /dev/null +++ b/test/LinkerScript/memory-missing-attrs.test @@ -0,0 +1,32 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ + +MEMORY +{ + ram () : ORIGIN = 0x20000000, LENGTH = 128M +/* +CHECK-ERR: [[@LINE-2]]:8: error: Expected memory attribute string. +CHECK-ERR-NEXT: {{^ ram \(\) : ORIGIN = 0x20000000, LENGTH = 128M}} +CHECK-ERR-NEXT: {{^ \^}} +*/ +} + +/* +CHECK: kw_memory: MEMORY +CHECK: l_brace: { +CHECK: identifier: ram +CHECK: l_paren: ( +CHECK: r_paren: ) +CHECK: colon: : +CHECK: kw_origin: ORIGIN +CHECK: equal: = +CHECK: number: 0x20000000 +CHECK: comma: , +CHECK: kw_length: LENGTH +CHECK: equal: = +CHECK: number: 128M +CHECK: r_brace: } +CHECK: eof: +*/ diff --git a/test/LinkerScript/memory-missing-length.test b/test/LinkerScript/memory-missing-length.test new file mode 100644 index 000000000000..f317c9a26788 --- /dev/null +++ b/test/LinkerScript/memory-missing-length.test @@ -0,0 +1,29 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ + +MEMORY +{ + ram (rwx) : ORIGIN = 0x20000000, +} +/* +CHECK-ERR: [[@LINE-2]]:1: error: expected LENGTH +CHECK-ERR-NEXT: {{^}}} +CHECK-ERR-NEXT: {{^\^}} +*/ + +/* +CHECK: kw_memory: MEMORY +CHECK: l_brace: { +CHECK: identifier: ram +CHECK: l_paren: ( +CHECK: identifier: rwx +CHECK: r_paren: ) +CHECK: colon: : +CHECK: kw_origin: ORIGIN +CHECK: equal: = +CHECK: number: 0x20000000 +CHECK: r_brace: } +CHECK: eof: +*/ diff --git a/test/LinkerScript/memory-missing-name.test b/test/LinkerScript/memory-missing-name.test new file mode 100644 index 000000000000..46597d4351d3 --- /dev/null +++ b/test/LinkerScript/memory-missing-name.test @@ -0,0 +1,31 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ + +MEMORY +{ + (rwx) : ORIGIN = 0x20000000, LENGTH = 128M +/* +CHECK-ERR: [[@LINE-2]]:3: error: expected memory block definition. +CHECK-ERR-NEXT: {{^ \(rwx\) : ORIGIN = 0x20000000, LENGTH = 128M}} +CHECK-ERR-NEXT: {{^ \^}} +*/ +} + +/* +CHECK: kw_memory: MEMORY +CHECK: l_brace: { +CHECK: l_paren: ( +CHECK: r_paren: ) +CHECK: colon: : +CHECK: kw_origin: ORIGIN +CHECK: equal: = +CHECK: number: 0x20000000 +CHECK: comma: , +CHECK: kw_length: LENGTH +CHECK: equal: = +CHECK: number: 128M +CHECK: r_brace: } +CHECK: eof: +*/ diff --git a/test/LinkerScript/memory-missing-origin.test b/test/LinkerScript/memory-missing-origin.test new file mode 100644 index 000000000000..50a64d17d6c5 --- /dev/null +++ b/test/LinkerScript/memory-missing-origin.test @@ -0,0 +1,30 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ + +MEMORY +{ + ram (rwx) : LENGTH = 128M +/* +CHECK-ERR: [[@LINE-2]]:15: error: expected ORIGIN +CHECK-ERR-NEXT: {{^ ram \(rwx\) : LENGTH = 128M}} +CHECK-ERR-NEXT: {{^ \^}} +*/ + +} + +/* +CHECK: kw_memory: MEMORY +CHECK: l_brace: { +CHECK: identifier: ram +CHECK: l_paren: ( +CHECK: identifier: rwx +CHECK: r_paren: ) +CHECK: colon: : +CHECK: kw_length: LENGTH +CHECK: equal: = +CHECK: number: 128M +CHECK: r_brace: } +CHECK: eof: +*/ diff --git a/test/LinkerScript/memory-valid.test b/test/LinkerScript/memory-valid.test new file mode 100644 index 000000000000..7a0e906c5fb5 --- /dev/null +++ b/test/LinkerScript/memory-valid.test @@ -0,0 +1,56 @@ +/* + RUN: linker-script-test %s | FileCheck %s +*/ + +MEMORY +{ + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 96K + rom (rx) : org = 0x0, len = 256K + boot : o = 0x1000000, l = 0x5f00 +} + +/* +CHECK: kw_memory: MEMORY +CHECK: l_brace: { +CHECK: identifier: ram +CHECK: l_paren: ( +CHECK: identifier: rwx +CHECK: r_paren: ) +CHECK: colon: : +CHECK: kw_origin: ORIGIN +CHECK: equal: = +CHECK: number: 0x20000000 +CHECK: comma: , +CHECK: kw_length: LENGTH +CHECK: equal: = +CHECK: number: 96K +CHECK: identifier: rom +CHECK: l_paren: ( +CHECK: identifier: rx +CHECK: r_paren: ) +CHECK: colon: : +CHECK: kw_origin: org +CHECK: equal: = +CHECK: number: 0x0 +CHECK: comma: , +CHECK: kw_length: len +CHECK: equal: = +CHECK: number: 256K +CHECK: identifier: boot +CHECK: colon: : +CHECK: kw_origin: o +CHECK: equal: = +CHECK: number: 0x1000000 +CHECK: comma: , +CHECK: kw_length: l +CHECK: equal: = +CHECK: number: 0x5f00 +CHECK: r_brace: } +CHECK: eof: +CHECK: MEMORY +CHECK: { +CHECK: ram (rwx) : ORIGIN = 536870912, LENGTH = 98304 +CHECK: rom (rx) : ORIGIN = 0, LENGTH = 262144 +CHECK: boot : ORIGIN = 16777216, LENGTH = 24320 +CHECK: } +*/ diff --git a/test/LinkerScript/missing-entry-symbol.test b/test/LinkerScript/missing-entry-symbol.test new file mode 100644 index 000000000000..54e8f75c90a4 --- /dev/null +++ b/test/LinkerScript/missing-entry-symbol.test @@ -0,0 +1,21 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ +SECTIONS { + ENTRY() +/* +CHECK-ERR: [[@LINE-2]]:11: error: expected identifier in ENTRY +CHECK-ERR-NEXT: {{^ ENTRY()}} +CHECK-ERR-NEXT: {{^ \^}} +*/ +} + +/* +CHECK: l_brace: { +CHECK: kw_entry: ENTRY +CHECK: l_paren: ( +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: eof: +*/ diff --git a/test/LinkerScript/missing-input-file-name.test b/test/LinkerScript/missing-input-file-name.test new file mode 100644 index 000000000000..c4218ccef321 --- /dev/null +++ b/test/LinkerScript/missing-input-file-name.test @@ -0,0 +1,25 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ +SECTIONS { + .text : { ()} +/* +CHECK-ERR: [[@LINE-2]]:15: error: expected symbol assignment or input file name. +CHECK-ERR-NEXT: {{^ \.text : { \(\)}}} +CHECK-ERR-NEXT: {{^ \^}} +*/ +} + +/* +CHECK: kw_sections: SECTIONS +CHECK: l_brace: { +CHECK: identifier: .text +CHECK: colon: : +CHECK: l_brace: { +CHECK: l_paren: ( +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: r_brace: } +CHECK: eof: +*/ diff --git a/test/LinkerScript/missing-input-sections.test b/test/LinkerScript/missing-input-sections.test new file mode 100644 index 000000000000..5db93444b1a9 --- /dev/null +++ b/test/LinkerScript/missing-input-sections.test @@ -0,0 +1,27 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ +SECTIONS { + .text : { *(+)} +/* +CHECK-ERR: [[@LINE-2]]:16: error: expected ) +CHECK-ERR-NEXT: {{^ \.text : { \*\(\+\)}}} +CHECK-ERR-NEXT: {{^ \^}} +*/ +} + +/* +CHECK: kw_sections: SECTIONS +CHECK: l_brace: { +CHECK: identifier: .text +CHECK: colon: : +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: plus: + +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: r_brace: } +CHECK: eof: +*/ diff --git a/test/LinkerScript/missing-operand.test b/test/LinkerScript/missing-operand.test new file mode 100644 index 000000000000..cfa87bf40768 --- /dev/null +++ b/test/LinkerScript/missing-operand.test @@ -0,0 +1,24 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -check-prefix=CHECK-ERR -input-file %t %s +*/ +SECTIONS { + . = foo / ; +/* +CHECK-ERR: [[@LINE-2]]:15: error: expected symbol, number, minus, tilde or left parenthesis. +CHECK-ERR-NEXT: {{^ . = foo / ;}} +CHECK-ERR-NEXT: {{^ \^}} +*/ +} + +/* +CHECK: kw_sections: SECTIONS +CHECK: l_brace: { +CHECK: identifier: . +CHECK: equal: = +CHECK: identifier: foo +CHECK: slash: / +CHECK: semicolon: ; +CHECK: r_brace: } +CHECK: eof: + */ diff --git a/test/LinkerScript/missing-output-section-name.test b/test/LinkerScript/missing-output-section-name.test new file mode 100644 index 000000000000..79792982b619 --- /dev/null +++ b/test/LinkerScript/missing-output-section-name.test @@ -0,0 +1,25 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ +SECTIONS { + : { *()} +/* +CHECK-ERR: [[@LINE-2]]:5: error: expected symbol assignment, entry, overlay or output section name +CHECK-ERR-NEXT: {{^ : { \*\(\)}}} +CHECK-ERR-NEXT: {{^ \^}} +*/ +} + +/* +CHECK: kw_sections: SECTIONS +CHECK: l_brace: { +CHECK: colon: : +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: r_brace: } +CHECK: eof: +*/ diff --git a/test/LinkerScript/missing-symbol.test b/test/LinkerScript/missing-symbol.test new file mode 100644 index 000000000000..4e8777ef40b9 --- /dev/null +++ b/test/LinkerScript/missing-symbol.test @@ -0,0 +1,24 @@ +/* + RUN: linker-script-test %s 2> %t | FileCheck %s + RUN: FileCheck -input-file %t -check-prefix=CHECK-ERR %s +*/ +SECTIONS { + = foo + bar; +/* +CHECK-ERR: [[@LINE-2]]:5: error: expected symbol assignment, entry, overlay or output section name. +CHECK-ERR-NEXT: {{^ = foo \+ bar;}} +CHECK-ERR-NEXT: {{^ \^}} +*/ +} + +/* +CHECK: kw_sections: SECTIONS +CHECK: l_brace: { +CHECK: equal: = +CHECK: identifier: foo +CHECK: plus: + +CHECK: identifier: bar +CHECK: semicolon: ; +CHECK: r_brace: } +CHECK: eof: +*/ diff --git a/test/LinkerScript/sections.test b/test/LinkerScript/sections.test new file mode 100644 index 000000000000..8f7d01418044 --- /dev/null +++ b/test/LinkerScript/sections.test @@ -0,0 +1,618 @@ +/* + This test exercises parsing typical commands found in GNU ld linker scripts. + RUN: linker-script-test %s | FileCheck %s +*/ + +SEARCH_DIR("/usr/x86_64-linux-gnu/lib64"); SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu"); +SECTIONS +{ + PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS; + .interp : { *(.interp) } + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash : { *(.hash) } + .rela.dyn : + { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + } + .rela.plt : + { + *(.rela.plt) + PROVIDE_HIDDEN (__rela_iplt_start = .); + *(.rela.iplt) + PROVIDE_HIDDEN (__rela_iplt_end = .); + } + .init : + { + KEEP (*(SORT_NONE(.init))) + } =0x909090909090909090909090 + PROVIDE (__etext = .); + .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } + .exception_ranges : ONLY_IF_RO { *(.exception_ranges + .exception_ranges*) } + . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); + /* Exception handling */ + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } + .ctors : + { + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } + . = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .); + .got.plt : { *(.got.plt) *(.igot.plt) } + .lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) : + { + *(.lrodata .lrodata.* .gnu.linkonce.lr.*) + } + .ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) : + { + *(.ldata .ldata.* .gnu.linkonce.l.*) + . = ALIGN(. != 0 ? 64 / 8 : 1); + } + . = ALIGN(64 / 8); + _end = .; PROVIDE (end = .); + . = DATA_SEGMENT_END (.); + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } +} + +/* +CHECK: kw_search_dir: SEARCH_DIR +CHECK: l_paren: ( +CHECK: identifier: /usr/x86_64-linux-gnu/lib64 +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: kw_search_dir: SEARCH_DIR +CHECK: l_paren: ( +CHECK: identifier: =/usr/local/lib/x86_64-linux-gnu +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: kw_sections: SECTIONS +CHECK: l_brace: { +CHECK: kw_provide: PROVIDE +CHECK: l_paren: ( +CHECK: identifier: __executable_start +CHECK: equal: = +CHECK: identifier: SEGMENT_START +CHECK: l_paren: ( +CHECK: identifier: text-segment +CHECK: comma: , +CHECK: number: 0x400000 +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: identifier: . +CHECK: equal: = +CHECK: identifier: SEGMENT_START +CHECK: l_paren: ( +CHECK: identifier: text-segment +CHECK: comma: , +CHECK: number: 0x400000 +CHECK: r_paren: ) +CHECK: plus: + +CHECK: identifier: SIZEOF_HEADERS +CHECK: semicolon: ; +CHECK: identifier: .interp +CHECK: colon: : +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .interp +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: identifier: .note.gnu.build-id +CHECK: colon: : +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .note.gnu.build-id +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: identifier: .hash +CHECK: colon: : +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .hash +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: identifier: .rela.dyn +CHECK: colon: : +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .rela.init +CHECK: r_paren: ) +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .rela.text +CHECK: identifier: .rela.text.* +CHECK: identifier: .rela.gnu.linkonce.t.* +CHECK: r_paren: ) +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .rela.fini +CHECK: r_paren: ) +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .rela.rodata +CHECK: identifier: .rela.rodata.* +CHECK: identifier: .rela.gnu.linkonce.r.* +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: identifier: .rela.plt +CHECK: colon: : +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .rela.plt +CHECK: r_paren: ) +CHECK: kw_provide_hidden: PROVIDE_HIDDEN +CHECK: l_paren: ( +CHECK: identifier: __rela_iplt_start +CHECK: equal: = +CHECK: identifier: . +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .rela.iplt +CHECK: r_paren: ) +CHECK: kw_provide_hidden: PROVIDE_HIDDEN +CHECK: l_paren: ( +CHECK: identifier: __rela_iplt_end +CHECK: equal: = +CHECK: identifier: . +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: r_brace: } +CHECK: identifier: .init +CHECK: colon: : +CHECK: l_brace: { +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: star: * +CHECK: l_paren: ( +CHECK: kw_sort_none: SORT_NONE +CHECK: l_paren: ( +CHECK: identifier: .init +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: kw_provide: PROVIDE +CHECK: l_paren: ( +CHECK: identifier: __etext +CHECK: equal: = +CHECK: identifier: . +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: identifier: .eh_frame +CHECK: colon: : +CHECK: kw_only_if_ro: ONLY_IF_RO +CHECK: l_brace: { +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .eh_frame +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: identifier: .exception_ranges +CHECK: colon: : +CHECK: kw_only_if_ro: ONLY_IF_RO +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .exception_ranges +CHECK: identifier: .exception_ranges* +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: identifier: . +CHECK: equal: = +CHECK: kw_align: ALIGN +CHECK: l_paren: ( +CHECK: identifier: CONSTANT +CHECK: l_paren: ( +CHECK: identifier: MAXPAGESIZE +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: minus: - +CHECK: l_paren: ( +CHECK: l_paren: ( +CHECK: identifier: CONSTANT +CHECK: l_paren: ( +CHECK: identifier: MAXPAGESIZE +CHECK: r_paren: ) +CHECK: minus: - +CHECK: identifier: . +CHECK: r_paren: ) +CHECK: amp: & +CHECK: l_paren: ( +CHECK: identifier: CONSTANT +CHECK: l_paren: ( +CHECK: identifier: MAXPAGESIZE +CHECK: r_paren: ) +CHECK: minus: - +CHECK: number: 1 +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: identifier: . +CHECK: equal: = +CHECK: identifier: DATA_SEGMENT_ALIGN +CHECK: l_paren: ( +CHECK: identifier: CONSTANT +CHECK: l_paren: ( +CHECK: identifier: MAXPAGESIZE +CHECK: r_paren: ) +CHECK: comma: , +CHECK: identifier: CONSTANT +CHECK: l_paren: ( +CHECK: identifier: COMMONPAGESIZE +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: identifier: .eh_frame +CHECK: colon: : +CHECK: kw_only_if_rw: ONLY_IF_RW +CHECK: l_brace: { +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .eh_frame +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: identifier: .ctors +CHECK: colon: : +CHECK: l_brace: { +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: identifier: *crtbegin.o +CHECK: l_paren: ( +CHECK: identifier: .ctors +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: identifier: *crtbegin?.o +CHECK: l_paren: ( +CHECK: identifier: .ctors +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: star: * +CHECK: l_paren: ( +CHECK: kw_exclude_file: EXCLUDE_FILE +CHECK: l_paren: ( +CHECK: identifier: *crtend.o +CHECK: identifier: *crtend?.o +CHECK: r_paren: ) +CHECK: identifier: .ctors +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: star: * +CHECK: l_paren: ( +CHECK: kw_sort_by_name: SORT +CHECK: l_paren: ( +CHECK: identifier: .ctors.* +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .ctors +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: identifier: .dtors +CHECK: colon: : +CHECK: l_brace: { +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: identifier: *crtbegin.o +CHECK: l_paren: ( +CHECK: identifier: .dtors +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: identifier: *crtbegin?.o +CHECK: l_paren: ( +CHECK: identifier: .dtors +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: star: * +CHECK: l_paren: ( +CHECK: kw_exclude_file: EXCLUDE_FILE +CHECK: l_paren: ( +CHECK: identifier: *crtend.o +CHECK: identifier: *crtend?.o +CHECK: r_paren: ) +CHECK: identifier: .dtors +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: star: * +CHECK: l_paren: ( +CHECK: kw_sort_by_name: SORT +CHECK: l_paren: ( +CHECK: identifier: .dtors.* +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: kw_keep: KEEP +CHECK: l_paren: ( +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .dtors +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: identifier: . +CHECK: equal: = +CHECK: identifier: DATA_SEGMENT_RELRO_END +CHECK: l_paren: ( +CHECK: identifier: SIZEOF +CHECK: l_paren: ( +CHECK: identifier: .got.plt +CHECK: r_paren: ) +CHECK: greaterequal: >= +CHECK: number: 24 +CHECK: question: ? +CHECK: number: 24 +CHECK: colon: : +CHECK: number: 0 +CHECK: comma: , +CHECK: identifier: . +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: identifier: .got.plt +CHECK: colon: : +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .got.plt +CHECK: r_paren: ) +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .igot.plt +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: identifier: .lrodata +CHECK: kw_align: ALIGN +CHECK: l_paren: ( +CHECK: identifier: CONSTANT +CHECK: l_paren: ( +CHECK: identifier: MAXPAGESIZE +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: plus: + +CHECK: l_paren: ( +CHECK: identifier: . +CHECK: amp: & +CHECK: l_paren: ( +CHECK: identifier: CONSTANT +CHECK: l_paren: ( +CHECK: identifier: MAXPAGESIZE +CHECK: r_paren: ) +CHECK: minus: - +CHECK: number: 1 +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: colon: : +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .lrodata +CHECK: identifier: .lrodata.* +CHECK: identifier: .gnu.linkonce.lr.* +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: identifier: .ldata +CHECK: kw_align: ALIGN +CHECK: l_paren: ( +CHECK: identifier: CONSTANT +CHECK: l_paren: ( +CHECK: identifier: MAXPAGESIZE +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: plus: + +CHECK: l_paren: ( +CHECK: identifier: . +CHECK: amp: & +CHECK: l_paren: ( +CHECK: identifier: CONSTANT +CHECK: l_paren: ( +CHECK: identifier: MAXPAGESIZE +CHECK: r_paren: ) +CHECK: minus: - +CHECK: number: 1 +CHECK: r_paren: ) +CHECK: r_paren: ) +CHECK: colon: : +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .ldata +CHECK: identifier: .ldata.* +CHECK: identifier: .gnu.linkonce.l.* +CHECK: r_paren: ) +CHECK: identifier: . +CHECK: equal: = +CHECK: kw_align: ALIGN +CHECK: l_paren: ( +CHECK: identifier: . +CHECK: exclaimequal: != +CHECK: number: 0 +CHECK: question: ? +CHECK: number: 64 +CHECK: slash: / +CHECK: number: 8 +CHECK: colon: : +CHECK: number: 1 +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: r_brace: } +CHECK: identifier: . +CHECK: equal: = +CHECK: kw_align: ALIGN +CHECK: l_paren: ( +CHECK: number: 64 +CHECK: slash: / +CHECK: number: 8 +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: identifier: _end +CHECK: equal: = +CHECK: identifier: . +CHECK: semicolon: ; +CHECK: kw_provide: PROVIDE +CHECK: l_paren: ( +CHECK: identifier: end +CHECK: equal: = +CHECK: identifier: . +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: identifier: . +CHECK: equal: = +CHECK: identifier: DATA_SEGMENT_END +CHECK: l_paren: ( +CHECK: identifier: . +CHECK: r_paren: ) +CHECK: semicolon: ; +CHECK: kw_discard: /DISCARD/ +CHECK: colon: : +CHECK: l_brace: { +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .note.GNU-stack +CHECK: r_paren: ) +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .gnu_debuglink +CHECK: r_paren: ) +CHECK: star: * +CHECK: l_paren: ( +CHECK: identifier: .gnu.lto_* +CHECK: r_paren: ) +CHECK: r_brace: } +CHECK: r_brace: } +CHECK: eof: +CHECK: SEARCH_DIR("/usr/x86_64-linux-gnu/lib64") +CHECK: SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu") +CHECK: SECTIONS +CHECK: { +CHECK: PROVIDE(__executable_start = SEGMENT_START(text-segment, 4194304)) +CHECK: . = (SEGMENT_START(text-segment, 4194304) + SIZEOF_HEADERS) +CHECK: .interp : +CHECK: { +CHECK: *(.interp) +CHECK: } +CHECK: .note.gnu.build-id : +CHECK: { +CHECK: *(.note.gnu.build-id) +CHECK: } +CHECK: .hash : +CHECK: { +CHECK: *(.hash) +CHECK: } +CHECK: .rela.dyn : +CHECK: { +CHECK: *(.rela.init) +CHECK: *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) +CHECK: *(.rela.fini) +CHECK: *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) +CHECK: } +CHECK: .rela.plt : +CHECK: { +CHECK: *(.rela.plt) +CHECK: PROVIDE_HIDDEN(__rela_iplt_start = .) +CHECK: *(.rela.iplt) +CHECK: PROVIDE_HIDDEN(__rela_iplt_end = .) +CHECK: } +CHECK: .init : +CHECK: { +CHECK: KEEP(*(SORT_NONE(.init))) +CHECK: } =0x909090909090909090909090 +CHECK: PROVIDE(__etext = .) +CHECK: .eh_frame : +CHECK: ONLY_IF_RO { +CHECK: KEEP(*(.eh_frame)) +CHECK: } +CHECK: .exception_ranges : +CHECK: ONLY_IF_RO { +CHECK: *(.exception_ranges .exception_ranges*) +CHECK: } +CHECK: . = (ALIGN(CONSTANT(MAXPAGESIZE)) - ((CONSTANT(MAXPAGESIZE) - .) & (CONSTANT(MAXPAGESIZE) - 1))) +CHECK: . = DATA_SEGMENT_ALIGN(CONSTANT(MAXPAGESIZE), CONSTANT(COMMONPAGESIZE)) +CHECK: .eh_frame : +CHECK: ONLY_IF_RW { +CHECK: KEEP(*(.eh_frame)) +CHECK: } +CHECK: .ctors : +CHECK: { +CHECK: KEEP(*crtbegin.o(.ctors)) +CHECK: KEEP(*crtbegin?.o(.ctors)) +CHECK: KEEP(*(EXCLUDE_FILE(*crtend.o *crtend?.o ) .ctors)) +CHECK: KEEP(*(SORT_BY_NAME(.ctors.*))) +CHECK: KEEP(*(.ctors)) +CHECK: } +CHECK: .dtors : +CHECK: { +CHECK: KEEP(*crtbegin.o(.dtors)) +CHECK: KEEP(*crtbegin?.o(.dtors)) +CHECK: KEEP(*(EXCLUDE_FILE(*crtend.o *crtend?.o ) .dtors)) +CHECK: KEEP(*(SORT_BY_NAME(.dtors.*))) +CHECK: KEEP(*(.dtors)) +CHECK: } +CHECK: . = DATA_SEGMENT_RELRO_END((SIZEOF(.got.plt) >= 24) ? 24 : 0, .) +CHECK: .got.plt : +CHECK: { +CHECK: *(.got.plt) +CHECK: *(.igot.plt) +CHECK: } +CHECK: .lrodata (ALIGN(CONSTANT(MAXPAGESIZE)) + (. & (CONSTANT(MAXPAGESIZE) - 1))) : +CHECK: { +CHECK: *(.lrodata .lrodata.* .gnu.linkonce.lr.*) +CHECK: } +CHECK: .ldata (ALIGN(CONSTANT(MAXPAGESIZE)) + (. & (CONSTANT(MAXPAGESIZE) - 1))) : +CHECK: { +CHECK: *(.ldata .ldata.* .gnu.linkonce.l.*) +CHECK: . = ALIGN((. != 0) ? (64 / 8) : 1) +CHECK: } +CHECK: . = ALIGN((64 / 8)) +CHECK: _end = . +CHECK: PROVIDE(end = .) +CHECK: . = DATA_SEGMENT_END(.) +CHECK: : +CHECK: { +CHECK: *(.note.GNU-stack) +CHECK: *(.gnu_debuglink) +CHECK: *(.gnu.lto_*) +CHECK: } +CHECK: } +*/ diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 000000000000..2d45e4fae2a7 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,71 @@ +LLD_LEVEL := .. +include $(LLD_LEVEL)/Makefile + +# Test in all immediate subdirectories if unset. +ifdef TESTSUITE +TESTDIRS := $(TESTSUITE:%=$(PROJ_SRC_DIR)/%) +else +TESTDIRS ?= $(PROJ_SRC_DIR) +endif + +# 'lit' wants objdir paths, so it will pick up the lit.site.cfg. +TESTDIRS := $(TESTDIRS:$(PROJ_SRC_DIR)%=$(PROJ_OBJ_DIR)%) + +# Allow EXTRA_TESTDIRS to provide additional test directories. +TESTDIRS += $(EXTRA_TESTDIRS) + +ifndef TESTARGS +ifdef VERBOSE +TESTARGS = -v +else +TESTARGS = -s -v +endif +endif + +# Make sure any extra test suites can find the main site config. +LIT_ARGS := --param lld_site_config=$(PROJ_OBJ_DIR)/lit.site.cfg + +ifdef VG + LIT_ARGS += "--vg" +endif + +all:: lit.site.cfg Unit/lit.site.cfg + @ echo '--- Running lld tests for $(TARGET_TRIPLE) ---' + @ $(PYTHON) $(LLVM_SRC_ROOT)/utils/lit/lit.py \ + $(LIT_ARGS) $(TESTARGS) $(TESTDIRS) + +FORCE: + +lit.site.cfg: FORCE + @echo "Making lld 'lit.site.cfg' file..." + @$(ECHOPATH) s=@LLVM_SOURCE_DIR@=$(LLVM_SRC_ROOT)=g > lit.tmp + @$(ECHOPATH) s=@LLVM_BINARY_DIR@=$(LLVM_OBJ_ROOT)=g >> lit.tmp + @$(ECHOPATH) s=@LLVM_TOOLS_DIR@=$(ToolDir)=g >> lit.tmp + @$(ECHOPATH) s=@LLVM_LIBS_DIR@=$(LibDir)=g >> lit.tmp + @$(ECHOPATH) s=@LLD_SOURCE_DIR@=$(PROJ_SRC_DIR)/..=g >> lit.tmp + @$(ECHOPATH) s=@LLD_BINARY_DIR@=$(PROJ_OBJ_DIR)/..=g >> lit.tmp + @$(ECHOPATH) s=@TARGET_TRIPLE@=$(TARGET_TRIPLE)=g >> lit.tmp + @sed -f lit.tmp $(PROJ_SRC_DIR)/lit.site.cfg.in > $@ + @-rm -f lit.tmp + +Unit/lit.site.cfg: FORCE + @echo "Making lld 'Unit/lit.site.cfg' file..." + @$(MKDIR) $(dir $@) + @$(ECHOPATH) s=@LLVM_SOURCE_DIR@=$(LLVM_SRC_ROOT)=g > unit.tmp + @$(ECHOPATH) s=@LLVM_BINARY_DIR@=$(LLVM_OBJ_ROOT)=g >> unit.tmp + @$(ECHOPATH) s=@LLVM_TOOLS_DIR@=$(ToolDir)=g >> unit.tmp + @$(ECHOPATH) s=@LLVM_LIBS_DIR@=$(LibDir)=g >> unit.tmp + @$(ECHOPATH) s=@LLD_SOURCE_DIR@=$(PROJ_SRC_DIR)/..=g >> unit.tmp + @$(ECHOPATH) s=@LLD_BINARY_DIR@=$(PROJ_OBJ_DIR)/..=g >> unit.tmp + @$(ECHOPATH) s=@TARGET_TRIPLE@=$(TARGET_TRIPLE)=g >> unit.tmp + @$(ECHOPATH) s=@LLVM_BUILD_MODE@=$(BuildMode)=g >> unit.tmp + @$(ECHOPATH) s=@ENABLE_SHARED@=$(ENABLE_SHARED)=g >> unit.tmp + @$(ECHOPATH) s=@SHLIBDIR@=$(SharedLibDir)=g >> unit.tmp + @$(ECHOPATH) s=@SHLIBPATH_VAR@=$(SHLIBPATH_VAR)=g >> unit.tmp + @sed -f unit.tmp $(PROJ_SRC_DIR)/Unit/lit.site.cfg.in > $@ + @-rm -f unit.tmp + +clean:: + @ find . -name Output | xargs rm -fr + +.PHONY: all report clean diff --git a/test/Unit/lit.cfg b/test/Unit/lit.cfg new file mode 100644 index 000000000000..4bc973a58edd --- /dev/null +++ b/test/Unit/lit.cfg @@ -0,0 +1,23 @@ +# -*- Python -*- + +# Configuration file for the 'lit' test runner. + +import os + +import lit.formats + +# name: The name of this test suite. +config.name = 'lld-Unit' + +# suffixes: A list of file extensions to treat as test files. +config.suffixes = [] + +# test_source_root: The root path where unit test binaries are located. +# test_exec_root: The root path where tests should be run. +config.test_source_root = os.path.join(config.lld_obj_root, 'unittests') +config.test_exec_root = config.test_source_root + +# testFormat: The test format to use to interpret tests. +if not hasattr(config, 'llvm_build_mode'): + lit_config.fatal("unable to find llvm_build_mode value on config") +config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, 'Tests') diff --git a/test/Unit/lit.site.cfg.in b/test/Unit/lit.site.cfg.in new file mode 100644 index 000000000000..74c5eca91153 --- /dev/null +++ b/test/Unit/lit.site.cfg.in @@ -0,0 +1,25 @@ +## Autogenerated by LLVM/lld configuration. +# Do not edit! +config.llvm_src_root = "@LLVM_SOURCE_DIR@" +config.llvm_obj_root = "@LLVM_BINARY_DIR@" +config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" +config.llvm_libs_dir = "@LLVM_LIBS_DIR@" +config.llvm_build_mode = "@LLVM_BUILD_MODE@" +config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" +config.lld_obj_root = "@LLD_BINARY_DIR@" +config.lld_src_root = "@LLD_SOURCE_DIR@" +config.target_triple = "@TARGET_TRIPLE@" +config.python_executable = "@PYTHON_EXECUTABLE@" + +# Support substitution of the tools and libs dirs with user parameters. This is +# used when we can't determine the tool dir at configuration time. +try: + config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params + config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params + config.llvm_build_mode = config.llvm_build_mode % lit_config.params +except KeyError as e: + key, = e.args + lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key)) + +# Let the main config do the real work. +lit_config.load_config(config, "@LLD_SOURCE_DIR@/test/Unit/lit.cfg") diff --git a/test/core/absolute-basic.objtxt b/test/core/absolute-basic.objtxt new file mode 100644 index 000000000000..edfbe8629b0d --- /dev/null +++ b/test/core/absolute-basic.objtxt @@ -0,0 +1,23 @@ +# RUN: lld -core --dead-strip %s | FileCheck %s + +# +# Test that absolute symbols are parsed and preserved +# + +--- +absolute-atoms: + - name: putchar + value: 0xFFFF0040 + + - name: reset + value: 0xFFFF0080 + +... + + +# CHECK: absolute-atoms: +# CHECK: name: putchar +# CHECK: value: 0x00000000FFFF0040 +# CHECK: name: reset +# CHECK: value: 0x00000000FFFF0080 +# CHECK: ... diff --git a/test/core/absolute-local.objtxt b/test/core/absolute-local.objtxt new file mode 100644 index 000000000000..1ba4c7f04326 --- /dev/null +++ b/test/core/absolute-local.objtxt @@ -0,0 +1,25 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that absolute symbols with local scope do not cause name conflict +# +--- +absolute-atoms: + - name: putchar + ref-name: pc1 + value: 0xFFFF0040 + scope: static + + - name: putchar + ref-name: pc2 + value: 0xFFFF0040 + scope: static +... + +# CHECK: --- +# CHECK: absolute-atoms: +# CHECK: - name: putchar +# CHECK: value: 0x00000000FFFF0040 +# CHECK: - name: putchar +# CHECK: value: 0x00000000FFFF0040 +# CHECK: ... diff --git a/test/core/archive-basic.objtxt b/test/core/archive-basic.objtxt new file mode 100644 index 000000000000..ec825c1a7e52 --- /dev/null +++ b/test/core/archive-basic.objtxt @@ -0,0 +1,44 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Tests archives in YAML. Tests that an undefined in a regular file will load +# all atoms in select archive members. +# + +--- !native +defined-atoms: + - name: foo + type: code + +undefined-atoms: + - name: bar + +--- !archive +members: + - name: bar.o + content: !native + defined-atoms: + - name: bar + scope: global + type: code + + - name: bar2 + type: code + + - name: baz.o + content: !native + defined-atoms: + - name: baz + scope: global + type: code + + - name: baz2 + type: code +... + +# CHECK: name: foo +# CHECK-NOT: undefined-atoms: +# CHECK: name: bar +# CHECK: name: bar2 +# CHECK-NOT: name: baz +# CHECK: ... diff --git a/test/core/archive-chain.objtxt b/test/core/archive-chain.objtxt new file mode 100644 index 000000000000..0f80985ec112 --- /dev/null +++ b/test/core/archive-chain.objtxt @@ -0,0 +1,70 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Tests that an undefine in one archive can force a load from another archive. +# + +--- !native +defined-atoms: + - name: foo + type: code + +undefined-atoms: + - name: bar1 + +--- !archive +members: + - name: bar1.o + content: !native + defined-atoms: + - name: bar1 + scope: global + type: code + + - name: bar1b + type: code + + undefined-atoms: + - name: baz1 + + - name: bar2.o + content: !native + defined-atoms: + - name: bar2 + scope: global + type: code + + - name: bar2b + type: code + +--- !archive +members: + - name: baz1.o + content: !native + defined-atoms: + - name: baz1 + scope: global + type: code + + - name: baz1b + type: code + + - name: baz2.o + content: !native + defined-atoms: + - name: baz2 + scope: global + type: code + + - name: baz2b + type: code +... + +# CHECK: name: foo +# CHECK: name: bar1 +# CHECK: name: bar1b +# CHECK-NOT: name: bar2 +# CHECK: name: baz1 +# CHECK: name: baz1b +# CHECK-NOT: name: baz2 +# CHECK: ... diff --git a/test/core/archive-tentdef-search.objtxt b/test/core/archive-tentdef-search.objtxt new file mode 100644 index 000000000000..3d26778e4986 --- /dev/null +++ b/test/core/archive-tentdef-search.objtxt @@ -0,0 +1,42 @@ +# RUN: lld -core %s | FileCheck -check-prefix=CHK1 %s +# RUN: lld -core --commons-search-archives %s | FileCheck -check-prefix=CHK2 %s + +# +# Tests that -commons-search-archives cause core linker to look for overrides +# of tentative definition in archives, and that not using that option +# does not search. +# + +--- !native +defined-atoms: + - name: foo + type: code + + - name: bar + scope: global + type: zero-fill + merge: as-tentative + +--- !archive +members: + - name: bar.o + content: !native + defined-atoms: + - name: bar + scope: global + type: data + + - name: bar2 + type: data +... + +# CHK1: name: foo +# CHK1: name: bar +# CHK1: merge: as-tentative +# CHK1: ... + +# CHK2: name: foo +# CHK2: name: bar +# CHK2-NOT: merge: as-tentative +# CHK2: name: bar2 +# CHK2: ... diff --git a/test/core/associates.objtxt b/test/core/associates.objtxt new file mode 100644 index 000000000000..bf780693ab70 --- /dev/null +++ b/test/core/associates.objtxt @@ -0,0 +1,30 @@ +# RUN: lld -core %s | FileCheck %s + +--- +defined-atoms: + - name: f1 + merge: as-weak + scope: global + references: + - kind: associate + target: f2 + - name: f2 +--- +defined-atoms: + - name: f1 + merge: as-weak + scope: global + references: + - kind: associate + target: f2 + - name: f2 +... + +# CHECK: defined-atoms: +# CHECK: - name: f1 +# CHECK: scope: global +# CHECK: references: +# CHECK: - kind: associate +# CHECK: target: f2 +# CHECK: - name: f2 +# CHECK-NOT: - name: f2 diff --git a/test/core/auto-hide-coalesce.objtxt b/test/core/auto-hide-coalesce.objtxt new file mode 100644 index 000000000000..ad82d5afc573 --- /dev/null +++ b/test/core/auto-hide-coalesce.objtxt @@ -0,0 +1,60 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Tests auto-hide bit during coalescing +# + +--- +defined-atoms: + - name: _inlineFunc1 + scope: global + type: code + merge: as-weak + + - name: _inlineFunc2 + scope: global + type: code + merge: as-weak + + - name: _inlineFunc3 + scope: global + type: code + merge: as-addressed-weak + + - name: _inlineFunc4 + scope: global + type: code + merge: as-addressed-weak +--- +defined-atoms: + - name: _inlineFunc1 + scope: global + type: code + merge: as-weak + + - name: _inlineFunc2 + scope: global + type: code + merge: as-addressed-weak + + - name: _inlineFunc3 + scope: global + type: code + merge: as-weak + + - name: _inlineFunc4 + scope: global + type: code + merge: as-addressed-weak +... + + +# CHECK: name: _inlineFunc1 +# CHECK: merge: as-weak +# CHECK: name: _inlineFunc3 +# CHECK: merge: as-addressed-weak +# CHECK: name: _inlineFunc4 +# CHECK: merge: as-addressed-weak +# CHECK: name: _inlineFunc2 +# CHECK: merge: as-addressed-weak +# CHECK: ... diff --git a/test/core/code-model-attributes.objtxt b/test/core/code-model-attributes.objtxt new file mode 100644 index 000000000000..8c30e868567d --- /dev/null +++ b/test/core/code-model-attributes.objtxt @@ -0,0 +1,50 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that code model attributes are preserved +# + +--- +defined-atoms: + - name: _def +--- +defined-atoms: + - name: _none + code-model: none +--- +defined-atoms: + - name: _mips_pic + code-model: mips-pic +--- +defined-atoms: + - name: _mips_micro + code-model: mips-micro +--- +defined-atoms: + - name: _mips_micro_pic + code-model: mips-micro-pic +--- +defined-atoms: + - name: _mips_16 + code-model: mips-16 +... + +# CHECK: name: _def +# CHECK-NOT: code-model: mips-pic +# CHECK-NOT: code-model: mips-micro +# CHECK-NOT: code-model: mips-micro-pic +# CHECK-NOT: code-model: mips-16 +# CHECK: name: _none +# CHECK-NOT: code-model: mips-pic +# CHECK-NOT: code-model: mips-micro +# CHECK-NOT: code-model: mips-micro-pic +# CHECK-NOT: code-model: mips-16 +# CHECK: name: _mips_pic +# CHECK: code-model: mips-pic +# CHECK: name: _mips_micro +# CHECK: code-model: mips-micro +# CHECK: name: _mips_micro_pic +# CHECK: code-model: mips-micro-pic +# CHECK: name: _mips_16 +# CHECK: code-model: mips-16 +# CHECK: ... diff --git a/test/core/constants-coalesce.objtxt b/test/core/constants-coalesce.objtxt new file mode 100644 index 000000000000..a82f68009087 --- /dev/null +++ b/test/core/constants-coalesce.objtxt @@ -0,0 +1,60 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that duplicate merge-by-content anonymous constants are coalesced +# and non-mergable duplicate constants are not coalesced. +# + +--- +defined-atoms: + - ref-name: L4-byte + type: constant + merge: by-content + content: [ 01, 02, 03, 04 ] + + - ref-name: L8-byte + type: constant + merge: by-content + content: [ 01, 23, 45, 67, 89, AB, CD, EF ] + + - ref-name: L1 + type: constant + content: [ 01, 02 ] +--- +defined-atoms: + - ref-name: L1 + type: constant + content: [ 01, 02 ] + - ref-name: L2 + type: constant + merge: by-content + content: [ 01, 02, 03, 04 ] +--- +defined-atoms: + - ref-name: L2 + type: constant + merge: by-content + content: [ 01, 23, 45, 67, 89, AB, CD, EF ] + - ref-name: L3 + type: constant + merge: by-content + content: [ 01, 02, 03 ] +... + +# CHECK-NOT: name: +# CHECK: type: constant +# CHECK: content: [ 01, 02, 03, 04 ] +# CHECK: merge: by-content +# CHECK: type: constant +# CHECK: content: [ 01, 23, 45, 67, 89, AB, CD, EF ] +# CHECK: merge: by-content +# CHECK: type: constant +# CHECK: content: [ 01, 02 ] +# CHECK: type: constant +# CHECK: content: [ 01, 02 ] +# CHECK: type: constant +# CHECK: content: [ 01, 02, 03 ] +# CHECK: merge: by-content +# CHECK: ... + + diff --git a/test/core/cstring-coalesce.objtxt b/test/core/cstring-coalesce.objtxt new file mode 100644 index 000000000000..78986a08c640 --- /dev/null +++ b/test/core/cstring-coalesce.objtxt @@ -0,0 +1,41 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that duplicate c-strings are coalesced +# + +--- +defined-atoms: + - ref-name: L0 + type: c-string + merge: by-content + content: [ 68, 65, 6c, 6c, 6f, 00 ] + + - ref-name: L1 + type: c-string + merge: by-content + content: [ 74, 68, 65, 72, 65, 00 ] +--- +defined-atoms: + - ref-name: L2 + type: c-string + merge: by-content + content: [ 68, 65, 6c, 6c, 6f, 00 ] +--- +defined-atoms: + - ref-name: L2 + type: c-string + merge: by-content + content: [ 74, 68, 65, 72, 65, 00 ] +... + +# CHECK-NOT: name: +# CHECK: type: c-string +# CHECK: content: [ 68, 65, 6C, 6C, 6F, 00 ] +# CHECK: merge: by-content +# CHECK: type: c-string +# CHECK: content: [ 74, 68, 65, 72, 65, 00 ] +# CHECK: merge: by-content +# CHECK: ... + + diff --git a/test/core/custom-section-coalesce.objtxt b/test/core/custom-section-coalesce.objtxt new file mode 100644 index 000000000000..e9bada56938d --- /dev/null +++ b/test/core/custom-section-coalesce.objtxt @@ -0,0 +1,78 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that custom sections are preserved when duplicate merge-by-content +# constants are coalesced. +# + +--- +defined-atoms: + - ref-name: L1 + type: constant + merge: by-content + content: [ 01, 02, 03, 04 ] + section-choice: custom-required + section-name: .mysection + + - ref-name: L2 + type: constant + merge: by-content + content: [ 05, 06, 07, 08 ] + section-choice: custom-required + section-name: .mysection + + - ref-name: L3 + type: constant + merge: by-content + content: [ 01, 02, 03, 04 ] + +--- +defined-atoms: + - ref-name: L1 + type: constant + merge: by-content + content: [ 01, 02, 03, 04 ] + section-choice: custom-required + section-name: .mysection + + - ref-name: L2 + type: constant + merge: by-content + content: [ 01, 02, 03, 04 ] + section-choice: custom-required + section-name: .mysection2 +--- +defined-atoms: + - ref-name: L1 + type: constant + merge: by-content + content: [ 05, 06, 07, 08 ] + section-choice: custom-required + section-name: .mysection + + - ref-name: L2 + type: constant + merge: by-content + content: [ 01, 02, 03, 04 ] +... + + +# CHECK:defined-atoms: +# CHECK: - type: constant +# CHECK: content: [ 01, 02, 03, 04 ] +# CHECK: merge: by-content +# CHECK: section-choice: custom-required +# CHECK: section-name: .mysection +# CHECK: - type: constant +# CHECK: content: [ 05, 06, 07, 08 ] +# CHECK: merge: by-content +# CHECK: section-choice: custom-required +# CHECK: section-name: .mysection +# CHECK: - type: constant +# CHECK: content: [ 01, 02, 03, 04 ] +# CHECK: merge: by-content +# CHECK: - type: constant +# CHECK: content: [ 01, 02, 03, 04 ] +# CHECK: merge: by-content +# CHECK: section-choice: custom-required +# CHECK: section-name: .mysection2 diff --git a/test/core/custom-section.objtxt b/test/core/custom-section.objtxt new file mode 100644 index 000000000000..ce305e9af38e --- /dev/null +++ b/test/core/custom-section.objtxt @@ -0,0 +1,34 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that custom sections are preserved +# + +--- +defined-atoms: + - name: _foo1 + scope: global + section-choice: content + + - name: _foo2 + scope: global + section-choice: custom + section-name: __foozle + + - name: _foo3 + scope: global + section-choice: custom-required + section-name: __boozle + +... + + +# CHECK: name: _foo1 +# CHECK-NOT: section-name: +# CHECK: name: _foo2 +# CHECK: section-choice: custom +# CHECK: section-name: __foozle +# CHECK: name: _foo3 +# CHECK: section-choice: custom-required +# CHECK: section-name: __boozle +# CHECK: ... diff --git a/test/core/dead-strip-attributes.objtxt b/test/core/dead-strip-attributes.objtxt new file mode 100644 index 000000000000..dcb35a21e261 --- /dev/null +++ b/test/core/dead-strip-attributes.objtxt @@ -0,0 +1,29 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that dead strip attributes are preserved +# + +--- +defined-atoms: + - name: _foo1 + dead-strip: normal +--- +defined-atoms: + - name: _foo2 + dead-strip: never +--- +defined-atoms: + - name: _foo3 + dead-strip: always +... + + +# CHECK: name: _foo1 +# CHECK-NOT: dead-strip: never +# CHECK-NOT: dead-strip: always +# CHECK: name: _foo2 +# CHECK: dead-strip: never +# CHECK: name: _foo3 +# CHECK: dead-strip: always +# CHECK: ... diff --git a/test/core/dead-strip-basic.objtxt b/test/core/dead-strip-basic.objtxt new file mode 100644 index 000000000000..64cd2291c76b --- /dev/null +++ b/test/core/dead-strip-basic.objtxt @@ -0,0 +1,62 @@ +# RUN: lld -core --dead-strip %s | FileCheck -check-prefix=CHK1 %s +# RUN: lld -core %s | FileCheck -check-prefix=CHK2 %s + +# +# Test that -dead-strip removes unreachable code and data +# and that not using that option leaves them. +# + +--- +defined-atoms: + - name: entry + dead-strip: never + references: + - offset: 1 + kind: pcrel32 + target: bar + - offset: 6 + kind: pcrel32 + target: baz + + - name: mydead1 + scope: global + +undefined-atoms: + - name: bar + + - name: baz +--- +defined-atoms: + - name: mydead2 + scope: global + type: data + + - name: bar + scope: global + type: data +--- +defined-atoms: + - name: baz + scope: global + type: code + + - name: mydead3 + type: code +... + + +# CHK1: name: entry +# CHK1-NOT: name: mydead1 +# CHK1: name: bar +# CHK1-NOT: name: mydead2 +# CHK1: name: baz +# CHK1-NOT: name: mydead3 +# CHK1: ... + +# CHK2: name: entry +# CHK2: name: mydead1 +# CHK2: name: mydead2 +# CHK2: name: bar +# CHK2: name: baz +# CHK2: name: mydead3 +# CHK2: ... diff --git a/test/core/dead-strip-globals.objtxt b/test/core/dead-strip-globals.objtxt new file mode 100644 index 000000000000..8feb235d07c3 --- /dev/null +++ b/test/core/dead-strip-globals.objtxt @@ -0,0 +1,60 @@ +# RUN: lld -core --dead-strip --keep-globals %s | FileCheck -check-prefix=CHK1 %s +# RUN: lld -core --dead-strip %s | FileCheck -check-prefix=CHK2 %s + +# +# Test that -keep-globals prevents -dead-strip from removing globals. +# + +--- +defined-atoms: + - name: entry + dead-strip: never + references: + - offset: 1 + kind: pcrel32 + target: bar + - offset: 6 + kind: pcrel32 + target: baz + + - name: myglobal1 + scope: global + +undefined-atoms: + - name: bar + - name: baz +--- +defined-atoms: + - name: myglobal2 + scope: global + type: data + + - name: bar + scope: hidden + type: data +--- +defined-atoms: + - name: baz + scope: hidden + type: code + + - name: mydead + type: code +... + + +# CHK1: name: entry +# CHK1: name: myglobal1 +# CHK1: name: myglobal2 +# CHK1: name: bar +# CHK1: name: baz +# CHK1-NOT: name: mydead +# CHK1: ... + +# CHK2: name: entry +# CHK2-NOT: name: myglobal1 +# CHK2-NOT: name: myglobal2 +# CHK2: name: bar +# CHK2: name: baz +# CHK2-NOT: name: mydead +# CHK2: ... diff --git a/test/core/dead-strip-reverse.objtxt b/test/core/dead-strip-reverse.objtxt new file mode 100644 index 000000000000..f471bebcdf4e --- /dev/null +++ b/test/core/dead-strip-reverse.objtxt @@ -0,0 +1,25 @@ +# RUN: lld -core --dead-strip %s | FileCheck -check-prefix=CHECK1 %s +# RUN: lld -core %s | FileCheck -check-prefix=CHECK2 %s + +--- +defined-atoms: + - name: entry + dead-strip: never + scope: global + references: + - kind: layout-after + offset: 0 + target: def + - name: def + scope: global + - name: dead + scope: global +... + +# CHECK1: name: entry +# CHECK1: name: def +# CHECK1-NOT: name: dead + +# CHECK2: name: entry +# CHECK2: name: def +# CHECK2: name: dead diff --git a/test/core/error-atom-attribute.objtxt b/test/core/error-atom-attribute.objtxt new file mode 100644 index 000000000000..6643aba29eea --- /dev/null +++ b/test/core/error-atom-attribute.objtxt @@ -0,0 +1,19 @@ +# RUN: not lld -core %s 2> %t.err +# RUN: FileCheck %s < %t.err + +# +# Test that unknown atom attribute produces a readable error. +# + +--- +defined-atoms: + - name: entry + scope: hidden + foobar: true + dead-strip: never + +... + + +# CHECK: error: unknown key 'foobar' +# CHECK: foobar diff --git a/test/core/error-atom-content-byte-value.objtxt b/test/core/error-atom-content-byte-value.objtxt new file mode 100644 index 000000000000..6e675576461a --- /dev/null +++ b/test/core/error-atom-content-byte-value.objtxt @@ -0,0 +1,18 @@ +# RUN: not lld -core %s 2> %t.err +# RUN: FileCheck %s < %t.err + +# +# Test that an invalid hex byte produces a readable error. +# + +--- +defined-atoms: + - name: entry + scope: hidden + content: [ A5, 00, 4G, 1F ] + +... + + +# CHECK: error: invalid two-digit-hex number +# CHECK: 4G diff --git a/test/core/error-atom-content-bytes.objtxt b/test/core/error-atom-content-bytes.objtxt new file mode 100644 index 000000000000..a8a82b2b45e1 --- /dev/null +++ b/test/core/error-atom-content-bytes.objtxt @@ -0,0 +1,19 @@ +# RUN: not lld -core %s 2> %t.err +# RUN: FileCheck %s < %t.err + +# +# Test that an out of range byte value produces a readable error. +# + +--- +defined-atoms: + - name: entry + scope: hidden + content: [ A5, 1234, 00, 4F ] + +... + + +# CHECK: error: out of range two-digit-hex number +# CHECK: 1234 + diff --git a/test/core/error-atom-type.objtxt b/test/core/error-atom-type.objtxt new file mode 100644 index 000000000000..b0943f8e2749 --- /dev/null +++ b/test/core/error-atom-type.objtxt @@ -0,0 +1,19 @@ +# RUN: not lld -core %s 2> %t.err +# RUN: FileCheck %s < %t.err + +# +# Test that an unknown content type produces a readable error. +# + +--- +defined-atoms: + - name: entry + scope: hidden + type: superluminal + dead-strip: never + +... + + +# CHECK: error: unknown enumerated scalar +# CHECK: superluminal diff --git a/test/core/error-atom-undefined-wrong-attribue.objtxt b/test/core/error-atom-undefined-wrong-attribue.objtxt new file mode 100644 index 000000000000..5cdd8519c804 --- /dev/null +++ b/test/core/error-atom-undefined-wrong-attribue.objtxt @@ -0,0 +1,17 @@ +# RUN: not lld -core %s 2> %t.err +# RUN: FileCheck %s < %t.err + +# +# Test that a defined attribute on an undefined atom produces a readable error. +# + +--- +undefined-atoms: + - name: foo + type: code + +... + + +# CHECK: error: unknown key 'type' + diff --git a/test/core/error-duplicate-absolutes.objtxt b/test/core/error-duplicate-absolutes.objtxt new file mode 100644 index 000000000000..533297e59dcd --- /dev/null +++ b/test/core/error-duplicate-absolutes.objtxt @@ -0,0 +1,24 @@ +# RUN: not lld -core %s 2> %t.err +# RUN: FileCheck %s < %t.err + +# +# Test that duplicate absolute atoms produces a readable error. +# + +--- +absolute-atoms: + - name: absatom + value: 0 + scope: global +undefined-atoms: + - name: undefatom +--- +absolute-atoms: + - name: absatom + value: 0 + scope: global +... + + +# CHECK: SymbolTable: error while merging absatom +# CHECK: LLVM ERROR: duplicate symbol error diff --git a/test/core/error-file-attribute.objtxt b/test/core/error-file-attribute.objtxt new file mode 100644 index 000000000000..d8393dc5e400 --- /dev/null +++ b/test/core/error-file-attribute.objtxt @@ -0,0 +1,17 @@ +# RUN: not lld -core %s 2> %t.err +# RUN: FileCheck %s < %t.err + +# +# Test that unknown file attribute produces a readable error. +# + +--- +aardvark: true +defined-atoms: + - name: entry + scope: hidden + +... + + +# CHECK: error: unknown key 'aardvark' diff --git a/test/core/error-fixup-attribute.objtxt b/test/core/error-fixup-attribute.objtxt new file mode 100644 index 000000000000..025783a04427 --- /dev/null +++ b/test/core/error-fixup-attribute.objtxt @@ -0,0 +1,21 @@ +# RUN: not lld -core %s 2> %t.err +# RUN: FileCheck %s < %t.err + +# +# Test that unknown fixup attribute produces a readable error. +# + +--- +defined-atoms: + - name: entry + scope: hidden + references: + - offset: 3 + kind: pcrel32 + weasel: bar + addend: 100 + +... + + +# CHECK: error: unknown key 'weasel' diff --git a/test/core/error-fixup-target.objtxt b/test/core/error-fixup-target.objtxt new file mode 100644 index 000000000000..0e20d1636f50 --- /dev/null +++ b/test/core/error-fixup-target.objtxt @@ -0,0 +1,26 @@ +# RUN: not lld -core %s 2> %t.err +# RUN: FileCheck %s < %t.err + +# +# Test that unbindable target name produces a readable error. +# + +--- +defined-atoms: + - name: entry + scope: hidden + references: + - offset: 3 + kind: pcrel32 + target: bar + - offset: 5 + kind: pcrel32 + target: baz + +undefined-atoms: + - name: bar + +... + + +# CHECK: error: no such atom name: baz diff --git a/test/core/fixups-addend.objtxt b/test/core/fixups-addend.objtxt new file mode 100644 index 000000000000..d976150459c9 --- /dev/null +++ b/test/core/fixups-addend.objtxt @@ -0,0 +1,50 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test addends in references +# + +--- +defined-atoms: + - name: foo + type: code + content: [ 48, 8D, 3D, 00, 00, 00, 00, + 48, 8D, 3D, 00, 00, 00, 00 ] + references: + - offset: 3 + kind: pcrel32 + target: bar + addend: 100 + - offset: 10 + kind: pcrel32 + target: bar + addend: -50 + + - name: func + type: code + content: [ 48, 8D, 3D, 00, 00, 00, 00, + 48, 8D, 3D, 00, 00, 00, 00 ] + references: + - offset: 3 + kind: pcrel32 + target: bar + addend: 8000000000 + - offset: 10 + kind: pcrel32 + target: bar + addend: -50 + +undefined-atoms: + - name: bar + + +... + +# CHECK: name: foo +# CHECK: references: +# CHECK: addend: 100 +# CHECK: addend: -50 +# CHECK: name: func +# CHECK: references: +# CHECK: addend: 8000000000 +# CHECK: addend: -50 diff --git a/test/core/fixups-dup-named.objtxt b/test/core/fixups-dup-named.objtxt new file mode 100644 index 000000000000..1c57cd73bf09 --- /dev/null +++ b/test/core/fixups-dup-named.objtxt @@ -0,0 +1,31 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test references referencing multiple atoms that have the same name +# + +--- +defined-atoms: + - name: foo + type: code + content: [ E8, 00, 00, 00, 00, E8, 00, 00, 00, 00 ] + references: + - offset: 1 + kind: pcrel32 + target: bar_1 + - offset: 6 + kind: pcrel32 + target: bar_2 + + - name: bar + ref-name: bar_1 + scope: static + + - name: bar + ref-name: bar_2 + scope: static + + +... + +# CHECK: ... diff --git a/test/core/fixups-named.objtxt b/test/core/fixups-named.objtxt new file mode 100644 index 000000000000..1427a9b705d1 --- /dev/null +++ b/test/core/fixups-named.objtxt @@ -0,0 +1,36 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test references to simple named atoms +# + +--- +defined-atoms: + - name: foo + type: code + content: [ E8, 00, 00, 00, 00, + E8, 00, 00, 00, 00 ] + references: + - offset: 1 + kind: pcrel32 + target: bar + - offset: 6 + kind: pcrel32 + target: baz + + - name: baz + scope: static + type: code + +undefined-atoms: + - name: bar + + +... + +# CHECK: name: foo +# CHECK: references: +# CHECK: target: bar +# CHECK: target: baz +# CHECK: ... + diff --git a/test/core/fixups-unnamed.objtxt b/test/core/fixups-unnamed.objtxt new file mode 100644 index 000000000000..88afb6a447a2 --- /dev/null +++ b/test/core/fixups-unnamed.objtxt @@ -0,0 +1,40 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test references to unnamed atoms +# + +--- +defined-atoms: + - name: foo + type: code + content: [ 48, 8D, 3D, 00, 00, 00, 00, + 48, 8D, 3D, 00, 00, 00, 00 ] + references: + - offset: 3 + kind: pcrel32 + target: LC1 + - offset: 10 + kind: pcrel32 + target: LC2 + + + - ref-name: LC1 + type: c-string + merge: by-content + content: [ 68, 65, 6c, 6c, 6f, 00 ] + + - ref-name: LC2 + type: c-string + merge: by-content + content: [ 74, 68, 65, 72, 65, 00 ] + + +... + +# CHECK: name: foo +# CHECK: references: +# CHECK: offset: 3 +# CHECK: offset: 10 +# CHECK: ref-name: +# CHECK: ref-name: diff --git a/test/core/gnulinkonce-rearrange-resolve.objtxt b/test/core/gnulinkonce-rearrange-resolve.objtxt new file mode 100644 index 000000000000..2a6386a6935d --- /dev/null +++ b/test/core/gnulinkonce-rearrange-resolve.objtxt @@ -0,0 +1,79 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that gnu linkonce sections are parsed and the first section selected for symbol +# resolution +# + +--- +defined-atoms: + - name: g1 + scope: global + type: gnu-linkonce + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data +--- +defined-atoms: + - name: g1 + scope: global + type: gnu-linkonce + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data +... + +# CHECK: defined-atoms: +# CHECK: - name: g1 +# CHECK: ref-name: [[PARENT:[a-zA-Z\.0-9_]+]] +# CHECK: type: gnu-linkonce +# CHECK: references: +# CHECK: - kind: group-child +# CHECK: target: f1 +# CHECK: - kind: group-child +# CHECK: target: f2 +# CHECK: - kind: group-child +# CHECK: target: [[CHILD:[a-zA-Z\.0-9_]+]] +# CHECK: - kind: group-child +# CHECK: target: d1 +# CHECK: - name: f1 +# CHECK: - name: f2 +# CHECK: - name: g1 +# CHECK: ref-name: [[CHILD]] +# CHECK: - name: d1 diff --git a/test/core/gnulinkonce-remaining-undef.objtxt b/test/core/gnulinkonce-remaining-undef.objtxt new file mode 100644 index 000000000000..490608209ba9 --- /dev/null +++ b/test/core/gnulinkonce-remaining-undef.objtxt @@ -0,0 +1,80 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that gnu linkonce sections are parsed and the first section selected for +# symbol resolution. The second file which has the same gnu linkonce section has +# a unresolved undefined symbol. lets make sure that the symbol is kept around +# in the final link and remains undefined. +# + +--- +defined-atoms: + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: gnu-linkonce + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 +--- +defined-atoms: + - name: anotherfunction + scope: global + type: data + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: f3 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: gnu-linkonce + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: f3 + - kind: group-child + target: g1 + - kind: group-child + target: d1 +--- +undefined-atoms: + - name: f3 + can-be-null: never +... + +#CHECK: - name: anotherfunction +#CHECK: scope: global +#CHECK: type: data +#CHECK: undefined-atoms: +#CHECK: - name: f3 diff --git a/test/core/gnulinkonce-resolve.objtxt b/test/core/gnulinkonce-resolve.objtxt new file mode 100644 index 000000000000..817e9cfdd4e0 --- /dev/null +++ b/test/core/gnulinkonce-resolve.objtxt @@ -0,0 +1,89 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that gnu linkonce sections are parsed and the first section selected for symbol +# resolution +# + +--- +defined-atoms: + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: gnu-linkonce + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 +--- +defined-atoms: + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: gnu-linkonce + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 +... + +#CHECK: defined-atoms: +#CHECK: - name: g1 +#CHECK: ref-name: [[PARENT:[a-zA-Z\.0-9_]+]] +#CHECK: scope: global +#CHECK: type: gnu-linkonce +#CHECK: references: +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: f1 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: f2 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: [[GCHILD:[a-zA-Z\.0-9_]+]] +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: d1 +#CHECK: - name: f1 +#CHECK: scope: global +#CHECK: - name: f2 +#CHECK: scope: global +#CHECK: - name: g1 +#CHECK: ref-name: [[GCHILD]] +#CHECK: scope: global +#CHECK: - name: d1 +#CHECK: scope: global +#CHECK: type: data diff --git a/test/core/gnulinkonce-simple.objtxt b/test/core/gnulinkonce-simple.objtxt new file mode 100644 index 000000000000..da325d48c366 --- /dev/null +++ b/test/core/gnulinkonce-simple.objtxt @@ -0,0 +1,80 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that gnu linkonce sections are parsed properly when there is a reference to a +# atom from outside the gnu linkonce section. +# + +--- +defined-atoms: + - name: f1 + scope: global + type: code + references: + - kind: layout-after + target: anotherfunction + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: gnu-linkonce + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: d1 + - kind: group-child + target: g1 + - name: anotherfunction + scope: global + type: data +--- +undefined-atoms: + - name: f1 + can-be-null: never +... + +#CHECK: defined-atoms: +#CHECK: - name: g1 +#CHECK: ref-name: [[PARENT:[a-zA-Z\.0-9_]+]] +#CHECK: scope: global +#CHECK: type: gnu-linkonce +#CHECK: references: +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: f1 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: f2 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: d1 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: [[GCHILD:[a-zA-Z\.0-9_]+]] +#CHECK: - name: f1 +#CHECK: scope: global +#CHECK: references: +#CHECK: - kind: layout-after +#CHECK: offset: 0 +#CHECK: target: anotherfunction +#CHECK: - name: f2 +#CHECK: scope: global +#CHECK: - name: d1 +#CHECK: scope: global +#CHECK: type: data +#CHECK: - name: g1 +#CHECK: ref-name: [[GCHILD]] +#CHECK: scope: global +#CHECK: - name: anotherfunction +#CHECK: scope: global +#CHECK: type: data diff --git a/test/core/inline-coalesce.objtxt b/test/core/inline-coalesce.objtxt new file mode 100644 index 000000000000..6df9d0e7a49a --- /dev/null +++ b/test/core/inline-coalesce.objtxt @@ -0,0 +1,31 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that non-inlined inlined functions are silently coalesced +# + +--- +defined-atoms: + - name: _inlineFunc + scope: global + type: code + merge: as-weak +--- +defined-atoms: + - name: _inlineFunc + scope: global + type: code + merge: as-weak +--- +defined-atoms: + - name: _inlineFunc + scope: global + type: code + merge: as-weak +... + + +# CHECK: name: _inlineFunc +# CHECK: merge: as-weak +# CHECK-NOT: name: _inlineFunc +# CHECK: ... diff --git a/test/core/multiple-def-error.objtxt b/test/core/multiple-def-error.objtxt new file mode 100644 index 000000000000..7c7732c15fd9 --- /dev/null +++ b/test/core/multiple-def-error.objtxt @@ -0,0 +1,19 @@ +# RUN: not lld -core %s 2>&1 | FileCheck %s + +# +# Test that multiple definitions cause an error +# + +# CHECK: duplicate symbol + +--- +defined-atoms: + - name: _foo + scope: global + type: data +--- +defined-atoms: + - name: _foo + scope: global + type: data +... diff --git a/test/core/permissions.objtxt b/test/core/permissions.objtxt new file mode 100644 index 000000000000..af33ea65c455 --- /dev/null +++ b/test/core/permissions.objtxt @@ -0,0 +1,57 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test permissions for known content types are implicit, but can be overridden. +# +--- +defined-atoms: + - name: one + type: code + + - name: two + type: data + permissions: rw- + + - name: three + type: const-data + + - name: four + type: unknown + + - name: oddCode + type: code + permissions: rwx + + - name: oddData + type: data + permissions: rwx + + - name: oddConstData + type: const-data + permissions: rw- + + - name: oddUnknown + type: unknown + permissions: rw- + +... + +# CHECK: --- +# CHECK: defined-atoms: +# CHECK: - name: one +# CHECK-NOT: permissions: +# CHECK: - name: two +# CHECK-NOT: permissions: +# CHECK: - name: three +# CHECK-NOT: permissions: +# CHECK: - name: four +# CHECK-NOT: permissions: +# CHECK: - name: oddCode +# CHECK: permissions: rwx +# CHECK: - name: oddData +# CHECK: permissions: rwx +# CHECK: - name: oddConstData +# CHECK: permissions: rw- +# CHECK: - name: oddUnknown +# CHECK: permissions: rw- +# CHECK: ... diff --git a/test/core/sectiongroup-deadstrip.objtxt b/test/core/sectiongroup-deadstrip.objtxt new file mode 100644 index 000000000000..8606c52d62e1 --- /dev/null +++ b/test/core/sectiongroup-deadstrip.objtxt @@ -0,0 +1,88 @@ +# Test for section group members be preserved even if there is a +# reference to only one functions in the group. +# RUN: lld -core --dead-strip %s | FileCheck %s + +# +# Test that section groups are parsed properly when there is a reference to a +# group atom from outside a group. +# + +--- +defined-atoms: + - name: entry + dead-strip: never + references: + - offset: 1 + kind: pcrel32 + target: d1 + - name: f1 + scope: global + type: code + references: + - kind: layout-after + target: anotherfunction + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: group-comdat + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: d1 + - kind: group-child + target: g1 + - name: anotherfunction + scope: global + type: data +--- +undefined-atoms: + - name: f1 + can-be-null: never +... + +#CHECK: defined-atoms: +#CHECK: - name: g1 +#CHECK: ref-name: [[PARENT:[a-zA-Z\.0-9_]+]] +#CHECK: scope: global +#CHECK: type: group-comdat +#CHECK: references: +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: f1 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: f2 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: d1 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: [[GCHILD:[a-zA-Z\.0-9_]+]] +#CHECK: - name: f1 +#CHECK: scope: global +#CHECK: references: +#CHECK: - kind: layout-after +#CHECK: offset: 0 +#CHECK: target: anotherfunction +#CHECK: - name: f2 +#CHECK: scope: global +#CHECK: - name: d1 +#CHECK: scope: global +#CHECK: type: data +#CHECK: - name: g1 +#CHECK: ref-name: [[GCHILD]] +#CHECK: scope: global +#CHECK: - name: anotherfunction +#CHECK: scope: global +#CHECK: type: data diff --git a/test/core/sectiongroup-gnulinkonce-error.objtxt b/test/core/sectiongroup-gnulinkonce-error.objtxt new file mode 100644 index 000000000000..47598957f8df --- /dev/null +++ b/test/core/sectiongroup-gnulinkonce-error.objtxt @@ -0,0 +1,64 @@ +# RUN: not lld -core %s 2>&1 | FileCheck %s + +# +# Test that section groups/gnu linkonce sections are parsed and a merge error +# is displayed at the time of symbol resolution. +# + +--- +defined-atoms: + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: group-comdat + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 +--- +defined-atoms: + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: gnu-linkonce + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 +... + +#CHECK: SymbolTable: error while merging g1 +#CHECK: LLVM ERROR: duplicate symbol error + diff --git a/test/core/sectiongroup-rearrange-resolve.objtxt b/test/core/sectiongroup-rearrange-resolve.objtxt new file mode 100644 index 000000000000..7f5d2603775b --- /dev/null +++ b/test/core/sectiongroup-rearrange-resolve.objtxt @@ -0,0 +1,79 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that section groups are parsed and the first group selected for symbol +# resolution +# + +--- +defined-atoms: + - name: g1 + scope: global + type: group-comdat + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data +--- +defined-atoms: + - name: g1 + scope: global + type: group-comdat + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data +... + +# CHECK: defined-atoms: +# CHECK: - name: g1 +# CHECK: ref-name: [[PARENT:[a-zA-Z\.0-9_]+]] +# CHECK: type: group-comdat +# CHECK: references: +# CHECK: - kind: group-child +# CHECK: target: f1 +# CHECK: - kind: group-child +# CHECK: target: f2 +# CHECK: - kind: group-child +# CHECK: target: [[CHILD:[a-zA-Z\.0-9_]+]] +# CHECK: - kind: group-child +# CHECK: target: d1 +# CHECK: - name: f1 +# CHECK: - name: f2 +# CHECK: - name: g1 +# CHECK: ref-name: [[CHILD]] +# CHECK: - name: d1 diff --git a/test/core/sectiongroup-remaining-undef.objtxt b/test/core/sectiongroup-remaining-undef.objtxt new file mode 100644 index 000000000000..7d889b8a4931 --- /dev/null +++ b/test/core/sectiongroup-remaining-undef.objtxt @@ -0,0 +1,80 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that section groups are parsed and the first group selected for symbol +# resolution. The second file which has the same group has a unresolved +# undefined symbol. lets make sure that the symbol is kept around in the final +# link and remains undefined. +# + +--- +defined-atoms: + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: group-comdat + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 +--- +defined-atoms: + - name: anotherfunction + scope: global + type: data + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: f3 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: group-comdat + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: f3 + - kind: group-child + target: g1 + - kind: group-child + target: d1 +--- +undefined-atoms: + - name: f3 + can-be-null: never +... + +#CHECK: - name: anotherfunction +#CHECK: scope: global +#CHECK: type: data +#CHECK: undefined-atoms: +#CHECK: - name: f3 diff --git a/test/core/sectiongroup-resolve.objtxt b/test/core/sectiongroup-resolve.objtxt new file mode 100644 index 000000000000..2d481b1818b2 --- /dev/null +++ b/test/core/sectiongroup-resolve.objtxt @@ -0,0 +1,90 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that section groups are parsed and the first group selected for symbol +# resolution +# + +--- +defined-atoms: + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: group-comdat + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 +--- +defined-atoms: + - name: f1 + scope: global + type: code + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: group-comdat + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: g1 + - kind: group-child + target: d1 +... + +#CHECK: defined-atoms: +#CHECK: - name: g1 +#CHECK: ref-name: [[PARENT:[a-zA-Z\.0-9_]+]] +#CHECK: scope: global +#CHECK: type: group-comdat +#CHECK: references: +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: f1 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: f2 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: [[GCHILD:[a-zA-Z\.0-9_]+]] +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: d1 +#CHECK: - name: f1 +#CHECK: scope: global +#CHECK: - name: f2 +#CHECK: scope: global +#CHECK: - name: g1 +#CHECK: ref-name: [[GCHILD]] +#CHECK: scope: global +#CHECK: - name: d1 +#CHECK: scope: global +#CHECK: type: data +#CHECK: ... diff --git a/test/core/sectiongroup-simple.objtxt b/test/core/sectiongroup-simple.objtxt new file mode 100644 index 000000000000..9f0ff9581c1d --- /dev/null +++ b/test/core/sectiongroup-simple.objtxt @@ -0,0 +1,80 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that section groups are parsed properly when there is a reference to a +# group atom from outside a group. +# + +--- +defined-atoms: + - name: f1 + scope: global + type: code + references: + - kind: layout-after + target: anotherfunction + - name: f2 + scope: global + type: code + - name: g1 + scope: global + type: code + - name: d1 + scope: global + type: data + - name: g1 + scope: global + type: group-comdat + references: + - kind: group-child + target: f1 + - kind: group-child + target: f2 + - kind: group-child + target: d1 + - kind: group-child + target: g1 + - name: anotherfunction + scope: global + type: data +--- +undefined-atoms: + - name: f1 + can-be-null: never +... + +#CHECK: defined-atoms: +#CHECK: - name: g1 +#CHECK: ref-name: [[PARENT:[a-zA-Z\.0-9_]+]] +#CHECK: scope: global +#CHECK: type: group-comdat +#CHECK: references: +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: f1 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: f2 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: d1 +#CHECK: - kind: group-child +#CHECK: offset: 0 +#CHECK: target: [[GCHILD:[a-zA-Z\.0-9_]+]] +#CHECK: - name: f1 +#CHECK: scope: global +#CHECK: references: +#CHECK: - kind: layout-after +#CHECK: offset: 0 +#CHECK: target: anotherfunction +#CHECK: - name: f2 +#CHECK: scope: global +#CHECK: - name: d1 +#CHECK: scope: global +#CHECK: type: data +#CHECK: - name: g1 +#CHECK: ref-name: [[GCHILD]] +#CHECK: scope: global +#CHECK: - name: anotherfunction +#CHECK: scope: global +#CHECK: type: data diff --git a/test/core/shared-library-basic.objtxt b/test/core/shared-library-basic.objtxt new file mode 100644 index 000000000000..61445e7431fd --- /dev/null +++ b/test/core/shared-library-basic.objtxt @@ -0,0 +1,40 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that shared-library symbols are parsed and preserved +# + +--- +shared-library-atoms: + - name: malloc + load-name: libc.so + type: code + size: 0 + + - name: free + load-name: libc.so + + - name: fast_malloc + load-name: libc.so + can-be-null: at-runtime + + - name: stdout + load-name: libc.so + type: data + size: 8 + +... + +# CHECK: shared-library-atoms: +# CHECK: name: malloc +# CHECK: load-name: libc.so +# CHECK: name: free +# CHECK: load-name: libc.so +# CHECK: name: fast_malloc +# CHECK: load-name: libc.so +# CHECK: can-be-null: at-runtime +# CHECK: name: stdout +# CHECK: load-name: libc.so +# CHECK: type: data +# CHECK: size: 8 +# CHECK: ... diff --git a/test/core/shared-library-coalesce.objtxt b/test/core/shared-library-coalesce.objtxt new file mode 100644 index 000000000000..51ff93e87a88 --- /dev/null +++ b/test/core/shared-library-coalesce.objtxt @@ -0,0 +1,84 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that shared library symbols preserve their attributes and merge properly +# + +--- +shared-library-atoms: + - name: foo1 + load-name: libc.so + + - name: foo2 + load-name: libc.so + + - name: bar1 + load-name: libc.so + can-be-null: at-runtime + + - name: bar2 + load-name: libc.so + can-be-null: at-runtime + + - name: mismatchNull1 + load-name: libc.so + can-be-null: at-runtime + + - name: mismatchNull2 + load-name: libc.so + + - name: mismatchload1 + load-name: liba.so + + - name: mismatchload2 + load-name: libb.so + +--- +shared-library-atoms: + - name: foo2 + load-name: libc.so + + - name: foo3 + load-name: libc.so + + - name: bar2 + load-name: libc.so + can-be-null: at-runtime + + - name: bar3 + load-name: libc.so + can-be-null: at-runtime + + - name: mismatchNull1 + load-name: libc.so + + - name: mismatchNull2 + load-name: libc.so + can-be-null: at-runtime + + - name: mismatchload1 + load-name: libb.so + + - name: mismatchload2 + load-name: liba.so + +... + +# CHECK: name: foo1 +# CHECK: name: foo2 +# CHECK: name: bar1 +# CHECK: can-be-null: at-runtime +# CHECK: name: bar2 +# CHECK: can-be-null: at-runtime +# CHECK: name: mismatchNull1 +# CHECK: can-be-null: at-runtime +# CHECK: name: mismatchNull2 +# CHECK-NOT: can-be-null: at-runtime +# CHECK: name: mismatchload1 +# CHECK: load-name: liba.so +# CHECK: name: mismatchload2 +# CHECK: load-name: libb.so +# CHECK: name: foo3 +# CHECK: name: bar3 +# CHECK: can-be-null: at-runtime +# CHECK: ... diff --git a/test/core/tent-merge.objtxt b/test/core/tent-merge.objtxt new file mode 100644 index 000000000000..8ad46d40ae18 --- /dev/null +++ b/test/core/tent-merge.objtxt @@ -0,0 +1,25 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that a tentative definition and a regular global are merged into +# one regular global +# + +--- +defined-atoms: + - name: _foo + merge: as-tentative + scope: global + type: zero-fill + size: 4 +--- +defined-atoms: + - name: _foo + scope: global + type: data + content: [ 00, 00, 00, 00 ] +... + + +# CHECK: name: _foo +# CHECK-NOT: merge: as-tentative diff --git a/test/core/undef-coalesce-error.objtxt b/test/core/undef-coalesce-error.objtxt new file mode 100644 index 000000000000..a0485befd288 --- /dev/null +++ b/test/core/undef-coalesce-error.objtxt @@ -0,0 +1,47 @@ +# RUN: not lld -core --undefines-are-errors %s 2> %t.err +# RUN: FileCheck -check-prefix=CHECKERR %s < %t.err +# RUN: lld -core %s | FileCheck %s + +# +# Test that -undefines-are-errors triggers and error +# and that not using that option results in undefined atoms. +# + +--- +defined-atoms: + - name: foo + type: code + +undefined-atoms: + - name: malloc + - name: free +--- +defined-atoms: + - name: bar + type: code + +undefined-atoms: + - name: malloc + - name: myfunc +--- +defined-atoms: + - name: myfunc + scope: global + type: code + +undefined-atoms: + - name: free +... + +# CHECKERR: free +# CHECKERR: malloc +# CHECKERR: symbol(s) not found + +# CHECK: defined-atoms: +# CHECK: name: foo +# CHECK: name: bar +# CHECK: name: myfunc +# CHECK: undefined-atoms: +# CHECK: name: malloc +# CHECK: name: free +# CHECK: ... diff --git a/test/core/undef-coalesce.objtxt b/test/core/undef-coalesce.objtxt new file mode 100644 index 000000000000..822ed5acf191 --- /dev/null +++ b/test/core/undef-coalesce.objtxt @@ -0,0 +1,42 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that undefined symbols are coalesced with other undefined symbols +# and definitions override them. +# + +--- +defined-atoms: + - name: foo + type: code + +undefined-atoms: + - name: malloc + - name: free +--- +defined-atoms: + - name: bar + type: code + +undefined-atoms: + - name: malloc + - name: myfunc +--- +defined-atoms: + - name: myfunc + scope: global + type: code + +undefined-atoms: + - name: free +... + +# CHECK: defined-atoms: +# CHECK: name: foo +# CHECK: name: bar +# CHECK: name: myfunc +# CHECK: scope: global +# CHECK: undefined-atoms: +# CHECK: name: malloc +# CHECK: name: free +# CHECK: ... diff --git a/test/core/undef-fallback.objtxt b/test/core/undef-fallback.objtxt new file mode 100644 index 000000000000..8abaa93c8e8d --- /dev/null +++ b/test/core/undef-fallback.objtxt @@ -0,0 +1,37 @@ +# RUN: lld -core %s | FileCheck %s + +# Test that fallback atoms can be parsed by YAML reader and processed by the +# core linker. + +--- +defined-atoms: + - name: def1 + scope: global + +undefined-atoms: + - name: undef1 + fallback: + name: fallback1 + - name: undef2 + fallback: + name: fallback2 +--- +defined-atoms: + - name: fallback1 + +undefined-atoms: + - name: def1 + fallback: + name: fallback3 +... + +# CHECK: defined-atoms: +# CHECK-NEXT: - name: def1 +# CHECK-NEXT: scope: global +# CHECK-NEXT: - name: fallback1 +# CHECK-NEXT: ref-name: fallback1 +# CHECK-NEXT: undefined-atoms: +# CHECK-NEXT: - name: fallback1 +# CHECK-NEXT: - name: fallback2 + +# CHECK-NOT: - name: fallback3 diff --git a/test/core/undef-weak-coalesce.objtxt b/test/core/undef-weak-coalesce.objtxt new file mode 100644 index 000000000000..97e0fd28500d --- /dev/null +++ b/test/core/undef-weak-coalesce.objtxt @@ -0,0 +1,72 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that undefined symbols preserve their attributes and merge properly +# + +--- +undefined-atoms: + - name: regular_func + can-be-null: never + - name: weak_import_func + can-be-null: at-runtime + - name: weak_func + can-be-null: at-buildtime + - name: bar1 + can-be-null: never + - name: bar2 + can-be-null: at-runtime + - name: bar3 + can-be-null: at-buildtime + - name: bar4 + can-be-null: never + - name: bar5 + can-be-null: at-runtime + - name: bar6 + can-be-null: at-buildtime + - name: bar7 + can-be-null: never + - name: bar8 + can-be-null: at-runtime + - name: bar9 + can-be-null: at-buildtime +--- +undefined-atoms: + - name: bar1 + can-be-null: never + - name: bar2 + can-be-null: at-runtime + - name: bar3 + can-be-null: at-buildtime + - name: bar4 + can-be-null: at-runtime + - name: bar5 + can-be-null: at-buildtime + - name: bar6 + can-be-null: never + - name: bar7 + can-be-null: at-buildtime + - name: bar8 + can-be-null: never + - name: bar9 + can-be-null: at-runtime +... + +# CHECK: - name: regular_func +# CHECK-NEXT: - name: weak_import_func +# CHECK-NEXT: can-be-null: at-runtime +# CHECK-NEXT: - name: weak_func +# CHECK-NEXT: can-be-null: at-buildtime +# CHECK-NEXT: - name: bar1 +# CHECK-NEXT: - name: bar2 +# CHECK-NEXT: can-be-null: at-runtime +# CHECK-NEXT: - name: bar3 +# CHECK-NEXT: can-be-null: at-buildtime +# CHECK-NEXT: - name: bar4 +# CHECK-NEXT: - name: bar5 +# CHECK-NEXT: can-be-null: at-runtime +# CHECK-NEXT: - name: bar7 +# CHECK-NEXT: - name: bar6 +# CHECK-NEXT: - name: bar8 +# CHECK-NEXT: - name: bar9 +# CHECK-NEXT: can-be-null: at-runtime diff --git a/test/core/weak-coalesce.objtxt b/test/core/weak-coalesce.objtxt new file mode 100644 index 000000000000..550c10cfa468 --- /dev/null +++ b/test/core/weak-coalesce.objtxt @@ -0,0 +1,30 @@ +# RUN: lld -core %s | FileCheck %s + +# +# Test that weak definitions are coalesced away in favor of a regular definition +# + +--- +defined-atoms: + - name: _foo + merge: as-weak + scope: global + type: data +--- +defined-atoms: + - name: _foo + scope: global + type: data +--- +defined-atoms: + - name: _foo + merge: as-weak + scope: global + type: data +... + + +# CHECK: name: _foo +# CHECK-NOT: merge: as-weak +# CHECK-NOT: name: _foo +# CHECK: ... diff --git a/test/darwin/native-and-mach-o.objtxt b/test/darwin/native-and-mach-o.objtxt new file mode 100644 index 000000000000..20f2d0b96207 --- /dev/null +++ b/test/darwin/native-and-mach-o.objtxt @@ -0,0 +1,65 @@ +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t && \ +# RUN: llvm-nm %t | FileCheck %s +# +# Test a mix of atoms and mach-o both encoded in yaml +# + +--- !native +defined-atoms: + - name: _main + type: code + scope: global + content: [ 55, 48, 89, E5, 30, C0, E8, 00, + 00, 00, 00, 31, C0, 5D, C3 ] + references: + - offset: 7 + kind: branch32 + target: _foo + +undefined-atoms: + - name: _foo + + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS ] + address: 0 + content: [ 0xC3 ] +global-symbols: + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ ] + value: 0 + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +flags: [ ] +install-name: /usr/lib/libSystem.B.dylib +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55 ] + +global-symbols: + - name: dyld_stub_binder + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + + +... + +# CHECK: {{[0-9a-f]+}} T _foo +# CHECK: {{[0-9a-f]+}} T _main diff --git a/test/elf/AArch64/Inputs/fn.c b/test/elf/AArch64/Inputs/fn.c new file mode 100644 index 000000000000..54939a2426b2 --- /dev/null +++ b/test/elf/AArch64/Inputs/fn.c @@ -0,0 +1,4 @@ +int fn() +{ + return 0; +} diff --git a/test/elf/AArch64/Inputs/fn.o b/test/elf/AArch64/Inputs/fn.o Binary files differnew file mode 100644 index 000000000000..53e47ad37742 --- /dev/null +++ b/test/elf/AArch64/Inputs/fn.o diff --git a/test/elf/AArch64/Inputs/initfini-option.c b/test/elf/AArch64/Inputs/initfini-option.c new file mode 100644 index 000000000000..6021fb57ffa9 --- /dev/null +++ b/test/elf/AArch64/Inputs/initfini-option.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +void init() { + printf("%s\n", __FUNCTION__); +} + +void fini() { + printf("%s\n", __FUNCTION__); +} + +int main() { +} diff --git a/test/elf/AArch64/Inputs/initfini-option.o b/test/elf/AArch64/Inputs/initfini-option.o Binary files differnew file mode 100644 index 000000000000..c75079b013fa --- /dev/null +++ b/test/elf/AArch64/Inputs/initfini-option.o diff --git a/test/elf/AArch64/Inputs/initfini.c b/test/elf/AArch64/Inputs/initfini.c new file mode 100644 index 000000000000..8369d68a8dab --- /dev/null +++ b/test/elf/AArch64/Inputs/initfini.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +void __attribute__ ((constructor)) constructor() { + printf("%s\n", __FUNCTION__); +} + +void __attribute__ ((destructor)) destructor() { + printf("%s\n", __FUNCTION__); +} + +int main() { + return 0; +} diff --git a/test/elf/AArch64/Inputs/initfini.o b/test/elf/AArch64/Inputs/initfini.o Binary files differnew file mode 100644 index 000000000000..030fe59878be --- /dev/null +++ b/test/elf/AArch64/Inputs/initfini.o diff --git a/test/elf/AArch64/Inputs/main.c b/test/elf/AArch64/Inputs/main.c new file mode 100644 index 000000000000..0280c9127076 --- /dev/null +++ b/test/elf/AArch64/Inputs/main.c @@ -0,0 +1,4 @@ +int main() { + fn(); + return 0; +} diff --git a/test/elf/AArch64/Inputs/main.o b/test/elf/AArch64/Inputs/main.o Binary files differnew file mode 100644 index 000000000000..8c0f049da6a8 --- /dev/null +++ b/test/elf/AArch64/Inputs/main.o diff --git a/test/elf/AArch64/Inputs/no-interp-section.c b/test/elf/AArch64/Inputs/no-interp-section.c new file mode 100644 index 000000000000..3981c038ed33 --- /dev/null +++ b/test/elf/AArch64/Inputs/no-interp-section.c @@ -0,0 +1 @@ +int c = 10; diff --git a/test/elf/AArch64/Inputs/no-interp-section.o b/test/elf/AArch64/Inputs/no-interp-section.o Binary files differnew file mode 100644 index 000000000000..36b41fdbf782 --- /dev/null +++ b/test/elf/AArch64/Inputs/no-interp-section.o diff --git a/test/elf/AArch64/Inputs/zerosizedsection.o b/test/elf/AArch64/Inputs/zerosizedsection.o Binary files differnew file mode 100644 index 000000000000..10123fcef90d --- /dev/null +++ b/test/elf/AArch64/Inputs/zerosizedsection.o diff --git a/test/elf/AArch64/Inputs/zerosizedsection.s b/test/elf/AArch64/Inputs/zerosizedsection.s new file mode 100644 index 000000000000..651ee3aab503 --- /dev/null +++ b/test/elf/AArch64/Inputs/zerosizedsection.s @@ -0,0 +1,3 @@ +.text +.data +.word .text diff --git a/test/elf/AArch64/defsym.test b/test/elf/AArch64/defsym.test new file mode 100644 index 000000000000..8bf492d4a38a --- /dev/null +++ b/test/elf/AArch64/defsym.test @@ -0,0 +1,22 @@ +RUN: lld -flavor gnu -target aarch64--linux-gnu --defsym=main=fn \ +RUN: --noinhibit-exec %p/Inputs/fn.o -o %t +RUN: llvm-readobj -symbols %t | FileCheck %s + +CHECK: Symbol { +CHECK: Name: main (1) +CHECK: Value: 0x4001A4 +CHECK: Size: 0 +CHECK: Binding: Global (0x1) +CHECK: Type: Function (0x2) +CHECK: Other: 0 +CHECK: Section: .text (0x5) +CHECK: } +CHECK: Symbol { +CHECK: Name: fn (11) +CHECK: Value: 0x4001A4 +CHECK: Size: 8 +CHECK: Binding: Global (0x1) +CHECK: Type: Function (0x2) +CHECK: Other: 0 +CHECK: Section: .text (0x5) +CHECK: } diff --git a/test/elf/AArch64/dontignorezerosize-sections.test b/test/elf/AArch64/dontignorezerosize-sections.test new file mode 100644 index 000000000000..ac593abcc368 --- /dev/null +++ b/test/elf/AArch64/dontignorezerosize-sections.test @@ -0,0 +1,9 @@ +# This tests that lld is not ignoring zero sized sections +RUN: lld -flavor gnu -target aarch64--linux-gnu %p/Inputs/zerosizedsection.o \ +RUN: --noinhibit-exec --output-filetype=yaml -o %t +RUN: FileCheck %s < %t + +CHECK: references: +CHECK: - kind: layout-after +CHECK: offset: 0 +CHECK: target: L000 diff --git a/test/elf/AArch64/dynlib-nointerp-section.test b/test/elf/AArch64/dynlib-nointerp-section.test new file mode 100644 index 000000000000..9365b4d5b3e9 --- /dev/null +++ b/test/elf/AArch64/dynlib-nointerp-section.test @@ -0,0 +1,5 @@ +RUN: lld -flavor gnu -target aarch64--linux-gnu %p/Inputs/no-interp-section.o \ +RUN: -o %t -shared +RUN: llvm-objdump -section-headers %t | FileCheck %s + +CHECK-NOT: .interp diff --git a/test/elf/AArch64/initfini.test b/test/elf/AArch64/initfini.test new file mode 100644 index 000000000000..887e44ea105b --- /dev/null +++ b/test/elf/AArch64/initfini.test @@ -0,0 +1,23 @@ +# This tests the functionality that lld is able to read +# init_array/fini_array sections in the input ELF. This +# corresponds to the the .init_array/.fini_array sections +# in the output ELF. + +RUN: lld -flavor gnu -target aarch64--linux-gnu %p/Inputs/initfini.o \ +RUN: --noinhibit-exec --output-filetype=yaml -o %t +RUN: FileCheck %s < %t + +CHECK: type: data +CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +CHECK: section-name: .init_array +CHECK: references: +CHECK: - kind: R_AARCH64_ABS64 +CHECK: offset: 0 +CHECK: target: constructor +CHECK: type: data +CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +CHECK: section-name: .fini_array +CHECK: references: +CHECK: - kind: R_AARCH64_ABS64 +CHECK: offset: 0 +CHECK: target: destructor diff --git a/test/elf/AArch64/rel-abs32-overflow.test b/test/elf/AArch64/rel-abs32-overflow.test new file mode 100644 index 000000000000..e32fce173c51 --- /dev/null +++ b/test/elf/AArch64/rel-abs32-overflow.test @@ -0,0 +1,53 @@ +# Check handling of R_AARCH64_ABS32 relocation overflow. +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: not lld -flavor gnu -target arm64 -o %t-exe %t-obj 2>&1 | FileCheck %s + +# CHECK-DAG: Relocation out of range in file {{.*}}: reference from data1+0 to data2+34359738369 of type 258 (R_AARCH64_ABS32) +# CHECK-DAG: Relocation out of range in file {{.*}}: reference from data2+0 to data1+34359738369 of type 258 (R_AARCH64_ABS32) + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_AARCH64 + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "00000000" + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_EXECINSTR] +- Name: .data + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_WRITE] + +- Name: .rela.data + Type: SHT_RELA + Info: .data + AddressAlign: 8 + Relocations: + - Offset: 0x0 + Symbol: data2 + Type: R_AARCH64_ABS32 + Addend: 0x800000001 + - Offset: 0x4 + Symbol: data1 + Type: R_AARCH64_ABS32 + Addend: 0x800000001 + +Symbols: + Global: + - Name: _start + Section: .text + Value: 0x0 + Size: 4 + - Name: data1 + Section: .data + Size: 4 + - Name: data2 + Section: .data + Value: 0x4 + Size: 4 diff --git a/test/elf/AArch64/rel-abs32.test b/test/elf/AArch64/rel-abs32.test new file mode 100644 index 000000000000..edd7b69e428d --- /dev/null +++ b/test/elf/AArch64/rel-abs32.test @@ -0,0 +1,59 @@ +# Check handling of R_AARCH64_ABS32 relocation. +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target arm64 -o %t-exe %t-obj +# RUN: llvm-objdump -s -t %t-exe | FileCheck %s + +# CHECK: Contents of section .data: +# CHECK-NEXT: 401060 65104080 61104080 e.@.a.@. +# ^^ data2 + 0x80000001 = 0x80401069 +# ^^ data1 + 0x80000001 = 0x80401061 +# CHECK: SYMBOL TABLE: +# CHECK: 00401060 g .data 00000004 data1 +# CHECK: 00401064 g .data 00000004 data2 + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_AARCH64 + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "00000000" + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_EXECINSTR] +- Name: .data + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_WRITE] + +- Name: .rela.data + Type: SHT_RELA + Info: .data + AddressAlign: 8 + Relocations: + - Offset: 0x0 + Symbol: data2 + Type: R_AARCH64_ABS32 + Addend: 0x80000001 + - Offset: 0x4 + Symbol: data1 + Type: R_AARCH64_ABS32 + Addend: 0x80000001 + +Symbols: + Global: + - Name: _start + Section: .text + Value: 0x0 + Size: 4 + - Name: data1 + Section: .data + Size: 4 + - Name: data2 + Section: .data + Value: 0x4 + Size: 4 diff --git a/test/elf/AArch64/rel-abs64.test b/test/elf/AArch64/rel-abs64.test new file mode 100644 index 000000000000..c125e3f2450d --- /dev/null +++ b/test/elf/AArch64/rel-abs64.test @@ -0,0 +1,59 @@ +# Check handling of R_AARCH64_ABS64 relocation. +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target arm64 -o %t-exe %t-obj +# RUN: llvm-objdump -s -t %t-exe | FileCheck %s + +# CHECK: Contents of section .data: +# CHECK-NEXT: 401060 69104000 00000080 61104000 00000080 i.@.....a.@..... +# ^^ data2 + 0x8000000000000001 = 0x8000000000401069 +# ^^ data1 + 0x8000000000000001 = 0x8000000000401061 +# CHECK: SYMBOL TABLE: +# CHECK: 00401060 g .data 00000008 data1 +# CHECK: 00401068 g .data 00000008 data2 + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_AARCH64 + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "00000000" + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_EXECINSTR] +- Name: .data + Type: SHT_PROGBITS + Content: "00000000000000000000000000000000" + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_WRITE] + +- Name: .rela.data + Type: SHT_RELA + Info: .data + AddressAlign: 8 + Relocations: + - Offset: 0x0 + Symbol: data2 + Type: R_AARCH64_ABS64 + Addend: -9223372036854775807 + - Offset: 0x8 + Symbol: data1 + Type: R_AARCH64_ABS64 + Addend: -9223372036854775807 + +Symbols: + Global: + - Name: _start + Section: .text + Value: 0x0 + Size: 4 + - Name: data1 + Section: .data + Size: 8 + - Name: data2 + Section: .data + Value: 0x8 + Size: 8 diff --git a/test/elf/AArch64/rel-bad.test b/test/elf/AArch64/rel-bad.test new file mode 100644 index 000000000000..6b9e831146f3 --- /dev/null +++ b/test/elf/AArch64/rel-bad.test @@ -0,0 +1,44 @@ +# Check handling of a bad relocation (in this case dynamic in a static object). +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: not lld -flavor gnu -target arm64 -o %t-exe %t-obj 2>&1 | FileCheck %s + +# CHECK: Unhandled reference type in file {{.*}}: reference from data1+4 to data1+0 of type 1024 (R_AARCH64_COPY) + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_AARCH64 + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "00000000" + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_EXECINSTR] +- Name: .data + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_WRITE] + +- Name: .rela.data + Type: SHT_RELA + Info: .data + AddressAlign: 8 + Relocations: + - Offset: 0x4 + Symbol: data1 + Type: R_AARCH64_COPY + Addend: 0 + +Symbols: + Global: + - Name: _start + Section: .text + Value: 0x0 + Size: 4 + - Name: data1 + Section: .data + Size: 8 diff --git a/test/elf/ARM/arm-symbols.test b/test/elf/ARM/arm-symbols.test new file mode 100644 index 000000000000..b99960697679 --- /dev/null +++ b/test/elf/ARM/arm-symbols.test @@ -0,0 +1,52 @@ +# Check that symbols formed from ARM instructions are valid: +# 1. Symbol address. +# 2. Symbol content size. +# 3. Symbol content. + +# RUN: yaml2obj -format=elf %s > %t-a.o +# RUN: lld -flavor gnu -target arm-linux-gnu \ +# RUN: -Bstatic --noinhibit-exec %t-a.o -o %t-a +# RUN: llvm-readobj -symbols %t-a | FileCheck -check-prefix=SYM-ADDR %s +# RUN: llvm-readobj -symbols %t-a | FileCheck -check-prefix=SYM-SIZE %s +# RUN: llvm-objdump -s -t %t-a | FileCheck -check-prefix=SYM-CONTENT %s + +# SYM-ADDR: Name: main (1) +# SYM-ADDR-NEXT: Value: 0x400074 + +# SYM-SIZE: Name: main (1) +# SYM-SIZE-NEXT: Value: 0x{{[0-9a-f]+}} +# SYM-SIZE-NEXT: Size: 28 + +# SYM-CONTENT: Contents of section .text: +# SYM-CONTENT-NEXT: 400074 04b02de5 00b08de2 0030a0e3 0300a0e1 ..-......0...... +# SYM-CONTENT-NEXT: 400084 00d04be2 04b09de4 1eff2fe1 ..K......./. + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 04B02DE500B08DE20030A0E30300A0E100D04BE204B09DE41EFF2FE1 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: main + Type: STT_FUNC + Section: .text +... diff --git a/test/elf/ARM/defsym.test b/test/elf/ARM/defsym.test new file mode 100644 index 000000000000..0cd1736d924e --- /dev/null +++ b/test/elf/ARM/defsym.test @@ -0,0 +1,51 @@ +# Check that defined symbols are present in the generated executable + +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm-linux-gnu --defsym=main=fn \ +# RUN: -Bstatic --noinhibit-exec %t-o.o -o %t +# RUN: llvm-readobj -symbols %t | FileCheck %s + +# CHECK: Name: main (1) +# CHECK-NEXT: Value: 0x400074 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text (0x1) +# CHECK: Name: fn (6) +# CHECK-NEXT: Value: 0x400074 +# CHECK-NEXT: Size: {{[0-9]+}} +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text (0x1) + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 04B02DE500B08DE20030A0E30300A0E100D04BE204B09DE41EFF2FE1 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: fn + Type: STT_FUNC + Section: .text +... diff --git a/test/elf/ARM/entry-point.test b/test/elf/ARM/entry-point.test new file mode 100644 index 000000000000..d168bb6463c6 --- /dev/null +++ b/test/elf/ARM/entry-point.test @@ -0,0 +1,77 @@ +# 1. Check entry point address for ARM code - should be even. +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-arm.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-arm.o -o %t-arm +# RUN: llvm-readobj -file-headers %t-arm | FileCheck -check-prefix=ARM-ENTRY %s +# +# ARM-ENTRY: Entry: 0x400074 + +# 2. Check entry point address for Thumb code - should be odd. +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-thm.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-thm.o -o %t-thm +# RUN: llvm-readobj -file-headers %t-thm | FileCheck -check-prefix=THM-ENTRY %s +# +# THM-ENTRY: Entry: 0x400075 + +# arm.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 04B02DE500B08DE20030A0E30300A0E100D04BE204B09DE41EFF2FE1 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: _start + Type: STT_FUNC + Section: .text + +# thm.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 80B400AF00231846BD465DF8047B7047 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: _start + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 +... diff --git a/test/elf/ARM/missing-symbol.test b/test/elf/ARM/missing-symbol.test new file mode 100644 index 000000000000..f9b3e26ea1a3 --- /dev/null +++ b/test/elf/ARM/missing-symbol.test @@ -0,0 +1,39 @@ +# Check that _MISSING_SYMBOL_ symbol is not resolved + +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t 2>&1 | FileCheck %s + +# CHECK: Undefined symbol: {{.*}}: _MISSING_SYMBOL_ + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 80B483B000AF40F20003C0F200037B60002318460C37BD465DF8047B704700BF + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 + - Name: _MISSING_SYMBOL_ +... diff --git a/test/elf/ARM/rel-abs32.test b/test/elf/ARM/rel-abs32.test new file mode 100644 index 000000000000..57d323100feb --- /dev/null +++ b/test/elf/ARM/rel-abs32.test @@ -0,0 +1,59 @@ +# Check handling of R_ARM_ABS32 relocation. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s + +# CHECK: Contents of section .data: +# CHECK-NEXT: 401000 84004000 +# data = 0x400084 ^^ +# data main addr content +# 0x400084 = 0x400074 + 0x10 +# CHECK: SYMBOL TABLE: +# CHECK: 00400074 g F .text {{[0-9a-f]+}} main +# CHECK: 00401000 g .data 00000004 data + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 04B02DE500B08DE20030A0E30300A0E100D04BE204B09DE41EFF2FE1 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '10000000' + - Name: .rel.data + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .data + Relocations: + - Offset: 0x0000000000000000 + Symbol: main + Type: R_ARM_ABS32 + Addend: 0 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x000000000000001C + - Name: data + Type: STT_OBJECT + Section: .data + Size: 0x0000000000000004 +... diff --git a/test/elf/ARM/rel-arm-call.test b/test/elf/ARM/rel-arm-call.test new file mode 100644 index 000000000000..234b34eae92d --- /dev/null +++ b/test/elf/ARM/rel-arm-call.test @@ -0,0 +1,60 @@ +# Check handling of R_ARM_CALL relocation. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK: 400084 1eff2fe1 00482de9 04b08de2 f7ffffeb +# offset = -0x24 ^^ +# call site offset PC(arm) _Z1fv addr +# 0x400090 + (-0x24) + 0x8 = 0x400074 +# CHECK: SYMBOL TABLE: +# CHECK: 00400074 g F .text {{[0-9a-f]+}} _Z1fv +# CHECK: 00400088 g F .text {{[0-9a-f]+}} main + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 04B02DE500B08DE200D04BE204B09DE41EFF2FE100482DE904B08DE2FEFFFFEB0030A0E30300A0E10088BDE8 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x000000000000001C + Symbol: _Z1fv + Type: R_ARM_CALL + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: _Z1fv + Type: STT_FUNC + Section: .text + Size: 0x0000000000000014 + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000000014 + Size: 0x0000000000000018 +... diff --git a/test/elf/ARM/rel-arm-jump24-veneer-b.test b/test/elf/ARM/rel-arm-jump24-veneer-b.test new file mode 100644 index 000000000000..4caeac083b8d --- /dev/null +++ b/test/elf/ARM/rel-arm-jump24-veneer-b.test @@ -0,0 +1,101 @@ +# Check veneer generation for R_ARM_JUMP24 relocation (B instruction call). + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-arm.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-thm.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-arm.o %t-thm.o -o %t + +# RUN: llvm-objdump -s -t %t | FileCheck -check-prefix=B-VENEER %s +# RUN: llvm-objdump -s -t %t | FileCheck -check-prefix=B-ADDR %s + +# B-VENEER: Contents of section .text: +# B-VENEER: 400074 010000ea +# Call from main: +# offset = 0x4 ^^ +# call site offset PC(arm) ___Z1fv_from_arm addr +# 0x400074 + 0x4 + 0x8 = 0x400080 +# +# Code of the veneer: +# B-VENEER: {{[0-9a-f]+}} {{[0-9a-f]+}} 04f01fe5 +# B-VENEER: 400084 79004000 +# call addr = 0x400079 ^^ +# call addr _Z1fv addr Thumb mode +# 0x400079 = 0x400078 | 0x1 +# +# B-ADDR: SYMBOL TABLE: +# B-ADDR: 00400080 l F .text {{[0-9a-f]+}} ___Z1fv_from_arm +# B-ADDR: 00400074 g F .text {{[0-9a-f]+}} main +# B-ADDR: 00400078 g F .text {{[0-9a-f]+}} _Z1fv + +# arm.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: FEFFFFEA + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000000 + Symbol: _Z1fv + Type: R_ARM_JUMP24 + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: main + Type: STT_FUNC + Section: .text + - Name: _Z1fv + +# thm.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 4FF0000318467047 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: _Z1fv + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 +... diff --git a/test/elf/ARM/rel-arm-jump24-veneer-bl.test b/test/elf/ARM/rel-arm-jump24-veneer-bl.test new file mode 100644 index 000000000000..cd386dc5b1a4 --- /dev/null +++ b/test/elf/ARM/rel-arm-jump24-veneer-bl.test @@ -0,0 +1,100 @@ +# Check veneer generation for R_ARM_JUMP24 relocation (BL<c> instruction call). + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-arm.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-thm.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-arm.o %t-thm.o -o %t + +# RUN: llvm-objdump -s -t %t | FileCheck -check-prefix=BL-VENEER %s +# RUN: llvm-objdump -s -t %t | FileCheck -check-prefix=BL-ADDR %s + +# BL-VENEER: Contents of section .text: +# BL-VENEER: 400084 0400000b +# Call from main: +# offset = 0x10 ^^ +# call site offset PC(arm) ___Z1fv_from_arm addr +# 0x400084 + 0x10 + 0x8 = 0x40009c +# +# Code of the veneer: +# BL-VENEER: 400094 {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} 95004000 +# call addr = 0x400095 ^^ +# call addr _Z1fv addr Thumb mode +# 0x400095 = 0x400094 | 0x1 +# +# BL-ADDR: SYMBOL TABLE: +# BL-ADDR: 0040009c l F .text {{[0-9a-f]+}} ___Z1fv_from_arm +# BL-ADDR: 00400074 g F .text {{[0-9a-f]+}} main +# BL-ADDR: 00400094 g F .text {{[0-9a-f]+}} _Z1fv + +# arm.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 00482DE904B08DE20030A0E3000053E3FEFFFF0B0030A0E30300A0E10088BDE8 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000010 + Symbol: _Z1fv + Type: R_ARM_JUMP24 + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: main + Type: STT_FUNC + Section: .text + - Name: _Z1fv + +# thm.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 4FF0000318467047 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: _Z1fv + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 +... diff --git a/test/elf/ARM/rel-arm-jump24.test b/test/elf/ARM/rel-arm-jump24.test new file mode 100644 index 000000000000..18eb8397d7b5 --- /dev/null +++ b/test/elf/ARM/rel-arm-jump24.test @@ -0,0 +1,58 @@ +# Check handling of R_ARM_JUMP24 relocation. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK: 400094 04b08de2 f5ffffea 0030a0e1 0300a0e1 +# offset = -0x2C ^^ +# call site offset PC(arm) _Z1fv addr +# 0x400098 + (-0x2C) + 0x8 = 0x400074 +# CHECK: SYMBOL TABLE: +# CHECK: 00400074 g F .text {{[0-9a-f]+}} _Z1fv +# CHECK: 00400090 g F .text {{[0-9a-f]+}} main + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 04B02DE500B08DE20030A0E30300A0E100D04BE204B09DE41EFF2FE100482DE904B08DE2FEFFFFEA0030A0E10300A0E10088BDE8 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000024 + Symbol: _Z1fv + Type: R_ARM_JUMP24 + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: _Z1fv + Type: STT_FUNC + Section: .text + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x000000000000001C +... diff --git a/test/elf/ARM/rel-arm-mov.test b/test/elf/ARM/rel-arm-mov.test new file mode 100644 index 000000000000..e50aea4bb206 --- /dev/null +++ b/test/elf/ARM/rel-arm-mov.test @@ -0,0 +1,64 @@ +# Check handling of R_ARM_MOVW_ABS_NC and R_ARM_MOVT_ABS relocation pair. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK: 400074 04b02de5 00b08de2 003001e3 403040e3 +# addrL = 0x1000 ^^ +# addrH = 0x40 ^^ +# addrH addrL _ZL5data1 addr +# (0x40 << 16) + 0x1000 = 0x401000 +# CHECK: SYMBOL TABLE: +# CHECK: 00401000 l .bss 00000004 _ZL5data1 +# CHECK: 00400074 g F .text {{[0-9a-f]+}} main + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 04B02DE500B08DE2003000E3003040E30A20A0E3002083E50030A0E30300A0E100D04BE204B09DE41EFF2FE1 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000008 + Symbol: _ZL5data1 + Type: R_ARM_MOVW_ABS_NC + Addend: 0 + - Offset: 0x000000000000000C + Symbol: _ZL5data1 + Type: R_ARM_MOVT_ABS + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: 411C0000 +Symbols: + Local: + - Name: _ZL5data1 + Type: STT_OBJECT + Section: .bss + Size: 0x0000000000000004 + Global: + - Name: main + Type: STT_FUNC + Section: .text +... diff --git a/test/elf/ARM/rel-arm-prel31.test b/test/elf/ARM/rel-arm-prel31.test new file mode 100644 index 000000000000..1effc4eceb0e --- /dev/null +++ b/test/elf/ARM/rel-arm-prel31.test @@ -0,0 +1,47 @@ +# Check handling of R_ARM_PREL31 relocation. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s + +# CHECK: Contents of section .ARM.extab: +# CHECK: 4000a4 b1fffe7f +# CHECK: SYMBOL TABLE: +# CHECK: 00400054 g F .text {{[0-9a-f]+}} __gxx_personality_v0 + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .ARM.extab + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x4 + Content: 0000FF7F84019701B0B0B008FFFF01080E2432003A040000 + - Name: .rel.ARM.extab + Type: SHT_REL + Link: .symtab + AddressAlign: 0x4 + Info: .ARM.extab + Relocations: + - Offset: 0 + Symbol: __gxx_personality_v0 + Type: R_ARM_PREL31 + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x4 + Content: 80B400AF00231846BD465DF8047B704780B582B000AF3B1D1846FFF7FEFFFFF7FEFFFFF7FEFF0420FFF7FEFF0346184601230360002240F20001C0F20001FFF7FEFF3B1D1846FFF7FEFFFFF7FEFF00BF +Symbols: + Local: + Global: + - Name: __gxx_personality_v0 + Type: STT_FUNC + Section: .text + Value: 0x1 +... + diff --git a/test/elf/ARM/rel-arm-thm-interwork.test b/test/elf/ARM/rel-arm-thm-interwork.test new file mode 100644 index 000000000000..8ee9186b48db --- /dev/null +++ b/test/elf/ARM/rel-arm-thm-interwork.test @@ -0,0 +1,123 @@ +# Check ARM <=> Thumb interwork. +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-arm.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-thm.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-arm.o %t-thm.o -o %t + +# Check R_ARM_CALL veneer to call Thumb code +# RUN: llvm-objdump -s -t %t | FileCheck -check-prefix=ARM-CALL %s + +# ARM-CALL: Contents of section .text: +# ARM-CALL: 400074 00482de9 04b08de2 000000fa 0088bde8 +# offset = 0x0 ^^ +# call site offset PC(arm) _Z2f2v addr +# 0x40007C + 0x0 + 0x8 = 0x400084 +# ARM-CALL: SYMBOL TABLE: +# ARM-CALL: 00400074 g F .text {{[0-9a-f]+}} _Z1fv +# ARM-CALL: 00400084 g F .text {{[0-9a-f]+}} _Z2f2v +# ARM-CALL: 00400090 g F .text {{[0-9a-f]+}} main + +# Check R_ARM_THM_CALL veneer to call ARM code +# RUN: llvm-objdump -s -t %t | FileCheck -check-prefix=THM-CALL %s + +# THM-CALL: Contents of section .text: +# THM-CALL: 400094 00bffff7 eeef0023 184680bd +# offset = -0x24 ^^ +# call site aligned = Align(0x400096, 4) = 0x400094 +# call site aligned offset PC(thm) _Z1fv addr +# 0x400094 + (-0x24) + 0x4 = 0x400074 +# THM-CALL: SYMBOL TABLE: +# THM-CALL: 00400074 g F .text {{[0-9a-f]+}} _Z1fv +# THM-CALL: 00400084 g F .text {{[0-9a-f]+}} _Z2f2v +# THM-CALL: 00400090 g F .text {{[0-9a-f]+}} main + +# arm.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 00482DE904B08DE2FEFFFFEB0088BDE8 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000008 + Symbol: _Z2f2v + Type: R_ARM_CALL + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: _Z1fv + Type: STT_FUNC + Section: .text + Size: 0x0000000000000010 + - Name: _Z2f2v + +# thm.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 80B400AFBD465DF8047B704780B500AF00BFFFF7FEFF0023184680BD + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000012 + Symbol: _Z1fv + Type: R_ARM_THM_CALL + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: _Z2f2v + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 + Size: 0x000000000000000C + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x000000000000000D + Size: 0x0000000000000010 + - Name: _Z1fv +... diff --git a/test/elf/ARM/rel-rel32.test b/test/elf/ARM/rel-rel32.test new file mode 100644 index 000000000000..47779ac918e3 --- /dev/null +++ b/test/elf/ARM/rel-rel32.test @@ -0,0 +1,57 @@ +# Check handling of R_ARM_REL32 relocation. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 400074 {{[0-9a-f]+}} 880fff00 +# CHECK: SYMBOL TABLE: +# CHECK: 00400074 g F .text {{[0-9a-f]+}} main +# CHECK: 00401000 g .bss {{[0-9a-f]+}} _myref + +--- +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 80B400AF0000FF0000231846BD465DF8047B7047 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000004 + Symbol: _myref + Type: R_ARM_REL32 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' +Symbols: + Global: + - Name: _myref + Type: STT_OBJECT + Section: .bss + Size: 0x0000000000000004 + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 + Size: 0x0000000000000014 +... diff --git a/test/elf/ARM/rel-thm-call.test b/test/elf/ARM/rel-thm-call.test new file mode 100644 index 000000000000..b9bf8cefc0b8 --- /dev/null +++ b/test/elf/ARM/rel-thm-call.test @@ -0,0 +1,61 @@ +# Check handling of R_ARM_THM_CALL relocation. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK: 400084 fff7f6ff 00231846 80bd00bf +# ^^ offset = -0x14 +# call site offset PC(thm) _Z1fv addr +# 0x400084 + (-0x14) + 0x4 = 0x400074 +# CHECK: SYMBOL TABLE: +# CHECK: 00400074 g F .text {{[0-9a-f]+}} _Z1fv +# CHECK: 00400080 g F .text {{[0-9a-f]+}} main + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 80B400AFBD465DF8047B704780B500AFFFF7FEFF0023184680BD00BF + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000010 + Symbol: _Z1fv + Type: R_ARM_THM_CALL + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: _Z1fv + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 + Size: 0x000000000000000C + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x000000000000000D + Size: 0x000000000000000E +... diff --git a/test/elf/ARM/rel-thm-jump11.test b/test/elf/ARM/rel-thm-jump11.test new file mode 100644 index 000000000000..4998c2b96c97 --- /dev/null +++ b/test/elf/ARM/rel-thm-jump11.test @@ -0,0 +1,141 @@ +# Check handling of R_ARM_THM_JUMP11 relocation. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK: 4001a4 0021c7e7 +# CHECK: SYMBOL TABLE: +# CHECK: 00400138 g F .text 00000060 __gnu_h2f_internal +# CHECK: 004001a4 g F .text 00000004 __gnu_h2f_alternative + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 70B4020CC0F3C754FF2CC0F3160302F4004080B241D0002C08BF002B3BD0A4F17F0543F4000315F10E0FA8BF41F6FF7209DA15F1190FA3BFA4F166066FF07F42F2406FF07F4212EA03060CD001325208964208BF03EA42021344B3F1807F24BF5B08A4F17E0501B30F2D26DC15F1180F11DB15F10E0FB5BF4FF6F2710E35CFF6FF71AD02B7BF491BAAB2CB40002202EB5333034398B270BC70470029FBD040EA533370BC43F4FC407047102DDEDD6FEAD0336FEAC33398B2EDE740F4F84398B2E9E700BFC0F3842310B4A3F11F040029B4FA84F400F400424FEA541408BF0024C0F309002146140481B943B14203703302EBC35343EA04005DF8044B704760B1B0FA80F3153B98405B42EFE744EA40305DF8044B40F0FF40704720465DF8044B704700BF01216BE70121FEE7002167E70021FEE7 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x000000000000012A + Symbol: __gnu_h2f_internal + Type: R_ARM_THM_JUMP11 + - Offset: 0x0000000000000132 + Symbol: __gnu_h2f_internal + Type: R_ARM_THM_JUMP11 + - Name: .text.startup + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 0020FFF7FEBF00BF + - Name: .rel.text.startup + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text.startup + Relocations: + - Offset: 0x0000000000000002 + Symbol: __gnu_h2f_alternative + Type: R_ARM_THM_JUMP24 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 004743433A202863726F7373746F6F6C2D4E47206C696E61726F2D312E31332E312D342E392D323031342E3039202D204C696E61726F2047434320342E392D323031342E30392920342E392E32203230313430393034202870726572656C656173652900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .ARM.attributes + Type: SHT_ARM_ATTRIBUTES + AddressAlign: 0x0000000000000001 + Content: 4134000000616561626900012A00000005372D4100060A0741080109020A041204140115011703180119011A021B031C011E022201 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .text.startup + Type: STT_SECTION + Section: .text.startup + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .ARM.attributes + Type: STT_SECTION + Section: .ARM.attributes + - Name: '$t' + Section: .text + - Name: __gnu_f2h_internal + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 + Size: 0x00000000000000C2 + Global: + - Name: __gnu_f2h_alternative + Type: STT_FUNC + Section: .text + Value: 0x000000000000012D + Size: 0x0000000000000004 + Visibility: STV_HIDDEN + - Name: __gnu_h2f_alternative + Type: STT_FUNC + Section: .text + Value: 0x0000000000000131 + Size: 0x0000000000000004 + Visibility: STV_HIDDEN + - Name: __gnu_h2f_ieee + Type: STT_FUNC + Section: .text + Value: 0x0000000000000129 + Size: 0x0000000000000004 + Visibility: STV_HIDDEN + - Name: main + Type: STT_FUNC + Section: .text.startup + Value: 0x0000000000000001 + Size: 0x0000000000000006 + - Name: __gnu_f2h_ieee + Type: STT_FUNC + Section: .text + Value: 0x0000000000000125 + Size: 0x0000000000000004 + Visibility: STV_HIDDEN + - Name: __gnu_h2f_internal + Type: STT_FUNC + Section: .text + Value: 0x00000000000000C5 + Size: 0x000000000000005E + Visibility: STV_HIDDEN +... diff --git a/test/elf/ARM/rel-thm-jump24-veneer.test b/test/elf/ARM/rel-thm-jump24-veneer.test new file mode 100644 index 000000000000..fffce44ca477 --- /dev/null +++ b/test/elf/ARM/rel-thm-jump24-veneer.test @@ -0,0 +1,100 @@ +# Check veneer generation for R_ARM_THM_JUMP24 relocation (B instruction call). + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-arm.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-thm.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-arm.o %t-thm.o -o %t + +# RUN: llvm-objdump -s -t %t | FileCheck -check-prefix=B-VENEER %s +# RUN: llvm-objdump -s -t %t | FileCheck -check-prefix=B-ADDR %s + +# B-VENEER: Contents of section .text: +# B-VENEER: 400074 {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} 00f000b8 +# Call from main: +# offset = 0x0 ^^ +# call site offset PC(thm) ___Z1fv_from_thumb addr +# 0x400080 + 0x0 + 0x4 = 0x400084 +# +# Code of the veneer: +# B-VENEER: 400084 78470000 f9ffffea +# offset = -0x1C ^^ +# call site offset PC(arm) _Z1fv +# 0x400088 + (-0x1C) + 0x8 = 0x400074 +# +# B-ADDR: SYMBOL TABLE: +# B-ADDR: 00400084 l F .text {{[0-9a-f]+}} ___Z1fv_from_thumb +# B-ADDR: 00400074 g F .text {{[0-9a-f]+}} _Z1fv +# B-ADDR: 00400080 g F .text {{[0-9a-f]+}} main + +# arm.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 0030A0E30300A0E11EFF2FE1 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: _Z1fv + Type: STT_FUNC + Section: .text + +# thm.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: FFF7FEBF + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000000 + Symbol: _Z1fv + Type: R_ARM_THM_JUMP24 + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 + - Name: _Z1fv +... diff --git a/test/elf/ARM/rel-thm-jump24.test b/test/elf/ARM/rel-thm-jump24.test new file mode 100644 index 000000000000..6c9b63447c9d --- /dev/null +++ b/test/elf/ARM/rel-thm-jump24.test @@ -0,0 +1,59 @@ +# Check handling of R_ARM_THM_JUMP24 relocation. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK: 400084 80b500af fff7f4bf 03461846 80bd00bf +# ^^ offset = -0x18 +# call site offset PC(thm) _Z1fv addr +# 0x400088 + (-0x18) + 0x4 = 0x400074 +# CHECK: SYMBOL TABLE: +# CHECK: 00400074 g F .text {{[0-9a-f]+}} _Z1fv +# CHECK: 00400084 g F .text {{[0-9a-f]+}} main + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 80B400AF00231846BD465DF8047B704780B500AFFFF7FEBF0346184680BD00BF + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000014 + Symbol: _Z1fv + Type: R_ARM_THM_JUMP24 + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: _Z1fv + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000000011 +... diff --git a/test/elf/ARM/rel-thm-mov.test b/test/elf/ARM/rel-thm-mov.test new file mode 100644 index 000000000000..25edc4cda4b9 --- /dev/null +++ b/test/elf/ARM/rel-thm-mov.test @@ -0,0 +1,70 @@ +# 1. Check handling of R_ARM_THM_MOVW_ABS_NC and R_THM_ARM_MOVT_ABS relocation pair. +# 2. Check that instructions are not cropped for symbols that address Thumb code. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s +# RUN: llvm-objdump -s -t %t | FileCheck -check-prefix=INSN-CROP %s + +# CHECK: Contents of section .text: +# CHECK: 400074 {{[0-9a-f]+}} 41f20003 c0f24003 0a221a60 +# addrL = 0x1000 ^^ +# addrH = 0x40 ^^ +# addrH addrL _ZL5data1 addr +# (0x40 << 16) + 0x1000 = 0x401000 +# CHECK: SYMBOL TABLE: +# CHECK: 00401000 l .bss 00000004 _ZL5data1 +# CHECK: 00400074 g F .text {{[0-9a-f]+}} main +# +# INSN-CROP: Contents of section .text: +# INSN-CROP: 400074 80b400af + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 80B400AF40F20003C0F200030A221A6000231846BD465DF8047B7047 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000004 + Symbol: _ZL5data1 + Type: R_ARM_THM_MOVW_ABS_NC + Addend: 0 + - Offset: 0x0000000000000008 + Symbol: _ZL5data1 + Type: R_ARM_THM_MOVT_ABS + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: 411C0000 +Symbols: + Local: + - Name: _ZL5data1 + Type: STT_OBJECT + Section: .bss + Size: 0x0000000000000004 + Global: + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 +... diff --git a/test/elf/ARM/rel-tls-ie32.test b/test/elf/ARM/rel-tls-ie32.test new file mode 100644 index 000000000000..7b65c2f194c7 --- /dev/null +++ b/test/elf/ARM/rel-tls-ie32.test @@ -0,0 +1,109 @@ +# Check handling of R_ARM_TLS_IE32 relocation. +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-tls.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-tlsv.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-tls.o %t-tlsv.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s + +# CHECK: Contents of section .got: +# CHECK: 401008 08000000 0c000000 +# tp_off(i) = 0x08 ^^ ^^ tp_off(j) = 0x0c +# tp_off(i) + sizeof(i) = tp_off(j) +# 0x08 + 0x04 = 0x0c +# CHECK: SYMBOL TABLE: +# CHECK: 00400094 g F .text {{[0-9a-f]+}} main +# CHECK: 00000000 g .tdata 00000004 i +# sizeof(i) = 0x04 ^^ +# CHECK: 00000004 g .tdata 00000004 j + +# tls.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 80B400AF0C4B7B441B681DEE702FD2580A4B7B441B681DEE701FCB581A44084B7B441B681DEE701FCB585B0013441846BD465DF8047B70472E000000260000001C000000 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000038 + Symbol: i + Type: R_ARM_TLS_IE32 + - Offset: 0x000000000000003C + Symbol: i + Type: R_ARM_TLS_IE32 + - Offset: 0x0000000000000040 + Symbol: j + Type: R_ARM_TLS_IE32 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 + - Name: i + Type: STT_TLS + - Name: j + Type: STT_TLS + +# tlsv.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x0000000000000004 + Content: 05000000FBFFFFFF +Symbols: + Global: + - Name: i + Type: STT_TLS + Section: .tdata + Size: 0x0000000000000004 + - Name: j + Type: STT_TLS + Section: .tdata + Value: 0x0000000000000004 + Size: 0x0000000000000004 +... diff --git a/test/elf/ARM/rel-tls-le32.test b/test/elf/ARM/rel-tls-le32.test new file mode 100644 index 000000000000..d0d3d5b6821a --- /dev/null +++ b/test/elf/ARM/rel-tls-le32.test @@ -0,0 +1,61 @@ +# Check handling of R_ARM_TLS_LE32 relocation. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -s -t %t | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK: 4000b4 {{[0-9a-f]+}} 08000000 +# tp_off = 0x000008 ^^ +# CHECK: SYMBOL TABLE: +# CHECK: 00400094 g F .text {{[0-9a-f]+}} main +# CHECK: 00000000 g .tdata 00000004 i + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 04B02DE500B08DE2703F1DEE10209FE5023093E70300A0E100D04BE204B09DE41EFF2FE100000000 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000024 + Symbol: i + Type: R_ARM_TLS_LE32 + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x0000000000000004 + Content: '05000000' +Symbols: + Global: + - Name: i + Type: STT_TLS + Section: .tdata + Size: 0x0000000000000004 + - Name: main + Type: STT_FUNC + Section: .text +... diff --git a/test/elf/ARM/thm-symbols.test b/test/elf/ARM/thm-symbols.test new file mode 100644 index 000000000000..c91505c98100 --- /dev/null +++ b/test/elf/ARM/thm-symbols.test @@ -0,0 +1,52 @@ +# Check that symbols formed from Thumb instructions are valid: +# 1. Symbol address. +# 2. Symbol content size. +# 3. Symbol content. + +# RUN: yaml2obj -format=elf %s > %t-t.o +# RUN: lld -flavor gnu -target arm-linux-gnu \ +# RUN: -Bstatic --noinhibit-exec %t-t.o -o %t-t +# RUN: llvm-readobj -symbols %t-t | FileCheck -check-prefix=SYM-ADDR %s +# RUN: llvm-readobj -symbols %t-t | FileCheck -check-prefix=SYM-SIZE %s +# RUN: llvm-objdump -s -t %t-t | FileCheck -check-prefix=SYM-CONTENT %s + +# SYM-ADDR: Name: main (1) +# SYM-ADDR-NEXT: Value: 0x400075 + +# SYM-SIZE: Name: main (1) +# SYM-SIZE-NEXT: Value: 0x{{[0-9a-f]+}} +# SYM-SIZE-NEXT: Size: 16 + +# SYM-CONTENT: Contents of section .text: +# SYM-CONTENT-NEXT: 400074 80b400af 00231846 bd465df8 047b7047 .....#.F.F]..{pG + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 80B400AF00231846BD465DF8047B7047 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 +... diff --git a/test/elf/ARM/undef-lazy-symbol.test b/test/elf/ARM/undef-lazy-symbol.test new file mode 100644 index 000000000000..f32549e85be4 --- /dev/null +++ b/test/elf/ARM/undef-lazy-symbol.test @@ -0,0 +1,135 @@ +# Check that _GLOBAL_OFFSET_TABLE_ symbol is resolved + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-got.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-got.o -o %t +# RUN: llvm-readobj -symbols %t | FileCheck -check-prefix=GOT %s + +# GOT: Name: _GLOBAL_OFFSET_TABLE_ (185) +# GOT-NEXT: Value: {{[0-9]+}} +# GOT-NEXT: Size: 0 +# GOT-NEXT: Binding: Global (0x1) +# GOT-NEXT: Type: Object (0x1) +# GOT-NEXT: Other: 0 +# GOT-NEXT: Section: Absolute (0xFFF1) + +# Check that __exidx_start/_end symbols are resolved + +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-exidx.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --defsym=main=fn --noinhibit-exec %t-exidx.o -o %t +# RUN: llvm-readobj -symbols %t | FileCheck -check-prefix=EXIDX %s + +# EXIDX: Name: __exidx_start (188) +# EXIDX-NEXT: Value: {{[0-9]+}} +# EXIDX-NEXT: Size: 0 +# EXIDX-NEXT: Binding: Global (0x1) +# EXIDX-NEXT: Type: Object (0x1) +# EXIDX-NEXT: Other: 0 +# EXIDX-NEXT: Section: Absolute (0xFFF1) +# +# EXIDX: Name: __exidx_end (202) +# EXIDX-NEXT: Value: {{[0-9]+}} +# EXIDX-NEXT: Size: 0 +# EXIDX-NEXT: Binding: Global (0x1) +# EXIDX-NEXT: Type: Object (0x1) +# EXIDX-NEXT: Other: 0 +# EXIDX-NEXT: Section: Absolute (0xFFF1) + +# Check that all symbols are resolved + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-got.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-exidx.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \ +# RUN: --noinhibit-exec %t-got.o %t-exidx.o -o %t +# RUN: llvm-readobj -symbols %t | FileCheck -check-prefix=SYMS %s + +# SYMS: Name: _GLOBAL_OFFSET_TABLE_ (188) +# SYMS-NEXT: Value: {{[0-9]+}} +# SYMS-NEXT: Size: 0 +# SYMS-NEXT: Binding: Global (0x1) +# SYMS-NEXT: Type: Object (0x1) +# SYMS-NEXT: Other: 0 +# SYMS-NEXT: Section: Absolute (0xFFF1) +# +# SYMS: Name: __exidx_start (210) +# SYMS-NEXT: Value: {{[0-9]+}} +# SYMS-NEXT: Size: 0 +# SYMS-NEXT: Binding: Global (0x1) +# SYMS-NEXT: Type: Object (0x1) +# SYMS-NEXT: Other: 0 +# SYMS-NEXT: Section: Absolute (0xFFF1) +# +# SYMS: Name: __exidx_end (224) +# SYMS-NEXT: Value: {{[0-9]+}} +# SYMS-NEXT: Size: 0 +# SYMS-NEXT: Binding: Global (0x1) +# SYMS-NEXT: Type: Object (0x1) +# SYMS-NEXT: Other: 0 +# SYMS-NEXT: Section: Absolute (0xFFF1) + +# got.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 80B483B000AF40F20003C0F200037B60002318460C37BD465DF8047B704700BF + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 + - Name: _GLOBAL_OFFSET_TABLE_ + +# exidx.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM + Flags: [ EF_ARM_EABI_VER5 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 80B483B000AF40F20003C0F200037B60002318460C37BD465DF8047B704700BF + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Global: + - Name: fn + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 + - Name: __exidx_start + - Name: __exidx_end +... diff --git a/test/elf/Hexagon/Inputs/dynobj-data.c b/test/elf/Hexagon/Inputs/dynobj-data.c new file mode 100644 index 000000000000..0f4ea9b80526 --- /dev/null +++ b/test/elf/Hexagon/Inputs/dynobj-data.c @@ -0,0 +1,3 @@ +int d = 10; + +int fn() { return d; } diff --git a/test/elf/Hexagon/Inputs/dynobj-data.o b/test/elf/Hexagon/Inputs/dynobj-data.o Binary files differnew file mode 100644 index 000000000000..13d283cd0eff --- /dev/null +++ b/test/elf/Hexagon/Inputs/dynobj-data.o diff --git a/test/elf/Hexagon/Inputs/dynobj.c b/test/elf/Hexagon/Inputs/dynobj.c new file mode 100644 index 000000000000..f17fdadd6945 --- /dev/null +++ b/test/elf/Hexagon/Inputs/dynobj.c @@ -0,0 +1,26 @@ +extern int shankar; +static int a; +static int b; +int c; +int fn2() { + return 0; +} + +int fn1() { + return 0; +} + +int fn() { + a = 10; + b = 20; + c = 10; + shankar = 20; + return 0; +} + +int fn3() { + fn(); + fn1(); + fn2(); + return 0; +} diff --git a/test/elf/Hexagon/Inputs/dynobj.o b/test/elf/Hexagon/Inputs/dynobj.o Binary files differnew file mode 100644 index 000000000000..6c184f2edd60 --- /dev/null +++ b/test/elf/Hexagon/Inputs/dynobj.o diff --git a/test/elf/Hexagon/Inputs/got-plt-order.c b/test/elf/Hexagon/Inputs/got-plt-order.c new file mode 100644 index 000000000000..621f670ef7c5 --- /dev/null +++ b/test/elf/Hexagon/Inputs/got-plt-order.c @@ -0,0 +1,6 @@ +int c = 10; +int fn() { c = 20; return 0; } + +int fn1() { + return fn(); +} diff --git a/test/elf/Hexagon/Inputs/got-plt-order.o b/test/elf/Hexagon/Inputs/got-plt-order.o Binary files differnew file mode 100644 index 000000000000..e97678b739bd --- /dev/null +++ b/test/elf/Hexagon/Inputs/got-plt-order.o diff --git a/test/elf/Hexagon/Inputs/libMaxAlignment.a b/test/elf/Hexagon/Inputs/libMaxAlignment.a Binary files differnew file mode 100644 index 000000000000..cc5461a09ae4 --- /dev/null +++ b/test/elf/Hexagon/Inputs/libMaxAlignment.a diff --git a/test/elf/Hexagon/Inputs/sda-base.o b/test/elf/Hexagon/Inputs/sda-base.o Binary files differnew file mode 100644 index 000000000000..410a3d47d320 --- /dev/null +++ b/test/elf/Hexagon/Inputs/sda-base.o diff --git a/test/elf/Hexagon/Inputs/sdata1.c b/test/elf/Hexagon/Inputs/sdata1.c new file mode 100644 index 000000000000..77c2a54c36a1 --- /dev/null +++ b/test/elf/Hexagon/Inputs/sdata1.c @@ -0,0 +1,3 @@ +static int a = 0; + +int b = 10; diff --git a/test/elf/Hexagon/Inputs/sdata1.o b/test/elf/Hexagon/Inputs/sdata1.o Binary files differnew file mode 100644 index 000000000000..bf908fed27e9 --- /dev/null +++ b/test/elf/Hexagon/Inputs/sdata1.o diff --git a/test/elf/Hexagon/Inputs/sdata2.c b/test/elf/Hexagon/Inputs/sdata2.c new file mode 100644 index 000000000000..96b37271d773 --- /dev/null +++ b/test/elf/Hexagon/Inputs/sdata2.c @@ -0,0 +1,6 @@ +int sdata1 = 10; +int sdata2 = 20; +int sdata3 = 30; + +int sbss1 = 0; + diff --git a/test/elf/Hexagon/Inputs/sdata2.o b/test/elf/Hexagon/Inputs/sdata2.o Binary files differnew file mode 100644 index 000000000000..e4ec810866e5 --- /dev/null +++ b/test/elf/Hexagon/Inputs/sdata2.o diff --git a/test/elf/Hexagon/Inputs/use-shared.hexagon b/test/elf/Hexagon/Inputs/use-shared.hexagon Binary files differnew file mode 100644 index 000000000000..9e5ffb42d36a --- /dev/null +++ b/test/elf/Hexagon/Inputs/use-shared.hexagon diff --git a/test/elf/Hexagon/dynlib-data.test b/test/elf/Hexagon/dynlib-data.test new file mode 100644 index 000000000000..f3260ba4847b --- /dev/null +++ b/test/elf/Hexagon/dynlib-data.test @@ -0,0 +1,9 @@ +RUN: lld -flavor gnu -target hexagon %p/Inputs/dynobj-data.o \ +RUN: -o %t --noinhibit-exec -shared +RUN: llvm-objdump -s %t > %t1 +RUN: FileCheck -check-prefix=CHECKRELOCS %s < %t1 + +CHECKRELOCS: Contents of section .text: +CHECKRELOCS: 00f8 01c09da0 01d89da1 3c400000 18c4496a ........<@....Ij +CHECKRELOCS: 0108 ff7fff0f 00ff9897 00c08091 38c09d91 ............8... +CHECKRELOCS: 0118 1ec01e96 .... diff --git a/test/elf/Hexagon/dynlib-gotoff.test b/test/elf/Hexagon/dynlib-gotoff.test new file mode 100644 index 000000000000..752d3acd4c08 --- /dev/null +++ b/test/elf/Hexagon/dynlib-gotoff.test @@ -0,0 +1,128 @@ +# This tests GOT's and PLT's for dynamic libraries for Hexagon +RUN: lld -flavor gnu -target hexagon %p/Inputs/dynobj.o \ +RUN: -o %t --output-filetype=yaml -shared --noinhibit-exec +RUN: FileCheck -check-prefix=CHECKGOTPLT %s < %t + + - 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 +CHECKGOTPLT: addend: 4 + - 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, +CHECKGOTPLT: 00, 00, 00, 00 ] +CHECKGOTPLT: alignment: 2^3 +CHECKGOTPLT: section-name: .got.plt +CHECKGOTPLT: permissions: rw- + - name: __got_c +CHECKGOTPLT: type: got +CHECKGOTPLT: content: [ 00, 00, 00, 00 ] +CHECKGOTPLT: alignment: 2^2 +CHECKGOTPLT: section-name: .got +CHECKGOTPLT: permissions: rw- +CHECKGOTPLT: references: +CHECKGOTPLT: - kind: R_HEX_GLOB_DAT +CHECKGOTPLT: offset: 0 +CHECKGOTPLT: target: c + - name: __got_shankar +CHECKGOTPLT: type: got +CHECKGOTPLT: content: [ 00, 00, 00, 00 ] +CHECKGOTPLT: alignment: 2^2 +CHECKGOTPLT: section-name: .got +CHECKGOTPLT: permissions: rw- +CHECKGOTPLT: references: +CHECKGOTPLT: - kind: R_HEX_GLOB_DAT +CHECKGOTPLT: offset: 0 +CHECKGOTPLT: target: shankar + - name: __got_fn +CHECKGOTPLT: type: got +CHECKGOTPLT: content: [ 00, 00, 00, 00 ] +CHECKGOTPLT: alignment: 2^2 +CHECKGOTPLT: section-name: .got.plt +CHECKGOTPLT: permissions: rw- +CHECKGOTPLT: references: +CHECKGOTPLT: - kind: R_HEX_JMP_SLOT +CHECKGOTPLT: offset: 0 +CHECKGOTPLT: target: fn +CHECKGOTPLT: - kind: R_HEX_32 +CHECKGOTPLT: offset: 0 + target: .PLT0 + - name: __got_fn1 +CHECKGOTPLT: type: got +CHECKGOTPLT: content: [ 00, 00, 00, 00 ] +CHECKGOTPLT: alignment: 2^2 +CHECKGOTPLT: section-name: .got.plt +CHECKGOTPLT: permissions: rw- +CHECKGOTPLT: references: +CHECKGOTPLT: - kind: R_HEX_JMP_SLOT +CHECKGOTPLT: offset: 0 +CHECKGOTPLT: target: fn1 +CHECKGOTPLT: - kind: R_HEX_32 +CHECKGOTPLT: offset: 0 + target: .PLT0 + - name: __got_fn2 +CHECKGOTPLT: type: got +CHECKGOTPLT: content: [ 00, 00, 00, 00 ] +CHECKGOTPLT: alignment: 2^2 +CHECKGOTPLT: section-name: .got.plt +CHECKGOTPLT: permissions: rw- +CHECKGOTPLT: references: +CHECKGOTPLT: - kind: R_HEX_JMP_SLOT +CHECKGOTPLT: offset: 0 +CHECKGOTPLT: target: fn2 +CHECKGOTPLT: - kind: R_HEX_32 +CHECKGOTPLT: offset: 0 + target: .PLT0 diff --git a/test/elf/Hexagon/dynlib-hash.test b/test/elf/Hexagon/dynlib-hash.test new file mode 100644 index 000000000000..f93176492348 --- /dev/null +++ b/test/elf/Hexagon/dynlib-hash.test @@ -0,0 +1,9 @@ +RUN: lld -flavor gnu -target hexagon %p/Inputs/dynobj.o \ +RUN: -o %t --noinhibit-exec -shared +RUN: llvm-objdump -s %t > %t1 +RUN: FileCheck -check-prefix=CHECKHASH %s < %t1 + +CHECKHASH: Contents of section .hash: +CHECKHASH: 0094 03000000 07000000 06000000 01000000 +CHECKHASH: 00a4 04000000 00000000 00000000 00000000 +CHECKHASH: 00b4 00000000 03000000 02000000 05000000 diff --git a/test/elf/Hexagon/dynlib-rela.test b/test/elf/Hexagon/dynlib-rela.test new file mode 100644 index 000000000000..81617349e2f7 --- /dev/null +++ b/test/elf/Hexagon/dynlib-rela.test @@ -0,0 +1,9 @@ +# Tests that the relocation sections have the right alignment. +RUN: lld -flavor gnu -target hexagon %p/Inputs/use-shared.hexagon -shared -o %t1 +RUN: llvm-readobj -sections %t1 > %t2 +RUN: FileCheck -check-prefix=SECTIONS %s < %t2 + +SECTIONS: Section { +SECTIONS: Name: .rela.plt (23) +SECTIONS: AddressAlignment: 4 +SECTIONS: } diff --git a/test/elf/Hexagon/dynlib-syms.test b/test/elf/Hexagon/dynlib-syms.test new file mode 100644 index 000000000000..e649230d9e90 --- /dev/null +++ b/test/elf/Hexagon/dynlib-syms.test @@ -0,0 +1,7 @@ +RUN: lld -flavor gnu -target hexagon %p/Inputs/dynobj.o \ +RUN: -o %t --noinhibit-exec -shared +RUN: llvm-nm -n -M %t > %t1 +RUN: FileCheck -check-prefix=CHECKSYMS %s < %t1 + +CHECKSYMS: 0000025c A _DYNAMIC +CHECKSYMS: 00001008 A _GLOBAL_OFFSET_TABLE_ diff --git a/test/elf/Hexagon/dynlib.test b/test/elf/Hexagon/dynlib.test new file mode 100644 index 000000000000..c5bf23fdf229 --- /dev/null +++ b/test/elf/Hexagon/dynlib.test @@ -0,0 +1,36 @@ +RUN: lld -flavor gnu -target hexagon %p/Inputs/use-shared.hexagon -shared -o %t1 +RUN: llvm-readobj -dyn-symbols %t1 > %t2 +RUN: FileCheck -check-prefix=DYNSYMS %s < %t2 +RUN: llvm-readobj -program-headers %t1 | FileCheck %s + +DYNSYMS: DynamicSymbols [ +DYNSYMS: Symbol { +DYNSYMS: Name: fn2 +DYNSYMS-NEXT: Value: +DYNSYMS-NEXT: Size: +DYNSYMS-NEXT: Binding: Global +DYNSYMS-NEXT: Type: Function +DYNSYMS-NEXT: Other: +DYNSYMS-NEXT: Section: .text +DYNSYMS: } +DYNSYMS: Symbol { +DYNSYMS: Name: fn1 +DYNSYMS-NEXT: Value: +DYNSYMS-NEXT: Size: +DYNSYMS-NEXT: Binding: Global +DYNSYMS-NEXT: Type: Function +DYNSYMS-NEXT: Other: +DYNSYMS-NEXT: Section: .text +DYNSYMS: } +DYNSYMS: Symbol { +DYNSYMS: Name: fn3 +DYNSYMS-NEXT: Value: +DYNSYMS-NEXT: Size: +DYNSYMS-NEXT: Binding: Global +DYNSYMS-NEXT: Type: Function +DYNSYMS-NEXT: Other: +DYNSYMS-NEXT: Section: .text +DYNSYMS-NEXT: } +DYNSYMS-NEXT: ] + +CHECK-NOT: PT_PHDR diff --git a/test/elf/Hexagon/hexagon-got-plt-order.test b/test/elf/Hexagon/hexagon-got-plt-order.test new file mode 100644 index 000000000000..7600ebe59fc5 --- /dev/null +++ b/test/elf/Hexagon/hexagon-got-plt-order.test @@ -0,0 +1,5 @@ +RUN: lld -flavor gnu -target hexagon %p/Inputs/got-plt-order.o -o %t -shared +RUN: llvm-objdump -section-headers %t | FileCheck %s + +CHECK: .got +CHECK-NEXT: .got.plt diff --git a/test/elf/Hexagon/hexagon-plt-setup.test b/test/elf/Hexagon/hexagon-plt-setup.test new file mode 100644 index 000000000000..15c4e22ed9c5 --- /dev/null +++ b/test/elf/Hexagon/hexagon-plt-setup.test @@ -0,0 +1,12 @@ +RUN: lld -flavor gnu -target hexagon %p/Inputs/use-shared.hexagon \ +RUN: --output-filetype=yaml --noinhibit-exec -o %t2 +RUN: FileCheck %s < %t2 + +CHECK: - name: fn3 +CHECK: references: +CHECK: - kind: R_HEX_B22_PCREL +CHECK: offset: 4 + target: +CHECK: - kind: R_HEX_B22_PCREL +CHECK: offset: 8 + target: diff --git a/test/elf/Hexagon/maxalignment.test b/test/elf/Hexagon/maxalignment.test new file mode 100644 index 000000000000..cac1c200734f --- /dev/null +++ b/test/elf/Hexagon/maxalignment.test @@ -0,0 +1,8 @@ +# This tests that we lld is able to get the contentType properly for archives +# when they intermittently get loaded at an address whose alignment is 2 + +RUN: lld -flavor gnu -target hexagon --whole-archive %p/Inputs/libMaxAlignment.a \ +RUN: --noinhibit-exec -static -o %t +RUN: llvm-nm %t | FileCheck %s + +CHECK: {{[0-9a-f]+}} D a diff --git a/test/elf/Hexagon/rela-order.test b/test/elf/Hexagon/rela-order.test new file mode 100644 index 000000000000..925a82c29290 --- /dev/null +++ b/test/elf/Hexagon/rela-order.test @@ -0,0 +1,9 @@ +RUN: lld -flavor gnu -target hexagon %p/Inputs/dynobj.o -shared \ +RUN: --noinhibit-exec -o %t +RUN: llvm-objdump -section-headers %t | FileCheck %s + +CHECK: .dynsym +CHECK-NEXT: .dynstr +CHECK-NEXT: .rela.dyn +CHECK-NEXT: .rela.plt +CHECK-NEXT: .plt diff --git a/test/elf/Hexagon/sda-base.test b/test/elf/Hexagon/sda-base.test new file mode 100644 index 000000000000..0bab92abf685 --- /dev/null +++ b/test/elf/Hexagon/sda-base.test @@ -0,0 +1,4 @@ +RUN: lld -flavor gnu -target hexagon %p/Inputs/sda-base.o -o %t1 --noinhibit-exec +RUN: llvm-nm -n %t1 | FileCheck %s -check-prefix=sdabase + +sdabase: 00002000 A _SDA_BASE_ diff --git a/test/elf/Hexagon/zerofillquick-sdata.test b/test/elf/Hexagon/zerofillquick-sdata.test new file mode 100644 index 000000000000..5488e19f5c44 --- /dev/null +++ b/test/elf/Hexagon/zerofillquick-sdata.test @@ -0,0 +1,18 @@ +# This tests that a typeZeroFillFast atom is associated with a section that has +# the correct memory size. + +RUN: lld -flavor gnu -target hexagon %p/Inputs/sdata1.o %p/Inputs/sdata2.o \ +RUN: -o %t --noinhibit-exec -static +RUN: llvm-readobj -sections %t | FileCheck -check-prefix=CHECKSECTIONSANDSIZE %s + +CHECKSECTIONSANDSIZE: Section { +CHECKSECTIONSANDSIZE: Name: .sdata (13) +CHECKSECTIONSANDSIZE: Address: 0x1000 +CHECKSECTIONSANDSIZE: Offset: 0x1000 +CHECKSECTIONSANDSIZE: Size: 24 +CHECKSECTIONSANDSIZE: } +CHECKSECTIONSANDSIZE: Section { +CHECKSECTIONSANDSIZE: Name: .bss (20) +CHECKSECTIONSANDSIZE: Address: 0x1018 +CHECKSECTIONSANDSIZE: Offset: 0x1018 +CHECKSECTIONSANDSIZE: } diff --git a/test/elf/Inputs/abs-test.i386 b/test/elf/Inputs/abs-test.i386 Binary files differnew file mode 100644 index 000000000000..8556c24da551 --- /dev/null +++ b/test/elf/Inputs/abs-test.i386 diff --git a/test/elf/Inputs/bar.o.x86-64 b/test/elf/Inputs/bar.o.x86-64 Binary files differnew file mode 100644 index 000000000000..467485f0bb96 --- /dev/null +++ b/test/elf/Inputs/bar.o.x86-64 diff --git a/test/elf/Inputs/branch-test.hexagon b/test/elf/Inputs/branch-test.hexagon Binary files differnew file mode 100644 index 000000000000..1ffb47228e32 --- /dev/null +++ b/test/elf/Inputs/branch-test.hexagon diff --git a/test/elf/Inputs/branch-test.ppc b/test/elf/Inputs/branch-test.ppc Binary files differnew file mode 100644 index 000000000000..4698941e7503 --- /dev/null +++ b/test/elf/Inputs/branch-test.ppc diff --git a/test/elf/Inputs/consecutive-weak-defs.o.yaml b/test/elf/Inputs/consecutive-weak-defs.o.yaml new file mode 100644 index 000000000000..144c2426bae1 --- /dev/null +++ b/test/elf/Inputs/consecutive-weak-defs.o.yaml @@ -0,0 +1,66 @@ +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 554889E5E8000000005DC3554889E5B8640000005DC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000005 + Symbol: my_weak_func + Type: R_X86_64_PC32 + Addend: -4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: my_func + Type: STT_FUNC + Section: .text + Size: 0x000000000000000B + Weak: + - Name: my_weak_func + Type: STT_FUNC + Section: .text + Value: 0x000000000000000B + Size: 0x000000000000000B + - Name: my_weak_func2 + Type: STT_FUNC + Section: .text + Value: 0x000000000000000B + Size: 0x000000000000000B + - Name: my_weak_func3 + Type: STT_FUNC + Section: .text + Value: 0x000000000000000B + Size: 0x000000000000000B +... diff --git a/test/elf/Inputs/constants-merge.x86-64 b/test/elf/Inputs/constants-merge.x86-64 Binary files differnew file mode 100644 index 000000000000..0087eb8f8cb5 --- /dev/null +++ b/test/elf/Inputs/constants-merge.x86-64 diff --git a/test/elf/Inputs/constdata.x86-64 b/test/elf/Inputs/constdata.x86-64 Binary files differnew file mode 100644 index 000000000000..d877a5535357 --- /dev/null +++ b/test/elf/Inputs/constdata.x86-64 diff --git a/test/elf/Inputs/foo.o.x86-64 b/test/elf/Inputs/foo.o.x86-64 Binary files differnew file mode 100644 index 000000000000..72a89eefa8ed --- /dev/null +++ b/test/elf/Inputs/foo.o.x86-64 diff --git a/test/elf/Inputs/globalconst.c b/test/elf/Inputs/globalconst.c new file mode 100644 index 000000000000..08395a88e7ca --- /dev/null +++ b/test/elf/Inputs/globalconst.c @@ -0,0 +1,2 @@ +/* compile the code with -fmerge-all-constants */ +const char mystr[] = "foobar"; diff --git a/test/elf/Inputs/globalconst.o.x86-64 b/test/elf/Inputs/globalconst.o.x86-64 Binary files differnew file mode 100644 index 000000000000..d8e266e76334 --- /dev/null +++ b/test/elf/Inputs/globalconst.o.x86-64 diff --git a/test/elf/Inputs/gotpcrel.S b/test/elf/Inputs/gotpcrel.S new file mode 100644 index 000000000000..300675f59612 --- /dev/null +++ b/test/elf/Inputs/gotpcrel.S @@ -0,0 +1,11 @@ + .text + .globl main + .align 16, 0x90 + .type main,@function +main: # @main + movq blah@GOTPCREL(%rip), %rax + movq main@GOTPCREL(%rip), %rax + ret + + .weak blah + .type blah,@function diff --git a/test/elf/Inputs/gotpcrel.x86-64 b/test/elf/Inputs/gotpcrel.x86-64 Binary files differnew file mode 100644 index 000000000000..f9c61d0edf15 --- /dev/null +++ b/test/elf/Inputs/gotpcrel.x86-64 diff --git a/test/elf/Inputs/group-cmd-search-1.ls b/test/elf/Inputs/group-cmd-search-1.ls new file mode 100644 index 000000000000..965369309a20 --- /dev/null +++ b/test/elf/Inputs/group-cmd-search-1.ls @@ -0,0 +1 @@ +GROUP ( shared.so-x86-64 ) diff --git a/test/elf/Inputs/group-cmd-search-2.ls b/test/elf/Inputs/group-cmd-search-2.ls new file mode 100644 index 000000000000..f1eee6a35efa --- /dev/null +++ b/test/elf/Inputs/group-cmd-search-2.ls @@ -0,0 +1 @@ +GROUP ( /shared.so-x86-64 ) diff --git a/test/elf/Inputs/group-cmd-search-3.ls b/test/elf/Inputs/group-cmd-search-3.ls new file mode 100644 index 000000000000..83ce0ca62fb1 --- /dev/null +++ b/test/elf/Inputs/group-cmd-search-3.ls @@ -0,0 +1 @@ +GROUP ( -l:shared.so-x86-64 -lfnarchive ) diff --git a/test/elf/Inputs/ifunc.S b/test/elf/Inputs/ifunc.S new file mode 100644 index 000000000000..0ac1f5a5b0bb --- /dev/null +++ b/test/elf/Inputs/ifunc.S @@ -0,0 +1,21 @@ + .text + .globl hey; + .type hey, @function; +hey: + .type hey, @gnu_indirect_function; + leaq __hey_1(%rip), %rax + ret + + .text + .type __hey_1, @function; + .globl __hey_1; +__hey_1: + movq $42, %rax + ret + + .text + .type plt, @function; + .globl plt; +plt: + call hey@PLT + ret diff --git a/test/elf/Inputs/ifunc.cpp b/test/elf/Inputs/ifunc.cpp new file mode 100644 index 000000000000..2e520277d36c --- /dev/null +++ b/test/elf/Inputs/ifunc.cpp @@ -0,0 +1,3 @@ +extern "C" int hey(); + +int main() { return hey(); } diff --git a/test/elf/Inputs/ifunc.cpp.x86-64 b/test/elf/Inputs/ifunc.cpp.x86-64 Binary files differnew file mode 100644 index 000000000000..20c812cabd2c --- /dev/null +++ b/test/elf/Inputs/ifunc.cpp.x86-64 diff --git a/test/elf/Inputs/ifunc.x86-64 b/test/elf/Inputs/ifunc.x86-64 Binary files differnew file mode 100644 index 000000000000..36c8e04ca837 --- /dev/null +++ b/test/elf/Inputs/ifunc.x86-64 diff --git a/test/elf/Inputs/init_array.x86-64 b/test/elf/Inputs/init_array.x86-64 Binary files differnew file mode 100644 index 000000000000..2425c227fd42 --- /dev/null +++ b/test/elf/Inputs/init_array.x86-64 diff --git a/test/elf/Inputs/libfnarchive.a b/test/elf/Inputs/libfnarchive.a Binary files differnew file mode 100644 index 000000000000..753acd6e2c65 --- /dev/null +++ b/test/elf/Inputs/libfnarchive.a diff --git a/test/elf/Inputs/libifunc.x86-64.so b/test/elf/Inputs/libifunc.x86-64.so Binary files differnew file mode 100644 index 000000000000..0f05b308ce78 --- /dev/null +++ b/test/elf/Inputs/libifunc.x86-64.so diff --git a/test/elf/Inputs/libundef.so b/test/elf/Inputs/libundef.so Binary files differnew file mode 100644 index 000000000000..41f2a668f360 --- /dev/null +++ b/test/elf/Inputs/libundef.so diff --git a/test/elf/Inputs/libweaksym.so b/test/elf/Inputs/libweaksym.so Binary files differnew file mode 100755 index 000000000000..7ff4ea56ae60 --- /dev/null +++ b/test/elf/Inputs/libweaksym.so diff --git a/test/elf/Inputs/main-with-global-def.o.yaml b/test/elf/Inputs/main-with-global-def.o.yaml new file mode 100644 index 000000000000..55029614e1e8 --- /dev/null +++ b/test/elf/Inputs/main-with-global-def.o.yaml @@ -0,0 +1,56 @@ +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 554889E5B8C80000005DC3554889E54883EC10C745FC00000000B000E8000000004883C4105DC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x000000000000001D + Symbol: my_func + Type: R_X86_64_PC32 + Addend: -4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x000000000000000B + Size: 0x000000000000001C + - Name: my_weak_func2 + Type: STT_FUNC + Section: .text + Size: 0x000000000000000B + - Name: my_func +... diff --git a/test/elf/Inputs/mainobj.x86_64 b/test/elf/Inputs/mainobj.x86_64 Binary files differnew file mode 100644 index 000000000000..d0f29418237d --- /dev/null +++ b/test/elf/Inputs/mainobj.x86_64 diff --git a/test/elf/Inputs/object-test.elf-hexagon b/test/elf/Inputs/object-test.elf-hexagon Binary files differnew file mode 100644 index 000000000000..bfc85a7d0b76 --- /dev/null +++ b/test/elf/Inputs/object-test.elf-hexagon diff --git a/test/elf/Inputs/object-test.elf-i386 b/test/elf/Inputs/object-test.elf-i386 Binary files differnew file mode 100644 index 000000000000..872684c7fcc1 --- /dev/null +++ b/test/elf/Inputs/object-test.elf-i386 diff --git a/test/elf/Inputs/phdr.i386 b/test/elf/Inputs/phdr.i386 Binary files differnew file mode 100644 index 000000000000..7c83dd314891 --- /dev/null +++ b/test/elf/Inputs/phdr.i386 diff --git a/test/elf/Inputs/quickdata-sort-test.o.elf-hexagon b/test/elf/Inputs/quickdata-sort-test.o.elf-hexagon Binary files differnew file mode 100644 index 000000000000..03d028707129 --- /dev/null +++ b/test/elf/Inputs/quickdata-sort-test.o.elf-hexagon diff --git a/test/elf/Inputs/quickdata-sortcommon-test.o.elf-hexagon b/test/elf/Inputs/quickdata-sortcommon-test.o.elf-hexagon Binary files differnew file mode 100644 index 000000000000..410a3d47d320 --- /dev/null +++ b/test/elf/Inputs/quickdata-sortcommon-test.o.elf-hexagon diff --git a/test/elf/Inputs/quickdata-test.elf-hexagon b/test/elf/Inputs/quickdata-test.elf-hexagon Binary files differnew file mode 100644 index 000000000000..c3ae53a6babe --- /dev/null +++ b/test/elf/Inputs/quickdata-test.elf-hexagon diff --git a/test/elf/Inputs/reloc-test.elf-i386 b/test/elf/Inputs/reloc-test.elf-i386 Binary files differnew file mode 100644 index 000000000000..1a5558131fff --- /dev/null +++ b/test/elf/Inputs/reloc-test.elf-i386 diff --git a/test/elf/Inputs/reloc-xb.x86 b/test/elf/Inputs/reloc-xb.x86 Binary files differnew file mode 100644 index 000000000000..4d9770aa2356 --- /dev/null +++ b/test/elf/Inputs/reloc-xb.x86 diff --git a/test/elf/Inputs/reloc-xt.x86 b/test/elf/Inputs/reloc-xt.x86 Binary files differnew file mode 100644 index 000000000000..dcdfbfb09f71 --- /dev/null +++ b/test/elf/Inputs/reloc-xt.x86 diff --git a/test/elf/Inputs/relocs-dynamic.x86-64 b/test/elf/Inputs/relocs-dynamic.x86-64 Binary files differnew file mode 100644 index 000000000000..0c44924d18e6 --- /dev/null +++ b/test/elf/Inputs/relocs-dynamic.x86-64 diff --git a/test/elf/Inputs/relocs.x86-64 b/test/elf/Inputs/relocs.x86-64 Binary files differnew file mode 100644 index 000000000000..112dfa733db9 --- /dev/null +++ b/test/elf/Inputs/relocs.x86-64 diff --git a/test/elf/Inputs/responsefile b/test/elf/Inputs/responsefile new file mode 100644 index 000000000000..2fe657a0e3b0 --- /dev/null +++ b/test/elf/Inputs/responsefile @@ -0,0 +1 @@ +--inresponsefile diff --git a/test/elf/Inputs/rodata-test.hexagon b/test/elf/Inputs/rodata-test.hexagon Binary files differnew file mode 100644 index 000000000000..f448748e2abe --- /dev/null +++ b/test/elf/Inputs/rodata-test.hexagon diff --git a/test/elf/Inputs/rodata-test.i386 b/test/elf/Inputs/rodata-test.i386 Binary files differnew file mode 100644 index 000000000000..09f71eb59969 --- /dev/null +++ b/test/elf/Inputs/rodata-test.i386 diff --git a/test/elf/Inputs/rodata.c b/test/elf/Inputs/rodata.c new file mode 100644 index 000000000000..b43c9c945898 --- /dev/null +++ b/test/elf/Inputs/rodata.c @@ -0,0 +1,4 @@ +const unsigned char *str = "llvm"; +int foo() { + return str[0]; +} diff --git a/test/elf/Inputs/rodata.o b/test/elf/Inputs/rodata.o Binary files differnew file mode 100644 index 000000000000..f13ddc9bba98 --- /dev/null +++ b/test/elf/Inputs/rodata.o diff --git a/test/elf/Inputs/section-test.i386 b/test/elf/Inputs/section-test.i386 Binary files differnew file mode 100644 index 000000000000..2b447a9f8f5b --- /dev/null +++ b/test/elf/Inputs/section-test.i386 diff --git a/test/elf/Inputs/shared.c b/test/elf/Inputs/shared.c new file mode 100644 index 000000000000..2be91c4b9e45 --- /dev/null +++ b/test/elf/Inputs/shared.c @@ -0,0 +1,16 @@ +#include <stdio.h> + +extern int i; +int i = 42; + +// Undefined weak function in a dynamic library. +__attribute__((weak)) void weakfoo(); + +// Regular function in a dynamic library. +void foo() { + // Try to call weakfoo so that the reference to weekfoo will be included in + // the resulting .so file. + if (weakfoo) + weakfoo(); + puts("Fooo!!"); +} diff --git a/test/elf/Inputs/shared.so-x86-64 b/test/elf/Inputs/shared.so-x86-64 Binary files differnew file mode 100644 index 000000000000..0240f0e67431 --- /dev/null +++ b/test/elf/Inputs/shared.so-x86-64 diff --git a/test/elf/Inputs/stripped-empty.x86_64 b/test/elf/Inputs/stripped-empty.x86_64 Binary files differnew file mode 100644 index 000000000000..7368ba280d79 --- /dev/null +++ b/test/elf/Inputs/stripped-empty.x86_64 diff --git a/test/elf/Inputs/target-test.hexagon b/test/elf/Inputs/target-test.hexagon Binary files differnew file mode 100644 index 000000000000..7da114561920 --- /dev/null +++ b/test/elf/Inputs/target-test.hexagon diff --git a/test/elf/Inputs/target-test.ppc b/test/elf/Inputs/target-test.ppc Binary files differnew file mode 100644 index 000000000000..001be338c20d --- /dev/null +++ b/test/elf/Inputs/target-test.ppc diff --git a/test/elf/Inputs/tls.S b/test/elf/Inputs/tls.S new file mode 100644 index 000000000000..7d9eab647b53 --- /dev/null +++ b/test/elf/Inputs/tls.S @@ -0,0 +1,50 @@ + .text + .globl main + .align 16, 0x90 + .type main,@function +main: # @main + callq GOTTPOFF + addl %fs:tls1@TPOFF, %eax + addl %fs:tls0@TPOFF, %eax + addl %fs:tls2@TPOFF, %eax + ret + + .text + .globl GOTTPOFF + .type GOTTPOFF,@function +GOTTPOFF: + movq tls2@GOTTPOFF(%rip), %rax + movl %fs:0(%rax), %eax + ret + + .text + .globl TLSLD + .type TLSLD,@function +TLSLD: + leaq tls0@tlsld(%rip), %rdi + call __tls_get_addr@plt + leaq tls0@dtpoff(%rax), %rax + ret + + .type tls0,@object # @tls0 + .section .tbss,"awT",@nobits + .globl tls0 + .align 4 +tls0: + .long 0 # 0x0 + .size tls0, 4 + + .type tls1,@object # @tls1 + .globl tls1 + .align 4 +tls1: + .long 0 # 0x0 + .size tls1, 4 + + .type tls2,@object # @tls2 + .section .tdata,"awT",@progbits + .globl tls2 + .align 4 +tls2: + .long 1 # 0x1 + .size tls2, 4 diff --git a/test/elf/Inputs/tls.c b/test/elf/Inputs/tls.c new file mode 100644 index 000000000000..672350756562 --- /dev/null +++ b/test/elf/Inputs/tls.c @@ -0,0 +1,11 @@ +extern __thread int tls0; +extern __thread int tls1; +extern __thread int tls2; + +__thread int tls0 = 0; +__thread int tls1 = 0; +__thread int tls2 = 1; + +int main() { + return tls0 + tls1 + tls2; +} diff --git a/test/elf/Inputs/tls.x86-64 b/test/elf/Inputs/tls.x86-64 Binary files differnew file mode 100644 index 000000000000..b420ce89b19b --- /dev/null +++ b/test/elf/Inputs/tls.x86-64 diff --git a/test/elf/Inputs/tlsAddr.x86-64 b/test/elf/Inputs/tlsAddr.x86-64 Binary files differnew file mode 100644 index 000000000000..16cc9ab25abf --- /dev/null +++ b/test/elf/Inputs/tlsAddr.x86-64 diff --git a/test/elf/Inputs/tlsaddr.c b/test/elf/Inputs/tlsaddr.c new file mode 100644 index 000000000000..f62d57b3bfb4 --- /dev/null +++ b/test/elf/Inputs/tlsaddr.c @@ -0,0 +1,8 @@ +__thread int tls0 = 0; +__thread int tls1 = 0; +__thread int tls2 = 1; +__thread int tls3 = 2; + +int main() { + return tls0 + tls1 + tls2; +} diff --git a/test/elf/Inputs/undef-from-main-so.c b/test/elf/Inputs/undef-from-main-so.c new file mode 100644 index 000000000000..f1cb63db7ada --- /dev/null +++ b/test/elf/Inputs/undef-from-main-so.c @@ -0,0 +1 @@ +int x[2] = {1, 2}; diff --git a/test/elf/Inputs/undef-from-main.c b/test/elf/Inputs/undef-from-main.c new file mode 100644 index 000000000000..366d934dd84f --- /dev/null +++ b/test/elf/Inputs/undef-from-main.c @@ -0,0 +1,5 @@ +extern int x[2]; + +int main() { + x[0] = 2; +} diff --git a/test/elf/Inputs/undef-pc32.o b/test/elf/Inputs/undef-pc32.o Binary files differnew file mode 100644 index 000000000000..954916d59991 --- /dev/null +++ b/test/elf/Inputs/undef-pc32.o diff --git a/test/elf/Inputs/undef.o b/test/elf/Inputs/undef.o Binary files differnew file mode 100644 index 000000000000..3c9b60c6ca33 --- /dev/null +++ b/test/elf/Inputs/undef.o diff --git a/test/elf/Inputs/undef2-so.o.yaml b/test/elf/Inputs/undef2-so.o.yaml new file mode 100644 index 000000000000..9ecf374ced11 --- /dev/null +++ b/test/elf/Inputs/undef2-so.o.yaml @@ -0,0 +1,50 @@ +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000001 + Content: 554889E5488B05000000008B005DC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000007 + Symbol: myexportedsymbol + Type: R_X86_64_GOTPCREL + Addend: -4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: func + Type: STT_FUNC + Section: .text + Size: 0x000000000000000F + - Name: _GLOBAL_OFFSET_TABLE_ + - Name: myexportedsymbol diff --git a/test/elf/Inputs/use-shared-32s.c b/test/elf/Inputs/use-shared-32s.c new file mode 100644 index 000000000000..63054cb036ea --- /dev/null +++ b/test/elf/Inputs/use-shared-32s.c @@ -0,0 +1,8 @@ +void foo(); + +void (*func)(); + +int main() { + func = foo; + func(); +} diff --git a/test/elf/Inputs/use-shared-32s.x86-64 b/test/elf/Inputs/use-shared-32s.x86-64 Binary files differnew file mode 100644 index 000000000000..7e223677b93f --- /dev/null +++ b/test/elf/Inputs/use-shared-32s.x86-64 diff --git a/test/elf/Inputs/use-shared.c b/test/elf/Inputs/use-shared.c new file mode 100644 index 000000000000..b370eaa4fac2 --- /dev/null +++ b/test/elf/Inputs/use-shared.c @@ -0,0 +1,7 @@ +extern int i; +void foo(); + +int main() { + foo(); + return i; +} diff --git a/test/elf/Inputs/use-shared.x86-64 b/test/elf/Inputs/use-shared.x86-64 Binary files differnew file mode 100644 index 000000000000..25e1eb87a2b4 --- /dev/null +++ b/test/elf/Inputs/use-shared.x86-64 diff --git a/test/elf/Inputs/weaksym.o b/test/elf/Inputs/weaksym.o Binary files differnew file mode 100644 index 000000000000..010ce704a313 --- /dev/null +++ b/test/elf/Inputs/weaksym.o diff --git a/test/elf/Inputs/writersyms.o b/test/elf/Inputs/writersyms.o Binary files differnew file mode 100644 index 000000000000..7cd472d99d77 --- /dev/null +++ b/test/elf/Inputs/writersyms.o diff --git a/test/elf/Inputs/x86-64-relocs.S b/test/elf/Inputs/x86-64-relocs.S new file mode 100644 index 000000000000..2547c0f19bb0 --- /dev/null +++ b/test/elf/Inputs/x86-64-relocs.S @@ -0,0 +1,12 @@ + .text + .globl main + .align 16, 0x90 + .type main,@function +main: # @main + call foo@PLT + ret + + .globl foo + .type foo,@function +foo: + ret diff --git a/test/elf/Mips/base-address-64.test b/test/elf/Mips/base-address-64.test new file mode 100644 index 000000000000..07110e7f918f --- /dev/null +++ b/test/elf/Mips/base-address-64.test @@ -0,0 +1,78 @@ +# Check executable base address configuration. Base address should be +# equal to 0x400000 and the MIPS_BASE_ADDRESS dynamic tag's value should +# be the same. +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mips64el --noinhibit-exec -o %t.exe %t.o +# RUN: llvm-readobj -dynamic-table -program-headers %t.exe | FileCheck %s + +# CHECK: DynamicSection [ (13 entries) +# CHECK: Tag Type Name/Value +# CHECK-NEXT: 0x0000000000000004 HASH 0x{{[0-9A-F]+}} +# CHECK-NEXT: 0x0000000000000005 STRTAB 0x{{[0-9A-F]+}} +# CHECK-NEXT: 0x0000000000000006 SYMTAB 0x{{[0-9A-F]+}} +# CHECK-NEXT: 0x000000000000000A STRSZ 1 (bytes) +# CHECK-NEXT: 0x000000000000000B SYMENT 24 (bytes) +# CHECK-NEXT: 0x0000000070000001 MIPS_RLD_VERSION 1 +# CHECK-NEXT: 0x0000000070000005 MIPS_FLAGS NOTPOT +# CHECK-NEXT: 0x0000000070000006 MIPS_BASE_ADDRESS 0x120000000 +# CHECK-NEXT: 0x000000007000000A MIPS_LOCAL_GOTNO 2 +# CHECK-NEXT: 0x0000000070000011 MIPS_SYMTABNO 1 +# CHECK-NEXT: 0x0000000070000013 MIPS_GOTSYM 0x1 +# CHECK-NEXT: 0x0000000000000003 PLTGOT 0x120001000 +# CHECK-NEXT: 0x0000000000000000 NULL 0x0 +# CHECK-NEXT: ] + +# CHECK: ProgramHeaders [ +# CHECK: ProgramHeader { +# CHECK: Type: PT_PHDR (0x6) +# CHECK: Offset: 0x40 +# CHECK: VirtualAddress: 0x{{[0-9A-F]+}} +# CHECK: } +# CHECK: ProgramHeader { +# CHECK: Type: PT_INTERP (0x3) +# CHECK: Offset: 0x190 +# CHECK: VirtualAddress: 0x{{[0-9A-F]+}} +# CHECK: } +# CHECK: ProgramHeader { +# CHECK: Type: PT_LOAD (0x1) +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x120000000 + +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ARCH_64R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x10 + Size: 0x00 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x10 + Size: 0x00 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: main + Section: .text diff --git a/test/elf/Mips/base-address.test b/test/elf/Mips/base-address.test new file mode 100644 index 000000000000..f55091f84c33 --- /dev/null +++ b/test/elf/Mips/base-address.test @@ -0,0 +1,109 @@ +# Check executable base address configuration. Base address should be +# equal to 0x400000 and the MIPS_BASE_ADDRESS dynamic tag's value should +# be the same. +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel --noinhibit-exec -o %t.exe %t.o +# RUN: llvm-readobj -dynamic-table -program-headers %t.exe | FileCheck %s + +# CHECK: DynamicSection [ (13 entries) +# CHECK: Tag Type Name/Value +# CHECK-NEXT: 0x00000004 HASH 0x{{[0-9A-F]+}} +# CHECK-NEXT: 0x00000005 STRTAB 0x{{[0-9A-F]+}} +# CHECK-NEXT: 0x00000006 SYMTAB 0x{{[0-9A-F]+}} +# CHECK-NEXT: 0x0000000A STRSZ 1 (bytes) +# CHECK-NEXT: 0x0000000B SYMENT 16 (bytes) +# CHECK-NEXT: 0x70000001 MIPS_RLD_VERSION 1 +# CHECK-NEXT: 0x70000005 MIPS_FLAGS NOTPOT +# CHECK-NEXT: 0x70000006 MIPS_BASE_ADDRESS 0x400000 +# CHECK-NEXT: 0x7000000A MIPS_LOCAL_GOTNO 2 +# CHECK-NEXT: 0x70000011 MIPS_SYMTABNO 1 +# CHECK-NEXT: 0x70000013 MIPS_GOTSYM 0x1 +# CHECK-NEXT: 0x00000003 PLTGOT 0x401000 +# CHECK-NEXT: 0x00000000 NULL 0x0 +# CHECK-NEXT: ] + +# CHECK: ProgramHeaders [ +# CHECK: ProgramHeader { +# CHECK: Type: PT_PHDR (0x6) +# CHECK: Offset: 0x34 +# CHECK: VirtualAddress: 0x{{[0-9A-F]+}} +# CHECK: } +# CHECK: ProgramHeader { +# CHECK: Type: PT_INTERP (0x3) +# CHECK: Offset: 0xF4 +# CHECK: VirtualAddress: 0x{{[0-9A-F]+}} +# CHECK: } +# CHECK: ProgramHeader { +# CHECK: Type: PT_LOAD (0x1) +# CHECK: Offset: 0x0 +# CHECK: VirtualAddress: 0x{{[0-9A-F]+}} +# CHECK: } +# CHECK: ProgramHeader { +# CHECK: Type: PT_LOAD (0x1) +# CHECK: Offset: 0x1000 +# CHECK: VirtualAddress: 0x{{[0-9A-F]+}} +# CHECK: } +# CHECK: ProgramHeader { +# CHECK: Type: PT_LOAD (0x1) +# CHECK: Offset: 0x2000 +# CHECK: VirtualAddress: 0x{{[0-9A-F]+}} +# CHECK: } +# CHECK: ProgramHeader { +# CHECK: Type: PT_DYNAMIC (0x2) +# CHECK: Offset: 0x12C +# CHECK: VirtualAddress: 0x{{[0-9A-F]+}} +# CHECK: } +# CHECK: ] + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x00 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x00 + - Name: .reginfo + Type: SHT_MIPS_REGINFO + Flags: [ SHF_ALLOC ] + AddressAlign: 0x01 + Size: 0x18 + - Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x08 + Content: '000020010101000100000000000000000000000000000000' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .reginfo + Type: STT_SECTION + Section: .reginfo + - Name: .MIPS.abiflags + Type: STT_SECTION + Section: .MIPS.abiflags + Global: + - Name: main + Section: .text diff --git a/test/elf/Mips/ctors-order.test b/test/elf/Mips/ctors-order.test new file mode 100644 index 000000000000..344dcd5fc516 --- /dev/null +++ b/test/elf/Mips/ctors-order.test @@ -0,0 +1,163 @@ +# Check ordering of .ctors.* sections. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-crtbeginS.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-crtendS.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-obj.o +# RUN: lld -flavor gnu -target mipsel -shared --output-filetype=yaml \ +# RUN: %t-crtbeginS.o %t-obj.o %t-crtendS.o | FileCheck %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so \ +# RUN: %t-crtbeginS.o %t-obj.o %t-crtendS.o +# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=RAW %s + +# CHECK: defined-atoms: +# CHECK-NEXT: - type: data +# CHECK-NEXT: alignment: 2^2 +# CHECK-NEXT: section-choice: custom-required +# CHECK-NEXT: section-name: .ctors +# CHECK-NEXT: references: +# CHECK-NEXT: - kind: layout-after +# CHECK-NEXT: offset: 0 +# CHECK-NEXT: target: __CTOR_LIST__ +# CHECK-NEXT: - name: __CTOR_LIST__ +# CHECK-NEXT: type: data +# CHECK-NEXT: content: [ FF, FF, FF, FF ] +# CHECK-NEXT: alignment: 2^2 +# CHECK-NEXT: section-choice: custom-required +# CHECK-NEXT: section-name: .ctors +# CHECK-NEXT: - type: data +# CHECK-NEXT: content: [ 11, 11, 11, 11 ] +# CHECK-NEXT: alignment: 2^2 +# CHECK-NEXT: section-choice: custom-required +# CHECK-NEXT: section-name: .ctors.1 +# CHECK-NEXT: - type: data +# CHECK-NEXT: content: [ 22, 22, 22, 22 ] +# CHECK-NEXT: alignment: 2^2 +# CHECK-NEXT: section-choice: custom-required +# CHECK-NEXT: section-name: .ctors.2 +# CHECK-NEXT: - ref-name: L003 +# CHECK-NEXT: type: data +# CHECK-NEXT: alignment: 2^2 +# CHECK-NEXT: section-choice: custom-required +# CHECK-NEXT: section-name: .ctors +# CHECK-NEXT: references: +# CHECK-NEXT: - kind: layout-after +# CHECK-NEXT: offset: 0 +# CHECK-NEXT: target: __CTOR_END__ +# CHECK-NEXT: - name: __CTOR_END__ +# CHECK-NEXT: type: data +# CHECK-NEXT: content: [ 00, 00, 00, 00 ] +# CHECK-NEXT: alignment: 2^2 +# CHECK-NEXT: section-choice: custom-required +# CHECK-NEXT: section-name: .ctors + +# RAW: Contents of section .ctors: +# RAW-NEXT: 1000 ffffffff 11111111 22222222 00000000 +# crtbeginS.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .ctors + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Content: 'FFFFFFFF' + +Symbols: + Local: + - Name: .ctors + Type: STT_SECTION + Section: .ctors + - Name: __CTOR_LIST__ + Type: STT_OBJECT + Section: .ctors + +# crtendS.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x0F + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: .ctors + Type: R_MIPS_HI16 + - Offset: 0x04 + Symbol: .ctors + Type: R_MIPS_LO16 + - Offset: 0x08 + Symbol: .ctors + Type: R_MIPS_HI16 + - Offset: 0x0C + Symbol: .ctors + Type: R_MIPS_LO16 + - Name: .ctors + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .ctors + Type: STT_SECTION + Section: .ctors + - Name: __CTOR_END__ + Type: STT_OBJECT + Section: .ctors + - Name: __do_global_ctors_aux + Type: STT_FUNC + Section: .text + +# obj.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .ctors.2 + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Content: '22222222' + - Name: .ctors.1 + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Content: '11111111' + +Symbols: + Local: + - Name: .ctors.2 + Type: STT_SECTION + Section: .ctors.2 + - Name: .ctors.1 + Type: STT_SECTION + Section: .ctors.1 +... diff --git a/test/elf/Mips/dt-textrel-64.test b/test/elf/Mips/dt-textrel-64.test new file mode 100644 index 000000000000..32cc99e54b2f --- /dev/null +++ b/test/elf/Mips/dt-textrel-64.test @@ -0,0 +1,74 @@ +# Check that if a dynamic relocation R_MIPS_64 modify a read-only section, +# .dynamic section contains the DT_TEXTREL tag. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mips64el -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dynamic-table %t.exe | FileCheck %s + +# CHECK: 0x{{[0-9A-F]+}} TEXTREL + +# so.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x4 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 0x08 + +# o.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x4 + Size: 0x8 + + - Name: .rel.text + Type: SHT_RELA + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MIPS_64 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x8 + - Name: T1 +... diff --git a/test/elf/Mips/dt-textrel.test b/test/elf/Mips/dt-textrel.test new file mode 100644 index 000000000000..ca854dff8e58 --- /dev/null +++ b/test/elf/Mips/dt-textrel.test @@ -0,0 +1,74 @@ +# Check that if a dynamic relocation modify a read-only section, +# .dynamic section contains the DT_TEXTREL tag. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dynamic-table %t.exe | FileCheck %s + +# CHECK: 0x{{[0-9A-F]+}} TEXTREL + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x04 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 0x04 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: '00000000' + + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MIPS_32 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x04 + - Name: T1 +... diff --git a/test/elf/Mips/dynlib-dynamic.test b/test/elf/Mips/dynlib-dynamic.test new file mode 100644 index 000000000000..54afdec263a6 --- /dev/null +++ b/test/elf/Mips/dynlib-dynamic.test @@ -0,0 +1,110 @@ +# Check MIPS specific tags in the dynamic table. + +# Build shared library +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec -o %t.so %t.o +# RUN: llvm-readobj -dynamic-table %t.so | FileCheck %s + +# CHECK: Format: ELF32-mips +# CHECK: Arch: mipsel +# CHECK: AddressSize: 32bit +# CHECK: LoadName: +# CHECK: DynamicSection [ (13 entries) +# CHECK: Tag Type Name/Value +# CHECK-NEXT: 0x00000004 HASH 0x{{[0-9A-F]+}} +# CHECK-NEXT: 0x00000005 STRTAB 0x{{[0-9A-F]+}} +# CHECK-NEXT: 0x00000006 SYMTAB 0x{{[0-9A-F]+}} +# CHECK-NEXT: 0x0000000A STRSZ 17 (bytes) +# CHECK-NEXT: 0x0000000B SYMENT 16 (bytes) +# CHECK-NEXT: 0x70000001 MIPS_RLD_VERSION 1 +# CHECK-NEXT: 0x70000005 MIPS_FLAGS NOTPOT +# CHECK-NEXT: 0x70000006 MIPS_BASE_ADDRESS 0x0 +# CHECK-NEXT: 0x7000000A MIPS_LOCAL_GOTNO 4 +# CHECK-NEXT: 0x70000011 MIPS_SYMTABNO 4 +# CHECK-NEXT: 0x70000013 MIPS_GOTSYM 0x2 +# CHECK-NEXT: 0x00000003 PLTGOT 0x1000 +# CHECK-NEXT: 0x00000000 NULL 0x0 +# CHECK-NEXT: ] + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x18 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: '$.str1' + Type: R_MIPS_GOT16 + - Offset: 0x04 + Symbol: '$.str1' + Type: R_MIPS_LO16 + - Offset: 0x08 + Symbol: '$.str2' + Type: R_MIPS_GOT16 + - Offset: 0x0C + Symbol: '$.str2' + Type: R_MIPS_LO16 + - Offset: 0x10 + Symbol: glob2 + Type: R_MIPS_CALL16 + - Offset: 0x14 + Symbol: ext1 + Type: R_MIPS_CALL16 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x00 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x00 + - Name: .rodata.str1 + Type: SHT_PROGBITS + AddressAlign: 0x01 + Size: 0x05 + - Name: .rodata.str2 + Type: SHT_PROGBITS + AddressAlign: 0x01 + Size: 0x05 + +Symbols: + Local: + - Name: '$.str1' + Section: .rodata.str1 + - Name: '$.str2' + Section: .rodata.str2 + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .rodata.str1 + Type: STT_SECTION + Section: .rodata.str1 + - Name: .rodata.str2 + Type: STT_SECTION + Section: .rodata.str2 + Global: + - Name: glob + Section: .text + - Name: ext1 + - Name: glob2 diff --git a/test/elf/Mips/dynlib-dynsym-micro.test b/test/elf/Mips/dynlib-dynsym-micro.test new file mode 100644 index 000000000000..4d75945af7b0 --- /dev/null +++ b/test/elf/Mips/dynlib-dynsym-micro.test @@ -0,0 +1,208 @@ +# 1. Check sorting of .dynsym content accordingly to .got section +# in case of using microMIPS relocations. +# 2. Check that microMIPS records in a dynamic symbol table have: +# - cleared the STO_MIPS_MICROMIPS flag +# - adjusted adress + +# Build shared library +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec -o %t-so %t.o +# RUN: llvm-readobj -dyn-symbols %t-so | FileCheck -check-prefix=CHECK-DYN %s + +# Build shared library (yaml format) +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec \ +# RUN: --output-filetype=yaml -o %t-yaml %t.o +# RUN: FileCheck -check-prefix=CHECK-GOT %s < %t-yaml + +# CHECK-DYN: Format: ELF32-mips +# CHECK-DYN: Arch: mipsel +# CHECK-DYN: AddressSize: 32bit +# CHECK-DYN: LoadName: +# CHECK-DYN: DynamicSymbols [ +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: @ (0) +# CHECK-DYN: Value: 0x0 +# CHECK-DYN: Size: 0 +# CHECK-DYN: Binding: Local (0x0) +# CHECK-DYN: Type: None (0x0) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: Undefined (0x0) +# CHECK-DYN: } +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: bar@ (5) +# CHECK-DYN: Value: 0x139 +# CHECK-DYN: Size: 4 +# CHECK-DYN: Binding: Global (0x1) +# CHECK-DYN: Type: Function (0x2) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: .text (0x4) +# CHECK-DYN: } +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: foo@ (1) +# CHECK-DYN: Value: 0x121 +# CHECK-DYN: Size: 24 +# CHECK-DYN: Binding: Global (0x1) +# CHECK-DYN: Type: Function (0x2) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: .text (0x4) +# CHECK-DYN: } +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: ext1@ (9) +# CHECK-DYN: Value: 0x0 +# CHECK-DYN: Size: 0 +# CHECK-DYN: Binding: Global (0x1) +# CHECK-DYN: Type: None (0x0) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: Undefined (0x0) +# CHECK-DYN: } +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: ext2@ (14) +# CHECK-DYN: Value: 0x0 +# CHECK-DYN: Size: 0 +# CHECK-DYN: Binding: Global (0x1) +# CHECK-DYN: Type: None (0x0) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: Undefined (0x0) +# CHECK-DYN: } +# CHECK-DYN: ] + +# CHECK-GOT: - type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: - type: got +# CHECK-GOT: content: [ 00, 00, 00, 80 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: - ref-name: L000 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_32_HI16 +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: L007 +# CHECK-GOT: - ref-name: L002 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_32_HI16 +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: L008 +# CHECK-GOT: - ref-name: L004 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: foo +# CHECK-GOT: - ref-name: L005 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: ext1 +# CHECK-GOT: - ref-name: L006 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: ext2 + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x1C + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: .rodata.str1 + Type: R_MICROMIPS_GOT16 + - Offset: 0x04 + Symbol: .rodata.str1 + Type: R_MICROMIPS_LO16 + - Offset: 0x08 + Symbol: .rodata.str2 + Type: R_MICROMIPS_GOT16 + - Offset: 0x0C + Symbol: .rodata.str2 + Type: R_MICROMIPS_LO16 + - Offset: 0x10 + Symbol: foo + Type: R_MICROMIPS_CALL16 + - Offset: 0x14 + Symbol: ext1 + Type: R_MICROMIPS_CALL16 + - Offset: 0x18 + Symbol: ext2 + Type: R_MICROMIPS_CALL16 + - Name: .rodata.str1 + Type: SHT_PROGBITS + AddressAlign: 0x01 + Size: 0x05 + - Name: .rodata.str2 + Type: SHT_PROGBITS + AddressAlign: 0x01 + Size: 0x05 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .rodata.str1 + Type: STT_SECTION + Section: .rodata.str1 + - Name: .rodata.str2 + Type: STT_SECTION + Section: .rodata.str2 + Global: + - Name: bar + Section: .text + Value: 0x18 + Other: [ STO_MIPS_MICROMIPS ] + - Name: foo + Section: .text + Other: [ STO_MIPS_MICROMIPS ] + - Name: ext1 + - Name: ext2 +... diff --git a/test/elf/Mips/dynlib-dynsym.test b/test/elf/Mips/dynlib-dynsym.test new file mode 100644 index 000000000000..d480c3cbbe41 --- /dev/null +++ b/test/elf/Mips/dynlib-dynsym.test @@ -0,0 +1,202 @@ +# Check sorting of .dynsym content accordingly to .got section. + +# Build shared library +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec -o %t-so %t.o +# RUN: llvm-readobj -dyn-symbols %t-so | FileCheck -check-prefix=CHECK-DYN %s + +# Build shared library (yaml format) +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec \ +# RUN: --output-filetype=yaml -o %t-yaml %t.o +# RUN: FileCheck -check-prefix=CHECK-GOT %s < %t-yaml + +# CHECK-DYN: Format: ELF32-mips +# CHECK-DYN: Arch: mipsel +# CHECK-DYN: AddressSize: 32bit +# CHECK-DYN: LoadName: +# CHECK-DYN: DynamicSymbols [ +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: @ (0) +# CHECK-DYN: Value: 0x0 +# CHECK-DYN: Size: 0 +# CHECK-DYN: Binding: Local (0x0) +# CHECK-DYN: Type: None (0x0) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: Undefined (0x0) +# CHECK-DYN: } +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: bar@ (5) +# CHECK-DYN: Value: 0x138 +# CHECK-DYN: Size: 4 +# CHECK-DYN: Binding: Global (0x1) +# CHECK-DYN: Type: Function (0x2) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: .text (0x4) +# CHECK-DYN: } +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: foo@ (1) +# CHECK-DYN: Value: 0x120 +# CHECK-DYN: Size: 24 +# CHECK-DYN: Binding: Global (0x1) +# CHECK-DYN: Type: Function (0x2) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: .text (0x4) +# CHECK-DYN: } +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: ext1@ (9) +# CHECK-DYN: Value: 0x0 +# CHECK-DYN: Size: 0 +# CHECK-DYN: Binding: Global (0x1) +# CHECK-DYN: Type: None (0x0) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: Undefined (0x0) +# CHECK-DYN: } +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: ext2@ (14) +# CHECK-DYN: Value: 0x0 +# CHECK-DYN: Size: 0 +# CHECK-DYN: Binding: Global (0x1) +# CHECK-DYN: Type: None (0x0) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: Undefined (0x0) +# CHECK-DYN: } +# CHECK-DYN: ] + +# CHECK-GOT: - type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: - type: got +# CHECK-GOT: content: [ 00, 00, 00, 80 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: - ref-name: L000 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_32_HI16 +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: L007 +# CHECK-GOT: - ref-name: L002 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_32_HI16 +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: L008 +# CHECK-GOT: - ref-name: L004 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: foo +# CHECK-GOT: - ref-name: L005 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: ext1 +# CHECK-GOT: - ref-name: L006 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: ext2 + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x1C + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: .rodata.str1 + Type: R_MIPS_GOT16 + - Offset: 0x04 + Symbol: .rodata.str1 + Type: R_MIPS_LO16 + - Offset: 0x08 + Symbol: .rodata.str2 + Type: R_MIPS_GOT16 + - Offset: 0x0C + Symbol: .rodata.str2 + Type: R_MIPS_LO16 + - Offset: 0x10 + Symbol: foo + Type: R_MIPS_CALL16 + - Offset: 0x14 + Symbol: ext1 + Type: R_MIPS_CALL16 + - Offset: 0x18 + Symbol: ext2 + Type: R_MIPS_CALL16 + - Name: .rodata.str1 + Type: SHT_PROGBITS + AddressAlign: 0x01 + Size: 0x05 + - Name: .rodata.str2 + Type: SHT_PROGBITS + AddressAlign: 0x01 + Size: 0x05 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .rodata.str1 + Type: STT_SECTION + Section: .rodata.str1 + - Name: .rodata.str2 + Type: STT_SECTION + Section: .rodata.str2 + Global: + - Name: bar + Section: .text + Value: 0x18 + - Name: foo + Section: .text + - Name: ext1 + - Name: ext2 +... diff --git a/test/elf/Mips/dynlib-fileheader-64.test b/test/elf/Mips/dynlib-fileheader-64.test new file mode 100644 index 000000000000..206f4fa7794d --- /dev/null +++ b/test/elf/Mips/dynlib-fileheader-64.test @@ -0,0 +1,72 @@ +# Check ELF Header for 64-bit shared library. + +# Build shared library +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t.o +# RUN: llvm-readobj -file-headers %t.so | FileCheck %s + +# CHECK: Format: ELF64-mips +# CHECK: Arch: mips64el +# CHECK: AddressSize: 64bit +# CHECK: LoadName: +# CHECK: ElfHeader { +# CHECK: Ident { +# CHECK: Magic: (7F 45 4C 46) +# CHECK: Class: 64-bit (0x2) +# CHECK: DataEncoding: LittleEndian (0x1) +# CHECK: FileVersion: 1 +# CHECK: OS/ABI: SystemV (0x0) +# CHECK: ABIVersion: 0 +# CHECK: Unused: (00 00 00 00 00 00 00) +# CHECK: } +# CHECK: Type: SharedObject (0x3) +# CHECK: Machine: EM_MIPS (0x8) +# CHECK: Version: 1 +# CHECK: Entry: 0x170 +# CHECK: ProgramHeaderOffset: 0x40 +# CHECK: SectionHeaderOffset: 0x2140 +# CHECK: Flags [ (0x80000006) +# CHECK: EF_MIPS_ARCH_64R2 (0x80000000) +# CHECK: EF_MIPS_CPIC (0x4) +# CHECK: EF_MIPS_PIC (0x2) +# CHECK: ] +# CHECK: HeaderSize: 64 +# CHECK: ProgramHeaderEntrySize: 56 +# CHECK: ProgramHeaderCount: 4 +# CHECK: SectionHeaderEntrySize: 64 +# CHECK: SectionHeaderCount: 11 +# CHECK: StringTableSectionIndex: 8 +# CHECK: } + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x10 + Size: 0x08 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + Global: + - Name: data + Type: STT_OBJECT + Section: .data + Size: 0x04 +... diff --git a/test/elf/Mips/dynlib-fileheader-micro-64.test b/test/elf/Mips/dynlib-fileheader-micro-64.test new file mode 100644 index 000000000000..c03a951671ea --- /dev/null +++ b/test/elf/Mips/dynlib-fileheader-micro-64.test @@ -0,0 +1,75 @@ +# Check ELF Header for shared library in case of microMIPS symbols. + +# Build shared library +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t.o +# RUN: llvm-readobj -file-headers %t.so | FileCheck %s + +# CHECK: Format: ELF64-mips +# CHECK-NEXT: Arch: mips64el +# CHECK-NEXT: AddressSize: 64bit +# CHECK-NEXT: LoadName: +# CHECK-NEXT: ElfHeader { +# CHECK-NEXT: Ident { +# CHECK-NEXT: Magic: (7F 45 4C 46) +# CHECK-NEXT: Class: 64-bit (0x2) +# CHECK-NEXT: DataEncoding: LittleEndian (0x1) +# CHECK-NEXT: FileVersion: 1 +# CHECK-NEXT: OS/ABI: SystemV (0x0) +# CHECK-NEXT: ABIVersion: 0 +# CHECK-NEXT: Unused: (00 00 00 00 00 00 00) +# CHECK-NEXT: } +# CHECK-NEXT: Type: SharedObject (0x3) +# CHECK-NEXT: Machine: EM_MIPS (0x8) +# CHECK-NEXT: Version: 1 +# CHECK-NEXT: Entry: 0x170 +# CHECK-NEXT: ProgramHeaderOffset: 0x40 +# CHECK-NEXT: SectionHeaderOffset: 0x2140 +# CHECK-NEXT: Flags [ (0x82000007) +# CHECK-NEXT: EF_MIPS_ARCH_64R2 (0x80000000) +# CHECK-NEXT: EF_MIPS_CPIC (0x4) +# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000) +# CHECK-NEXT: EF_MIPS_NOREORDER (0x1) +# CHECK-NEXT: EF_MIPS_PIC (0x2) +# CHECK-NEXT: ] +# CHECK-NEXT: HeaderSize: 64 +# CHECK-NEXT: ProgramHeaderEntrySize: 56 +# CHECK-NEXT: ProgramHeaderCount: 4 +# CHECK-NEXT: SectionHeaderEntrySize: 64 +# CHECK-NEXT: SectionHeaderCount: 11 +# CHECK-NEXT: StringTableSectionIndex: 8 +# CHECK-NEXT:} + +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_MICROMIPS, EF_MIPS_ARCH_64R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x10 + Size: 0x08 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + Global: + - Name: foo + Type: STT_FUNC + Section: .text + Size: 0x08 + Other: [ STO_MIPS_MICROMIPS ] diff --git a/test/elf/Mips/dynlib-fileheader-micro.test b/test/elf/Mips/dynlib-fileheader-micro.test new file mode 100644 index 000000000000..139b3aa626c9 --- /dev/null +++ b/test/elf/Mips/dynlib-fileheader-micro.test @@ -0,0 +1,82 @@ +# Check ELF Header for shared library in case of microMIPS symbols. + +# Build shared library +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t.o +# RUN: llvm-readobj -file-headers %t.so | FileCheck %s + +# CHECK: Format: ELF32-mips +# CHECK-NEXT: Arch: mipsel +# CHECK-NEXT: AddressSize: 32bit +# CHECK-NEXT: LoadName: +# CHECK-NEXT: ElfHeader { +# CHECK-NEXT: Ident { +# CHECK-NEXT: Magic: (7F 45 4C 46) +# CHECK-NEXT: Class: 32-bit (0x1) +# CHECK-NEXT: DataEncoding: LittleEndian (0x1) +# CHECK-NEXT: FileVersion: 1 +# CHECK-NEXT: OS/ABI: SystemV (0x0) +# CHECK-NEXT: ABIVersion: 0 +# CHECK-NEXT: Unused: (00 00 00 00 00 00 00) +# CHECK-NEXT: } +# CHECK-NEXT: Type: SharedObject (0x3) +# CHECK-NEXT: Machine: EM_MIPS (0x8) +# CHECK-NEXT: Version: 1 +# CHECK-NEXT: Entry: 0x100 +# CHECK-NEXT: ProgramHeaderOffset: 0x34 +# CHECK-NEXT: SectionHeaderOffset: 0x2100 +# CHECK-NEXT: Flags [ (0x72001007) +# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000) +# CHECK-NEXT: EF_MIPS_ARCH_32R2 (0x70000000) +# CHECK-NEXT: EF_MIPS_CPIC (0x4) +# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000) +# CHECK-NEXT: EF_MIPS_NOREORDER (0x1) +# CHECK-NEXT: EF_MIPS_PIC (0x2) +# CHECK-NEXT: ] +# CHECK-NEXT: HeaderSize: 52 +# CHECK-NEXT: ProgramHeaderEntrySize: 32 +# CHECK-NEXT: ProgramHeaderCount: 4 +# CHECK-NEXT: SectionHeaderEntrySize: 40 +# CHECK-NEXT: SectionHeaderCount: 11 +# CHECK-NEXT: StringTableSectionIndex: 8 +# CHECK-NEXT:} + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x00 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x00 + - Name: .reginfo + Type: SHT_MIPS_REGINFO + Flags: [ SHF_ALLOC ] + AddressAlign: 0x01 + Size: 0x18 + - Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x08 + Size: 0x18 + +Symbols: + Global: + - Name: glob + Section: .text + Other: [ STO_MIPS_MICROMIPS ] diff --git a/test/elf/Mips/dynlib-fileheader.test b/test/elf/Mips/dynlib-fileheader.test new file mode 100644 index 000000000000..5dd9d6a64a71 --- /dev/null +++ b/test/elf/Mips/dynlib-fileheader.test @@ -0,0 +1,80 @@ +# Check ELF Header for shared library. + +# Build shared library +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t.o +# RUN: llvm-readobj -file-headers %t.so | FileCheck %s + +# CHECK: Format: ELF32-mips +# CHECK: Arch: mipsel +# CHECK: AddressSize: 32bit +# CHECK: LoadName: +# CHECK: ElfHeader { +# CHECK: Ident { +# CHECK: Magic: (7F 45 4C 46) +# CHECK: Class: 32-bit (0x1) +# CHECK: DataEncoding: LittleEndian (0x1) +# CHECK: FileVersion: 1 +# CHECK: OS/ABI: SystemV (0x0) +# CHECK: ABIVersion: 0 +# CHECK: Unused: (00 00 00 00 00 00 00) +# CHECK: } +# CHECK: Type: SharedObject (0x3) +# CHECK: Machine: EM_MIPS (0x8) +# CHECK: Version: 1 +# CHECK: Entry: 0x100 +# CHECK: ProgramHeaderOffset: 0x34 +# CHECK: SectionHeaderOffset: 0x2100 +# CHECK: Flags [ (0x70001007) +# CHECK: EF_MIPS_ABI_O32 (0x1000) +# CHECK: EF_MIPS_ARCH_32R2 (0x70000000) +# CHECK: EF_MIPS_CPIC (0x4) +# CHECK: EF_MIPS_NOREORDER (0x1) +# CHECK: EF_MIPS_PIC (0x2) +# CHECK: ] +# CHECK: HeaderSize: 52 +# CHECK: ProgramHeaderEntrySize: 32 +# CHECK: ProgramHeaderCount: 4 +# CHECK: SectionHeaderEntrySize: 40 +# CHECK: SectionHeaderCount: 11 +# CHECK: StringTableSectionIndex: 8 +# CHECK:} + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x00 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x00 + - Name: .reginfo + Type: SHT_MIPS_REGINFO + Flags: [ SHF_ALLOC ] + AddressAlign: 0x01 + Size: 0x18 + - Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x08 + Size: 0x18 + +Symbols: + Global: + - Name: glob + Section: .text diff --git a/test/elf/Mips/dynsym-table-1.test b/test/elf/Mips/dynsym-table-1.test new file mode 100644 index 000000000000..43c48e730405 --- /dev/null +++ b/test/elf/Mips/dynsym-table-1.test @@ -0,0 +1,127 @@ +# Check that LLD does not populate an executable file dynamic symbol table +# by unnecessary symbols. +# 1. bar.so defines T2 +# 2. foo.so defines T1 and references T2 +# 3. main.o reference T1 +# 4. a.out dynamic table should contain T1 entry only + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-bar.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-foo.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-main.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t-bar.so %t-bar.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t-foo.so %t-foo.o %t-bar.so +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe --as-needed \ +# RUN: %t-main.o %t-foo.so %t-bar.so +# RUN: llvm-readobj -dt -dynamic-table %t.exe | FileCheck %s + +# CHECK: DynamicSymbols [ +# 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: T1@ ({{.*}}) +# CHECK-NEXT: Value: {{.*}} +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 8 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: 0x00000003 PLTGOT 0x401000 +# CHECK-NEXT: 0x00000001 NEEDED SharedLibrary (dynsym-table-1.test.tmp-foo.so) +# CHECK-NEXT: 0x00000000 NULL 0x0 + +# bar.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 +Symbols: + Global: + - Name: T2 + Type: STT_FUNC + Section: .text + Size: 0x08 + +# foo.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x08 + Info: .text + Relocations: + - Offset: 0 + Symbol: T2 + Type: R_MIPS_CALL16 +Symbols: + Global: + - Name: T1 + Type: STT_FUNC + Section: .text + Size: 0x08 + - Name: T2 + +# main.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x08 + Info: .text + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MIPS_32 +Symbols: + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x08 + - Name: T1 +... diff --git a/test/elf/Mips/dynsym-table-2.test b/test/elf/Mips/dynsym-table-2.test new file mode 100644 index 000000000000..538aa758910e --- /dev/null +++ b/test/elf/Mips/dynsym-table-2.test @@ -0,0 +1,105 @@ +# Check that LLD does not populate a shared library dynamic symbol table +# by unnecessary symbols. +# 1. bar.so defines T2 and T3 +# 2. foo.so defines T1 and references T2 +# 4. foo.so dynamic table should contain T1 and T2 entries only + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-bar.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-foo.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t-bar.so %t-bar.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t-foo.so %t-foo.o %t-bar.so +# RUN: llvm-readobj -dt -dynamic-table %t-foo.so | FileCheck %s + +# CHECK: DynamicSymbols [ +# 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: T1@ ({{.*}}) +# CHECK-NEXT: Value: {{.*}} +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text (0x4) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T2@ ({{.*}}) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: 0x00000003 PLTGOT 0x1000 +# CHECK-NEXT: 0x00000001 NEEDED SharedLibrary (dynsym-table-2.test.tmp-bar.so) +# CHECK-NEXT: 0x00000000 NULL 0x0 + +# bar.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 +Symbols: + Global: + - Name: T2 + Type: STT_FUNC + Section: .text + Size: 0x04 + - Name: T3 + Type: STT_FUNC + Section: .text + Value: 0x04 + Size: 0x04 + +# foo.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x08 + Info: .text + Relocations: + - Offset: 0 + Symbol: T2 + Type: R_MIPS_CALL16 +Symbols: + Global: + - Name: T1 + Type: STT_FUNC + Section: .text + Size: 0x08 + - Name: T2 +... diff --git a/test/elf/Mips/e-flags-merge-1-64.test b/test/elf/Mips/e-flags-merge-1-64.test new file mode 100644 index 000000000000..d5719539baaa --- /dev/null +++ b/test/elf/Mips/e-flags-merge-1-64.test @@ -0,0 +1,30 @@ +# Check that the linker shows an error when object +# file has unsupported ASE flags. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-mips16.o +# RUN: not lld -flavor gnu -target mips64el -e T -o %t.exe %t-mips16.o 2>&1 | \ +# RUN: FileCheck -check-prefix=MIPS16 %s + +# MIPS16: Unsupported extension: MIPS16 + +# mips16.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64, EF_MIPS_ARCH_ASE_M16] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +Symbols: + Global: + - Name: T + Section: .text +... diff --git a/test/elf/Mips/e-flags-merge-1.test b/test/elf/Mips/e-flags-merge-1.test new file mode 100644 index 000000000000..1f1d7aca6c41 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-1.test @@ -0,0 +1,56 @@ +# Check that the linker shows an error when object file has missed +# or unsupported ABI and ARCH flags or unsupported ASE flags. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-no-abi.o +# RUN: not lld -flavor gnu -target mipsel -e T -o %t.exe %t-no-abi.o 2>&1 | \ +# RUN: FileCheck -check-prefix=INVALID-ABI %s + +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-mips16.o +# RUN: not lld -flavor gnu -target mipsel -e T -o %t.exe %t-mips16.o 2>&1 | \ +# RUN: FileCheck -check-prefix=MIPS16 %s + +# INVALID-ABI: Unsupported ABI +# MIPS16: Unsupported extension: MIPS16 + +# no-abi.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T + Section: .text + +# mips16.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_ARCH_ASE_M16] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T + Section: .text +... diff --git a/test/elf/Mips/e-flags-merge-10.test b/test/elf/Mips/e-flags-merge-10.test new file mode 100644 index 000000000000..a0aa45d5f2c8 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-10.test @@ -0,0 +1,43 @@ +# Check that LLD shows an error and does not link files with mips32r2 +# and mips32r6 instructions sets. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-32r2.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-32r6.o + +# RUN: not lld -flavor gnu -target mipsel -shared -o %t.so \ +# RUN: %t-32r2.o %t-32r6.o 2>&1 | FileCheck %s + +# CHECK: Linking modules with incompatible ISA + +# 32r2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# 32r6.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 +... diff --git a/test/elf/Mips/e-flags-merge-11.test b/test/elf/Mips/e-flags-merge-11.test new file mode 100644 index 000000000000..b4c0039bd198 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-11.test @@ -0,0 +1,43 @@ +# Check that LLD shows an error and does not link files with mips64r2 +# and mips64r6 instructions sets. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-64r2.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-64r6.o + +# RUN: not lld -flavor gnu -target mips64el -shared -o %t.so \ +# RUN: %t-64r2.o %t-64r6.o 2>&1 | FileCheck %s + +# CHECK: Linking modules with incompatible ISA + +# 64r2.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64R2] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# 64r6.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64R6] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 +... diff --git a/test/elf/Mips/e-flags-merge-2-64.test b/test/elf/Mips/e-flags-merge-2-64.test new file mode 100644 index 000000000000..a169e7ea1645 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-2-64.test @@ -0,0 +1,33 @@ +# Check that the linker copies ELF header flags from the single input object +# file to the generated executable + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mips64el -e T -o %t.exe %t.o +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s + +# CHECK: Flags [ (0x62000001) +# CHECK-NEXT: EF_MIPS_ARCH_64 (0x60000000) +# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000) +# CHECK-NEXT: EF_MIPS_NOREORDER (0x1) +# CHECK-NEXT: ] + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_64, EF_MIPS_NOREORDER, EF_MIPS_MICROMIPS ] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +Symbols: + Global: + - Name: T + Section: .text +... diff --git a/test/elf/Mips/e-flags-merge-2.test b/test/elf/Mips/e-flags-merge-2.test new file mode 100644 index 000000000000..41d4a0b0c45e --- /dev/null +++ b/test/elf/Mips/e-flags-merge-2.test @@ -0,0 +1,35 @@ +# Check that the linker copies ELF header flags from the single input object +# file to the generated executable + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -e T -o %t.exe %t.o +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s + +# CHECK: Flags [ (0x52001001) +# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000) +# CHECK-NEXT: EF_MIPS_ARCH_32 (0x50000000) +# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000) +# CHECK-NEXT: EF_MIPS_NOREORDER (0x1) +# CHECK-NEXT: ] + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, + EF_MIPS_NOREORDER, EF_MIPS_MICROMIPS] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T + Section: .text +... diff --git a/test/elf/Mips/e-flags-merge-3-64.test b/test/elf/Mips/e-flags-merge-3-64.test new file mode 100644 index 000000000000..54065a63fb94 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-3-64.test @@ -0,0 +1,130 @@ +# Check PIC/CPIC flags merging in case of multiple input objects. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-none.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-cpic.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-pic.o +# RUN: yaml2obj -format=elf -docnum 4 %s > %t-both.o + +# RUN: lld -flavor gnu -target mips64el -e T1 -o %t-abi1.exe \ +# RUN: %t-none.o %t-pic.o 2>&1 | FileCheck -check-prefix=ABI-CALLS-WARN %s +# RUN: llvm-readobj -file-headers %t-abi1.exe \ +# RUN: | FileCheck -check-prefix=ABI-CALLS1 %s + +# RUN: lld -flavor gnu -target mips64el -e T1 -o %t-abi2.exe \ +# RUN: %t-cpic.o %t-none.o 2>&1 | FileCheck -check-prefix=ABI-CALLS-WARN %s +# RUN: llvm-readobj -file-headers %t-abi2.exe \ +# RUN: | FileCheck -check-prefix=ABI-CALLS2 %s + +# RUN: lld -flavor gnu -target mips64el -e T2 -o %t-cpic.exe %t-cpic.o %t-pic.o +# RUN: llvm-readobj -file-headers %t-cpic.exe | FileCheck -check-prefix=CPIC %s + +# RUN: lld -flavor gnu -target mips64el -e T3 -o %t-both.exe %t-pic.o %t-both.o +# RUN: llvm-readobj -file-headers %t-both.exe | FileCheck -check-prefix=BOTH %s + +# ABI-CALLS-WARN: lld warning: linking abicalls and non-abicalls files + +# ABI-CALLS1: Flags [ (0x60000004) +# ABI-CALLS1-NEXT: EF_MIPS_ARCH_64 (0x60000000) +# ABI-CALLS1-NEXT: EF_MIPS_CPIC (0x4) +# ABI-CALLS1-NEXT: ] + +# ABI-CALLS2: Flags [ (0x60000004) +# ABI-CALLS2-NEXT: EF_MIPS_ARCH_64 (0x60000000) +# ABI-CALLS2-NEXT: EF_MIPS_CPIC (0x4) +# ABI-CALLS2-NEXT: ] + +# CPIC: Flags [ (0x60000004) +# CPIC-NEXT: EF_MIPS_ARCH_64 (0x60000000) +# CPIC-NEXT: EF_MIPS_CPIC (0x4) +# CPIC-NEXT: ] + +# BOTH: Flags [ (0x60000006) +# BOTH-NEXT: EF_MIPS_ARCH_64 (0x60000000) +# BOTH-NEXT: EF_MIPS_CPIC (0x4) +# BOTH-NEXT: EF_MIPS_PIC (0x2) +# BOTH-NEXT: ] + +# none.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +Symbols: + Global: + - Name: T1 + Section: .text + +# cpic.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64, EF_MIPS_CPIC] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +Symbols: + Global: + - Name: T2 + Section: .text + +# pic.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64, EF_MIPS_PIC] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +Symbols: + Global: + - Name: T3 + Section: .text + +# both.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64, EF_MIPS_CPIC, EF_MIPS_PIC] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +Symbols: + Global: + - Name: T4 + Section: .text +... diff --git a/test/elf/Mips/e-flags-merge-3.test b/test/elf/Mips/e-flags-merge-3.test new file mode 100644 index 000000000000..e2d9f6c2e2fc --- /dev/null +++ b/test/elf/Mips/e-flags-merge-3.test @@ -0,0 +1,134 @@ +# Check PIC/CPIC flags merging in case of multiple input objects. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-none.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-cpic.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-pic.o +# RUN: yaml2obj -format=elf -docnum 4 %s > %t-both.o + +# RUN: lld -flavor gnu -target mipsel -e T1 -o %t-abi1.exe \ +# RUN: %t-none.o %t-pic.o 2>&1 | FileCheck -check-prefix=ABI-CALLS-WARN %s +# RUN: llvm-readobj -file-headers %t-abi1.exe \ +# RUN: | FileCheck -check-prefix=ABI-CALLS1 %s + +# RUN: lld -flavor gnu -target mipsel -e T1 -o %t-abi2.exe \ +# RUN: %t-cpic.o %t-none.o 2>&1 | FileCheck -check-prefix=ABI-CALLS-WARN %s +# RUN: llvm-readobj -file-headers %t-abi2.exe \ +# RUN: | FileCheck -check-prefix=ABI-CALLS2 %s + +# RUN: lld -flavor gnu -target mipsel -e T2 -o %t-cpic.exe %t-cpic.o %t-pic.o +# RUN: llvm-readobj -file-headers %t-cpic.exe | FileCheck -check-prefix=CPIC %s + +# RUN: lld -flavor gnu -target mipsel -e T3 -o %t-both.exe %t-pic.o %t-both.o +# RUN: llvm-readobj -file-headers %t-both.exe | FileCheck -check-prefix=BOTH %s + +# ABI-CALLS-WARN: lld warning: linking abicalls and non-abicalls files + +# ABI-CALLS1: Flags [ (0x50001004) +# ABI-CALLS1-NEXT: EF_MIPS_ABI_O32 (0x1000) +# ABI-CALLS1-NEXT: EF_MIPS_ARCH_32 (0x50000000) +# ABI-CALLS1-NEXT: EF_MIPS_CPIC (0x4) +# ABI-CALLS1-NEXT: ] + +# ABI-CALLS2: Flags [ (0x50001004) +# ABI-CALLS2-NEXT: EF_MIPS_ABI_O32 (0x1000) +# ABI-CALLS2-NEXT: EF_MIPS_ARCH_32 (0x50000000) +# ABI-CALLS2-NEXT: EF_MIPS_CPIC (0x4) +# ABI-CALLS2-NEXT: ] + +# CPIC: Flags [ (0x50001004) +# CPIC-NEXT: EF_MIPS_ABI_O32 (0x1000) +# CPIC-NEXT: EF_MIPS_ARCH_32 (0x50000000) +# CPIC-NEXT: EF_MIPS_CPIC (0x4) +# CPIC-NEXT: ] + +# BOTH: Flags [ (0x50001006) +# BOTH-NEXT: EF_MIPS_ABI_O32 (0x1000) +# BOTH-NEXT: EF_MIPS_ARCH_32 (0x50000000) +# BOTH-NEXT: EF_MIPS_CPIC (0x4) +# BOTH-NEXT: EF_MIPS_PIC (0x2) +# BOTH-NEXT: ] + +# none.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T1 + Section: .text + +# cpic.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T2 + Section: .text + +# pic.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_PIC] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T3 + Section: .text + +# both.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_PIC] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T4 + Section: .text +... diff --git a/test/elf/Mips/e-flags-merge-4-64.test b/test/elf/Mips/e-flags-merge-4-64.test new file mode 100644 index 000000000000..9ffa61343711 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-4-64.test @@ -0,0 +1,64 @@ +# Check ELF flags merging. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-none.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-noreorder.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-micro.o + +# RUN: lld -flavor gnu -target mips64el -shared -o %t.so \ +# RUN: %t-none.o %t-noreorder.o %t-micro.o +# RUN: llvm-readobj -file-headers %t.so | FileCheck %s + +# CHECK: Flags [ (0x82000001) +# CHECK-NEXT: EF_MIPS_ARCH_64R2 (0x80000000) +# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000) +# CHECK-NEXT: EF_MIPS_NOREORDER (0x1) +# CHECK-NEXT: ] + +# none.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_5] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +# noreorder.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64, EF_MIPS_NOREORDER] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +# micro.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64R2, EF_MIPS_MICROMIPS] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 +... diff --git a/test/elf/Mips/e-flags-merge-4.test b/test/elf/Mips/e-flags-merge-4.test new file mode 100644 index 000000000000..096b04d676e9 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-4.test @@ -0,0 +1,65 @@ +# Check ELF flags merging. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-none.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-noreorder.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-micro.o + +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so \ +# RUN: %t-none.o %t-noreorder.o %t-micro.o +# RUN: llvm-readobj -file-headers %t.so | FileCheck %s + +# CHECK: Flags [ (0x52001001) +# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000) +# CHECK-NEXT: EF_MIPS_ARCH_32 (0x50000000) +# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000) +# CHECK-NEXT: EF_MIPS_NOREORDER (0x1) +# CHECK-NEXT: ] + +# none.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# noreorder.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_NOREORDER] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# micro.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_MICROMIPS] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 +... diff --git a/test/elf/Mips/e-flags-merge-5-64.test b/test/elf/Mips/e-flags-merge-5-64.test new file mode 100644 index 000000000000..e629aedbc154 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-5-64.test @@ -0,0 +1,42 @@ +# Check that LLD does not allow to mix 32 and 64-bit MIPS object files. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-32.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-64.o + +# RUN: not lld -flavor gnu -target mips64el -shared -o %t.so \ +# RUN: %t-32.o %t-64.o 2>&1 | FileCheck %s + +# CHECK: Bitness is incompatible with that of the selected target + +# 32.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# 64.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 +... diff --git a/test/elf/Mips/e-flags-merge-5.test b/test/elf/Mips/e-flags-merge-5.test new file mode 100644 index 000000000000..3b5b397ab780 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-5.test @@ -0,0 +1,42 @@ +# Check that LLD does not allow to mix 32 and 64-bit MIPS object files. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-32.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-64.o + +# RUN: not lld -flavor gnu -target mipsel -shared -o %t.so \ +# RUN: %t-32.o %t-64.o 2>&1 | FileCheck %s + +# CHECK: Bitness is incompatible with that of the selected target + +# 32.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# 64.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 +... diff --git a/test/elf/Mips/e-flags-merge-6-64.test b/test/elf/Mips/e-flags-merge-6-64.test new file mode 100644 index 000000000000..fbc32b7135b2 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-6-64.test @@ -0,0 +1,79 @@ +# Check selecting ELF header ARCH flag. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-m3.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-m5.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-m64.o +# RUN: yaml2obj -format=elf -docnum 4 %s > %t-m64r2.o + +# RUN: lld -flavor gnu -target mips64el -shared -o %t.so \ +# RUN: %t-m64.o %t-m5.o %t-m64r2.o %t-m3.o +# RUN: llvm-readobj -file-headers %t.so | FileCheck %s + +# CHECK: Flags [ (0x80000000) +# CHECK-NEXT: EF_MIPS_ARCH_64R2 (0x80000000) +# CHECK-NEXT: ] + +# m3.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_3] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +# m5.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_5] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +# m64.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +# m64r2.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64R2] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 +... diff --git a/test/elf/Mips/e-flags-merge-6.test b/test/elf/Mips/e-flags-merge-6.test new file mode 100644 index 000000000000..759c8b63c97d --- /dev/null +++ b/test/elf/Mips/e-flags-merge-6.test @@ -0,0 +1,80 @@ +# Check selecting ELF header ARCH flag. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-m1.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-m2.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-m32.o +# RUN: yaml2obj -format=elf -docnum 4 %s > %t-m32r2.o + +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so \ +# RUN: %t-m32.o %t-m2.o %t-m32r2.o %t-m1.o +# RUN: llvm-readobj -file-headers %t.so | FileCheck %s + +# CHECK: Flags [ (0x70001000) +# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000) +# CHECK-NEXT: EF_MIPS_ARCH_32R2 (0x70000000) +# CHECK-NEXT: ] + +# m1.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_1] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# m2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_2] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# m32.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# m32r2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 +... diff --git a/test/elf/Mips/e-flags-merge-7-64.test b/test/elf/Mips/e-flags-merge-7-64.test new file mode 100644 index 000000000000..07ed6bb54836 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-7-64.test @@ -0,0 +1,42 @@ +# Check that LLD does not allow to mix nan2008 and legacy MIPS object files. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-2008.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-legacy.o + +# RUN: not lld -flavor gnu -target mips64el -shared -o %t.so \ +# RUN: %t-2008.o %t-legacy.o 2>&1 | FileCheck %s + +# CHECK: Linking -mnan=2008 and -mnan=legacy modules + +# 2008.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64, EF_MIPS_NAN2008] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +# legacy.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 +... diff --git a/test/elf/Mips/e-flags-merge-7.test b/test/elf/Mips/e-flags-merge-7.test new file mode 100644 index 000000000000..7e114ff968fe --- /dev/null +++ b/test/elf/Mips/e-flags-merge-7.test @@ -0,0 +1,42 @@ +# Check that LLD does not allow to mix nan2008 and legacy MIPS object files. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-2008.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-legacy.o + +# RUN: not lld -flavor gnu -target mipsel -shared -o %t.so \ +# RUN: %t-2008.o %t-legacy.o 2>&1 | FileCheck %s + +# CHECK: Linking -mnan=2008 and -mnan=legacy modules + +# 2008.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_NAN2008] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# legacy.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 +... diff --git a/test/elf/Mips/e-flags-merge-8.test b/test/elf/Mips/e-flags-merge-8.test new file mode 100644 index 000000000000..57af77d70260 --- /dev/null +++ b/test/elf/Mips/e-flags-merge-8.test @@ -0,0 +1,65 @@ +# Check that LLD links files with mips32 and mips64 instructions +# if all these files satisfy O32 ABI. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-32.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-64.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-64r2.o + +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-32.o %t-64.o %t-64r2.o +# RUN: llvm-readobj -file-headers %t.so | FileCheck %s + +# CHECK: Flags [ (0x80001100) +# CHECK-NEXT: EF_MIPS_32BITMODE (0x100) +# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000) +# CHECK-NEXT: EF_MIPS_ARCH_64R2 (0x80000000) +# CHECK-NEXT: ] + + +# 32.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# 64.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_64, EF_MIPS_32BITMODE] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# 64r2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_64R2, EF_MIPS_32BITMODE] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 +... diff --git a/test/elf/Mips/e-flags-merge-9.test b/test/elf/Mips/e-flags-merge-9.test new file mode 100644 index 000000000000..dea32f07cb9e --- /dev/null +++ b/test/elf/Mips/e-flags-merge-9.test @@ -0,0 +1,43 @@ +# Check that LLD shows an error and does not link files with mips32r2 +# and mips64 instructions sets. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-32r2.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-64.o + +# RUN: not lld -flavor gnu -target mipsel -shared -o %t.so \ +# RUN: %t-32r2.o %t-64.o 2>&1 | FileCheck %s + +# CHECK: Linking modules with incompatible ISA + +# 32r2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +# 64.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_64, EF_MIPS_32BITMODE] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 +... diff --git a/test/elf/Mips/entry-name.test b/test/elf/Mips/entry-name.test new file mode 100644 index 000000000000..b10adc68bde8 --- /dev/null +++ b/test/elf/Mips/entry-name.test @@ -0,0 +1,26 @@ +# Check name of executable entry symbol. +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel --noinhibit-exec -o %t.exe %t.o +# RUN: llvm-nm %t.exe | FileCheck %s + +# CHECK: U __start +# CHECK: 00400108 T main + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: main + Section: .text diff --git a/test/elf/Mips/exe-dynamic.test b/test/elf/Mips/exe-dynamic.test new file mode 100644 index 000000000000..28d2b13fbce8 --- /dev/null +++ b/test/elf/Mips/exe-dynamic.test @@ -0,0 +1,108 @@ +# Check MIPS specific tags in the dynamic table in case executable linking. + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dynamic-table %t.exe | FileCheck %s + +# CHECK: Format: ELF32-mips +# CHECK: Arch: mipsel +# CHECK: AddressSize: 32bit +# CHECK: LoadName: +# CHECK: DynamicSection [ (18 entries) +# CHECK: Tag Type Name/Value +# CHECK-NEXT: 0x00000004 HASH 0x400104 +# CHECK-NEXT: 0x00000005 STRTAB 0x400138 +# CHECK-NEXT: 0x00000006 SYMTAB 0x400118 +# CHECK-NEXT: 0x0000000A STRSZ 28 (bytes) +# CHECK-NEXT: 0x0000000B SYMENT 16 (bytes) +# CHECK-NEXT: 0x00000002 PLTRELSZ 8 (bytes) +# CHECK-NEXT: 0x70000032 MIPS_PLTGOT 0x402000 +# CHECK-NEXT: 0x00000014 PLTREL REL +# CHECK-NEXT: 0x00000017 JMPREL 0x400154 +# CHECK-NEXT: 0x70000001 MIPS_RLD_VERSION 1 +# CHECK-NEXT: 0x70000005 MIPS_FLAGS NOTPOT +# CHECK-NEXT: 0x70000006 MIPS_BASE_ADDRESS 0x400000 +# CHECK-NEXT: 0x7000000A MIPS_LOCAL_GOTNO 2 +# CHECK-NEXT: 0x70000011 MIPS_SYMTABNO 2 +# CHECK-NEXT: 0x70000013 MIPS_GOTSYM 0x2 +# CHECK-NEXT: 0x00000003 PLTGOT 0x401000 +# CHECK-NEXT: 0x00000001 NEEDED SharedLibrary (exe-dynamic.test.tmp.so) +# CHECK-NEXT: 0x00000000 NULL 0x0 +# CHECK-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: 0000000C000000000000000C000000000000000C00000000 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_26 + Addend: 0 + - Offset: 0x08 + Symbol: .text + Type: R_MIPS_26 + Addend: 0 + - Offset: 0x10 + Symbol: glob + Type: R_MIPS_26 + Addend: 0 + +Symbols: + Local: + - Name: loc + Section: .text + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + Value: 0x08 + - Name: T1 +... diff --git a/test/elf/Mips/exe-dynsym-micro.test b/test/elf/Mips/exe-dynsym-micro.test new file mode 100644 index 000000000000..e3b00277ef6a --- /dev/null +++ b/test/elf/Mips/exe-dynsym-micro.test @@ -0,0 +1,94 @@ +# Check that symbol referenced by an entry in the global part of GOT +# has a corresponded entry in the .dynsym section. This test covers +# the case when the GOT entry created because of the R_MICROMIPS_GOT16 +# relocation. + +# Build executable +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -e glob -o %t.exe %t.o +# RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck -check-prefix=CHECK-DYN %s + +# Build executabl (yaml format)e +# RUN: lld -flavor gnu -target mipsel -e glob \ +# RUN: --output-filetype=yaml -o %t.yaml %t.o +# RUN: FileCheck -check-prefix=CHECK-GOT %s < %t.yaml + +# CHECK-DYN: Format: ELF32-mips +# CHECK-DYN: Arch: mipsel +# CHECK-DYN: AddressSize: 32bit +# CHECK-DYN: LoadName: +# CHECK-DYN: DynamicSymbols [ +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: @ (0) +# CHECK-DYN: Value: 0x0 +# CHECK-DYN: Size: 0 +# CHECK-DYN: Binding: Local (0x0) +# CHECK-DYN: Type: None (0x0) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: Undefined (0x0) +# CHECK-DYN: } +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: weakf@ (1) +# CHECK-DYN: Value: 0x0 +# CHECK-DYN: Size: 0 +# CHECK-DYN: Binding: Weak (0x2) +# CHECK-DYN: Type: None (0x0) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: Undefined (0x0) +# CHECK-DYN: } +# CHECK-DYN: ] + +# CHECK-GOT: - type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: - type: got +# CHECK-GOT: content: [ 00, 00, 00, 80 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: - ref-name: L000 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: weakf + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x04 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: weakf + Type: R_MICROMIPS_GOT16 + +Symbols: + Global: + - Name: glob + Section: .text + Other: [ STO_MIPS_MICROMIPS ] + Weak: + - Name: weakf diff --git a/test/elf/Mips/exe-dynsym.test b/test/elf/Mips/exe-dynsym.test new file mode 100644 index 000000000000..a59916c4be4c --- /dev/null +++ b/test/elf/Mips/exe-dynsym.test @@ -0,0 +1,91 @@ +# Check that symbol referenced by an entry in the global part of GOT +# has a corresponded entry in the .dynsym section. + +# Build executable +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -e glob -o %t.exe %t.o +# RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck -check-prefix=CHECK-DYN %s + +# Build executabl (yaml format)e +# RUN: lld -flavor gnu -target mipsel -e glob \ +# RUN: --output-filetype=yaml -o %t.yaml %t.o +# RUN: FileCheck -check-prefix=CHECK-GOT %s < %t.yaml + +# CHECK-DYN: Format: ELF32-mips +# CHECK-DYN: Arch: mipsel +# CHECK-DYN: AddressSize: 32bit +# CHECK-DYN: LoadName: +# CHECK-DYN: DynamicSymbols [ +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: @ (0) +# CHECK-DYN: Value: 0x0 +# CHECK-DYN: Size: 0 +# CHECK-DYN: Binding: Local (0x0) +# CHECK-DYN: Type: None (0x0) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: Undefined (0x0) +# CHECK-DYN: } +# CHECK-DYN: Symbol { +# CHECK-DYN: Name: weakf@ (1) +# CHECK-DYN: Value: 0x0 +# CHECK-DYN: Size: 0 +# CHECK-DYN: Binding: Weak (0x2) +# CHECK-DYN: Type: None (0x0) +# CHECK-DYN: Other: 0 +# CHECK-DYN: Section: Undefined (0x0) +# CHECK-DYN: } +# CHECK-DYN: ] + +# CHECK-GOT: - type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: - type: got +# CHECK-GOT: content: [ 00, 00, 00, 80 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: - ref-name: L000 +# CHECK-GOT: type: got +# CHECK-GOT: content: [ 00, 00, 00, 00 ] +# CHECK-GOT: alignment: 2^2 +# CHECK-GOT: section-choice: custom-required +# CHECK-GOT: section-name: .got +# CHECK-GOT: permissions: rw- +# CHECK-GOT: references: +# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT +# CHECK-GOT: offset: 0 +# CHECK-GOT: target: weakf + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x04 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: weakf + Type: R_MIPS_GOT16 + +Symbols: + Global: + - Name: glob + Section: .text + Weak: + - Name: weakf diff --git a/test/elf/Mips/exe-fileheader-64.test b/test/elf/Mips/exe-fileheader-64.test new file mode 100644 index 000000000000..63baff53e678 --- /dev/null +++ b/test/elf/Mips/exe-fileheader-64.test @@ -0,0 +1,66 @@ +# Check ELF Header for 64-bit executable file. + +# Build executable +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target mips64el -e glob -o %t.exe %t-o.o +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s + +# CHECK: Format: ELF64-mips +# CHECK: Arch: mips64el +# CHECK: AddressSize: 64bit +# CHECK: LoadName: +# CHECK: ElfHeader { +# CHECK: Ident { +# CHECK: Magic: (7F 45 4C 46) +# CHECK: Class: 64-bit (0x2) +# CHECK: DataEncoding: LittleEndian (0x1) +# CHECK: FileVersion: 1 +# CHECK: OS/ABI: SystemV (0x0) +# CHECK: ABIVersion: 0 +# CHECK: Unused: (00 00 00 00 00 00 00) +# CHECK: } +# CHECK: Type: Executable (0x2) +# CHECK: Machine: EM_MIPS (0x8) +# CHECK: Version: 1 +# CHECK: Entry: 0x1200001A0 +# CHECK: ProgramHeaderOffset: 0x40 +# CHECK: SectionHeaderOffset: 0x1300 +# CHECK: Flags [ (0x60000007) +# CHECK: EF_MIPS_ARCH_64 (0x60000000) +# CHECK: EF_MIPS_CPIC (0x4) +# CHECK: EF_MIPS_NOREORDER (0x1) +# CHECK: EF_MIPS_PIC (0x2) +# CHECK: ] +# CHECK: HeaderSize: 64 +# CHECK: ProgramHeaderEntrySize: 56 +# CHECK: ProgramHeaderCount: 5 +# CHECK: SectionHeaderEntrySize: 64 +# CHECK: SectionHeaderCount: 11 +# CHECK: StringTableSectionIndex: 8 +# CHECK: } + +# o.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ARCH_64 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text +... diff --git a/test/elf/Mips/exe-fileheader-micro-64.test b/test/elf/Mips/exe-fileheader-micro-64.test new file mode 100644 index 000000000000..044c2f729f38 --- /dev/null +++ b/test/elf/Mips/exe-fileheader-micro-64.test @@ -0,0 +1,68 @@ +# Check ELF Header for 64-bit executable file in case of microMIPS entry symbol. + +# Build executable +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target mips64el -e glob -o %t.exe %t-o.o +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s + +# CHECK: Format: ELF64-mips +# CHECK: Arch: mips64el +# CHECK: AddressSize: 64bit +# CHECK: LoadName: +# CHECK: ElfHeader { +# CHECK: Ident { +# CHECK: Magic: (7F 45 4C 46) +# CHECK: Class: 64-bit (0x2) +# CHECK: DataEncoding: LittleEndian (0x1) +# CHECK: FileVersion: 1 +# CHECK: OS/ABI: SystemV (0x0) +# CHECK: ABIVersion: 0 +# CHECK: Unused: (00 00 00 00 00 00 00) +# CHECK: } +# CHECK: Type: Executable (0x2) +# CHECK: Machine: EM_MIPS (0x8) +# CHECK: Version: 1 +# CHECK: Entry: 0x1200001A1 +# CHECK: ProgramHeaderOffset: 0x40 +# CHECK: SectionHeaderOffset: 0x1300 +# CHECK: Flags [ (0x82000007) +# CHECK: EF_MIPS_ARCH_64R2 (0x80000000) +# CHECK: EF_MIPS_CPIC (0x4) +# CHECK: EF_MIPS_MICROMIPS (0x2000000) +# CHECK: EF_MIPS_NOREORDER (0x1) +# CHECK: EF_MIPS_PIC (0x2) +# CHECK: ] +# CHECK: HeaderSize: 64 +# CHECK: ProgramHeaderEntrySize: 56 +# CHECK: ProgramHeaderCount: 5 +# CHECK: SectionHeaderEntrySize: 64 +# CHECK: SectionHeaderCount: 11 +# CHECK: StringTableSectionIndex: 8 +# CHECK: } + +# o.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_MICROMIPS, EF_MIPS_ARCH_64R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + Other: [ STO_MIPS_MICROMIPS ] +... diff --git a/test/elf/Mips/exe-fileheader-micro.test b/test/elf/Mips/exe-fileheader-micro.test new file mode 100644 index 000000000000..351f299b04cd --- /dev/null +++ b/test/elf/Mips/exe-fileheader-micro.test @@ -0,0 +1,69 @@ +# Check ELF Header for non-pic executable file in case +# of microMIPS entry symbol. + +# Build executable +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e glob -o %t.exe %t-o.o +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s + +# CHECK: Format: ELF32-mips +# CHECK-NEXT: Arch: mipsel +# CHECK-NEXT: AddressSize: 32bit +# CHECK-NEXT: LoadName: +# CHECK-NEXT: ElfHeader { +# CHECK-NEXT: Ident { +# CHECK-NEXT: Magic: (7F 45 4C 46) +# CHECK-NEXT: Class: 32-bit (0x1) +# CHECK-NEXT: DataEncoding: LittleEndian (0x1) +# CHECK-NEXT: FileVersion: 1 +# CHECK-NEXT: OS/ABI: SystemV (0x0) +# CHECK-NEXT: ABIVersion: 0 +# CHECK-NEXT: Unused: (00 00 00 00 00 00 00) +# CHECK-NEXT: } +# CHECK-NEXT: Type: Executable (0x2) +# CHECK-NEXT: Machine: EM_MIPS (0x8) +# CHECK-NEXT: Version: 1 +# CHECK-NEXT: Entry: 0x400109 +# CHECK-NEXT: ProgramHeaderOffset: 0x34 +# CHECK-NEXT: SectionHeaderOffset: 0x1268 +# CHECK-NEXT: Flags [ (0x72001005) +# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000) +# CHECK-NEXT: EF_MIPS_ARCH_32R2 (0x70000000) +# CHECK-NEXT: EF_MIPS_CPIC (0x4) +# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000) +# CHECK-NEXT: EF_MIPS_NOREORDER (0x1) +# CHECK-NEXT: ] +# CHECK-NEXT: HeaderSize: 52 +# CHECK-NEXT: ProgramHeaderEntrySize: 32 +# CHECK-NEXT: ProgramHeaderCount: 5 +# CHECK-NEXT: SectionHeaderEntrySize: 40 +# CHECK-NEXT: SectionHeaderCount: 11 +# CHECK-NEXT: StringTableSectionIndex: 8 +# CHECK-NEXT: } + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + Other: [ STO_MIPS_MICROMIPS ] +... diff --git a/test/elf/Mips/exe-fileheader.test b/test/elf/Mips/exe-fileheader.test new file mode 100644 index 000000000000..ff0d38198c31 --- /dev/null +++ b/test/elf/Mips/exe-fileheader.test @@ -0,0 +1,105 @@ +# Check ELF Header for non-pic executable file. + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s + +# CHECK: Format: ELF32-mips +# CHECK: Arch: mipsel +# CHECK: AddressSize: 32bit +# CHECK: LoadName: +# CHECK: ElfHeader { +# CHECK: Ident { +# CHECK: Magic: (7F 45 4C 46) +# CHECK: Class: 32-bit (0x1) +# CHECK: DataEncoding: LittleEndian (0x1) +# CHECK: FileVersion: 1 +# CHECK: OS/ABI: SystemV (0x0) +# CHECK: ABIVersion: 1 +# CHECK: Unused: (00 00 00 00 00 00 00) +# CHECK: } +# CHECK: Type: Executable (0x2) +# CHECK: Machine: EM_MIPS (0x8) +# CHECK: Version: 1 +# CHECK: Entry: 0x400190 +# CHECK: ProgramHeaderOffset: 0x34 +# CHECK: SectionHeaderOffset: 0x2280 +# CHECK: Flags [ (0x70001005) +# CHECK: EF_MIPS_ABI_O32 (0x1000) +# CHECK: EF_MIPS_ARCH_32R2 (0x70000000) +# CHECK: EF_MIPS_CPIC (0x4) +# CHECK: EF_MIPS_NOREORDER (0x1) +# CHECK: ] +# CHECK: HeaderSize: 52 +# CHECK: ProgramHeaderEntrySize: 32 +# CHECK: ProgramHeaderCount: 6 +# CHECK: SectionHeaderEntrySize: 40 +# CHECK: SectionHeaderCount: 14 +# CHECK: StringTableSectionIndex: 11 +# CHECK: } + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_26 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + - Name: T1 +... diff --git a/test/elf/Mips/exe-got-micro.test b/test/elf/Mips/exe-got-micro.test new file mode 100644 index 000000000000..d2d1588ab964 --- /dev/null +++ b/test/elf/Mips/exe-got-micro.test @@ -0,0 +1,115 @@ +# Check that external symbol defined in the executable file +# and referenced by R_MICROMIPS_CALL16 relocation has a corresponded +# entry in the local GOT section. +# +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e glob \ +# RUN: --output-filetype=yaml -o %t.exe %t-o.o %t.so +# RUN: FileCheck -check-prefix=GOT %s < %t.exe + +# GOT header +# GOT: - type: got +# GOT: content: [ 00, 00, 00, 00 ] +# GOT: alignment: 2^2 +# GOT: section-choice: custom-required +# GOT: section-name: .got +# GOT: permissions: rw- +# GOT: - type: got +# GOT: content: [ 00, 00, 00, 80 ] +# GOT: alignment: 2^2 +# GOT: section-choice: custom-required +# GOT: section-name: .got +# GOT: permissions: rw- +# Local GOT entry for 'glob' symbol +# GOT: - ref-name: L000 +# GOT: type: got +# GOT: content: [ 00, 00, 00, 00 ] +# GOT: alignment: 2^2 +# GOT: section-choice: custom-required +# GOT: section-name: .got +# GOT: permissions: rw- +# GOT: references: +# GOT: - kind: R_MIPS_32 +# GOT: offset: 0 +# GOT: target: glob +# Global GOT entry for 'T1' symbol +# GOT: - ref-name: L001 +# GOT: type: got +# GOT: content: [ 00, 00, 00, 00 ] +# GOT: alignment: 2^2 +# GOT: section-choice: custom-required +# GOT: section-name: .got +# GOT: permissions: rw- +# GOT: references: +# GOT: - kind: LLD_R_MIPS_GLOBAL_GOT +# GOT: offset: 0 +# GOT: target: T1 + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: glob + Type: R_MICROMIPS_CALL16 + - Offset: 0x04 + Symbol: T1 + Type: R_MICROMIPS_CALL16 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 +... diff --git a/test/elf/Mips/exe-got.test b/test/elf/Mips/exe-got.test new file mode 100644 index 000000000000..7254c87530bc --- /dev/null +++ b/test/elf/Mips/exe-got.test @@ -0,0 +1,116 @@ +# Check that external symbol defined in the executable file +# and referenced by R_MIPS_CALL16 relocation has a corresponded +# entry in the local GOT section. +# +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e glob \ +# RUN: --output-filetype=yaml -o %t.exe %t-o.o %t.so +# RUN: FileCheck -check-prefix=GOT %s < %t.exe + +# GOT header +# GOT: - type: got +# GOT: content: [ 00, 00, 00, 00 ] +# GOT: alignment: 2^2 +# GOT: section-choice: custom-required +# GOT: section-name: .got +# GOT: permissions: rw- +# GOT: - type: got +# GOT: content: [ 00, 00, 00, 80 ] +# GOT: alignment: 2^2 +# GOT: section-choice: custom-required +# GOT: section-name: .got +# GOT: permissions: rw- +# Local GOT entry for 'glob' symbol +# GOT: - ref-name: L000 +# GOT: type: got +# GOT: content: [ 00, 00, 00, 00 ] +# GOT: alignment: 2^2 +# GOT: section-choice: custom-required +# GOT: section-name: .got +# GOT: permissions: rw- +# GOT: references: +# GOT: - kind: R_MIPS_32 +# GOT: offset: 0 +# GOT: target: glob +# Global GOT entry for 'T1' symbol +# GOT: - ref-name: L001 +# GOT: type: got +# GOT: content: [ 00, 00, 00, 00 ] +# GOT: alignment: 2^2 +# GOT: section-choice: custom-required +# GOT: section-name: .got +# GOT: permissions: rw- +# GOT: references: +# GOT: - kind: LLD_R_MIPS_GLOBAL_GOT +# GOT: offset: 0 +# GOT: target: T1 + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: glob + Type: R_MIPS_CALL16 + Addend: 0 + - Offset: 0x04 + Symbol: T1 + Type: R_MIPS_CALL16 + Addend: 0 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + - Name: T1 +... diff --git a/test/elf/Mips/got-page-32.test b/test/elf/Mips/got-page-32.test new file mode 100644 index 000000000000..00376da78663 --- /dev/null +++ b/test/elf/Mips/got-page-32.test @@ -0,0 +1,203 @@ +# Check handling of R_MIPS_GOT_DISP / PAGE / OFST relocations. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -symbols -dyn-symbols -mips-plt-got %t.exe \ +# RUN: | FileCheck -check-prefix=GOT %s +# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s + +# GOT: Symbol { +# GOT: Name: T0 (1) +# GOT-NEXT: Value: 0x400154 +# GOT: Symbol { +# GOT: Name: LT1 (4) +# GOT-NEXT: Value: 0x40017C +# GOT: Symbol { +# GOT: Name: LT2 (8) +# GOT-NEXT: Value: 0x400180 +# GOT: Symbol { +# GOT: Name: T1@ (1) +# GOT-NEXT: Value: 0x0 +# GOT: Symbol { +# GOT: Name: T2@ (4) +# GOT-NEXT: Value: 0x0 + +# GOT: Primary GOT { +# GOT-NEXT: Canonical gp value: 0x408FF0 +# GOT-NEXT: Reserved entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x401000 +# GOT-NEXT: Access: -32752 +# GOT-NEXT: Initial: 0x0 +# GOT-NEXT: Purpose: Lazy resolver +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x401004 +# GOT-NEXT: Access: -32748 +# GOT-NEXT: Initial: 0x80000000 +# GOT-NEXT: Purpose: Module pointer (GNU extension) +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Local entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x401008 +# GOT-NEXT: Access: -32744 +# GOT-NEXT: Initial: 0x40017C +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x40100C +# GOT-NEXT: Access: -32740 +# GOT-NEXT: Initial: 0x400000 +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x401010 +# GOT-NEXT: Access: -32736 +# GOT-NEXT: Initial: 0x400000 +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Global entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x401014 +# GOT-NEXT: Access: -32732 +# GOT-NEXT: Initial: 0x0 +# GOT-NEXT: Value: 0x0 +# GOT-NEXT: Type: Function (0x2) +# GOT-NEXT: Section: Undefined (0x0) +# GOT-NEXT: Name: T1@ (1) +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x401018 +# GOT-NEXT: Access: -32728 +# GOT-NEXT: Initial: 0x0 +# GOT-NEXT: Value: 0x0 +# GOT-NEXT: Type: Function (0x2) +# GOT-NEXT: Section: Undefined (0x0) +# GOT-NEXT: Name: T2@ (4) +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Number of TLS and multi-GOT entries: 0 +# GOT-NEXT: } + +# RAW: Contents of section .text: +# RAW-NEXT: 400154 24800000 18800000 24800000 28800000 $.......$...(... +# ^ = -32732 (T1) +# ^ = -32744 (LT1) +# ^ -32732 (T1) +# ^ -32728 (T2) +# RAW-NEXT: 400164 1c800000 20800000 00000000 00000000 .... ........... +# ^ -32740 (PAGE) +# ^ -32736 (PAGE) +# ^ T1 OFST +# ^ T2 OFST +# RAW-NEXT: 400174 7c010000 80010000 00000000 00000000 |............... +# ^ LT1 OFST +# ^ LT2 OFST + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_32, EF_MIPS_ABI_O32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 8 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 0x4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 0x4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_32, EF_MIPS_ABI_O32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x4 + Size: 0x30 + + - Name: .rel.text + Type: SHT_RELA + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x0 + Symbol: T1 + Type: R_MIPS_GOT_DISP + - Offset: 0x4 + Symbol: LT1 + Type: R_MIPS_GOT_DISP + - Offset: 0x8 + Symbol: T1 + Type: R_MIPS_GOT_PAGE + - Offset: 0xC + Symbol: T2 + Type: R_MIPS_GOT_PAGE + - Offset: 0x10 + Symbol: LT1 + Type: R_MIPS_GOT_PAGE + - Offset: 0x14 + Symbol: LT2 + Type: R_MIPS_GOT_PAGE + - Offset: 0x18 + Symbol: T1 + Type: R_MIPS_GOT_OFST + - Offset: 0x1C + Symbol: T2 + Type: R_MIPS_GOT_OFST + - Offset: 0x20 + Symbol: LT1 + Type: R_MIPS_GOT_OFST + - Offset: 0x24 + Symbol: LT2 + Type: R_MIPS_GOT_OFST + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x8 + - Name: LT1 + Type: STT_FUNC + Section: .text + Value: 0x28 + Size: 0x4 + - Name: LT2 + Type: STT_FUNC + Section: .text + Value: 0x2c + Size: 0x4 + - Name: T1 + - Name: T2 +... diff --git a/test/elf/Mips/got-page-64.test b/test/elf/Mips/got-page-64.test new file mode 100644 index 000000000000..21bece5d3242 --- /dev/null +++ b/test/elf/Mips/got-page-64.test @@ -0,0 +1,203 @@ +# Check handling of R_MIPS_GOT_DISP / PAGE / OFST relocations. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mips64el -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -symbols -dyn-symbols -mips-plt-got %t.exe \ +# RUN: | FileCheck -check-prefix=GOT %s +# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s + +# GOT: Symbol { +# GOT: Name: T0 (1) +# GOT-NEXT: Value: 0x1200001F0 +# GOT: Symbol { +# GOT: Name: LT1 (4) +# GOT-NEXT: Value: 0x120000218 +# GOT: Symbol { +# GOT: Name: LT2 (8) +# GOT-NEXT: Value: 0x12000021C +# GOT: Symbol { +# GOT: Name: T1@ (1) +# GOT-NEXT: Value: 0x0 +# GOT: Symbol { +# GOT: Name: T2@ (4) +# GOT-NEXT: Value: 0x0 + +# GOT: Primary GOT { +# GOT-NEXT: Canonical gp value: 0x120008FF0 +# GOT-NEXT: Reserved entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x120001000 +# GOT-NEXT: Access: -32752 +# GOT-NEXT: Initial: 0x0 +# GOT-NEXT: Purpose: Lazy resolver +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x120001008 +# GOT-NEXT: Access: -32744 +# GOT-NEXT: Initial: 0x8000000000000000 +# GOT-NEXT: Purpose: Module pointer (GNU extension) +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Local entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x120001010 +# GOT-NEXT: Access: -32736 +# GOT-NEXT: Initial: 0x120000218 +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x120001018 +# GOT-NEXT: Access: -32728 +# GOT-NEXT: Initial: 0x120000000 +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x120001020 +# GOT-NEXT: Access: -32720 +# GOT-NEXT: Initial: 0x120000000 +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Global entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x120001028 +# GOT-NEXT: Access: -32712 +# GOT-NEXT: Initial: 0x0 +# GOT-NEXT: Value: 0x0 +# GOT-NEXT: Type: Function (0x2) +# GOT-NEXT: Section: Undefined (0x0) +# GOT-NEXT: Name: T1@ (1) +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x120001030 +# GOT-NEXT: Access: -32704 +# GOT-NEXT: Initial: 0x0 +# GOT-NEXT: Value: 0x0 +# GOT-NEXT: Type: Function (0x2) +# GOT-NEXT: Section: Undefined (0x0) +# GOT-NEXT: Name: T2@ (4) +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Number of TLS and multi-GOT entries: 0 +# GOT-NEXT: } + +# RAW: Contents of section .text: +# RAW-NEXT: 1200001f0 38800000 20800000 38800000 40800000 8... ...8...@... +# ^ = -32712 (T1) +# ^ = -32736 (LT1) +# ^ -32712 (T1) +# ^ -32704 (T2) +# RAW-NEXT: 120000200 28800000 30800000 00000000 00000000 (...0........... +# ^ -32728 (PAGE) +# ^ -32720 (PAGE) +# ^ T1 OFST +# ^ T2 OFST +# RAW-NEXT: 120000210 18020000 1c020000 00000000 00000000 ................ +# ^ LT1 OFST +# ^ LT2 OFST + +# so.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 8 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 0x4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 0x4 + +# o.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x4 + Size: 0x30 + + - Name: .rel.text + Type: SHT_RELA + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x0 + Symbol: T1 + Type: R_MIPS_GOT_DISP + - Offset: 0x4 + Symbol: LT1 + Type: R_MIPS_GOT_DISP + - Offset: 0x8 + Symbol: T1 + Type: R_MIPS_GOT_PAGE + - Offset: 0xC + Symbol: T2 + Type: R_MIPS_GOT_PAGE + - Offset: 0x10 + Symbol: LT1 + Type: R_MIPS_GOT_PAGE + - Offset: 0x14 + Symbol: LT2 + Type: R_MIPS_GOT_PAGE + - Offset: 0x18 + Symbol: T1 + Type: R_MIPS_GOT_OFST + - Offset: 0x1C + Symbol: T2 + Type: R_MIPS_GOT_OFST + - Offset: 0x20 + Symbol: LT1 + Type: R_MIPS_GOT_OFST + - Offset: 0x24 + Symbol: LT2 + Type: R_MIPS_GOT_OFST + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x8 + - Name: LT1 + Type: STT_FUNC + Section: .text + Value: 0x28 + Size: 0x4 + - Name: LT2 + Type: STT_FUNC + Section: .text + Value: 0x2c + Size: 0x4 + - Name: T1 + - Name: T2 +... diff --git a/test/elf/Mips/got16-2.test b/test/elf/Mips/got16-2.test new file mode 100644 index 000000000000..6f576536c541 --- /dev/null +++ b/test/elf/Mips/got16-2.test @@ -0,0 +1,73 @@ +# Check handling of R_MIPS_GOT16 relocation against local +# symbols when addresses of local data cross 64 KBytes border. + +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t-exe %t-obj +# RUN: llvm-objdump -s %t-exe | FileCheck %s + +# CHECK: Contents of section .got: +# CHECK-NEXT: 40a000 00000000 00000080 00004000 00004100 ..........@...A. +# lazy module 0x400000 0x410000 +# resolver pointer for L1 for L2 + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: '00000000000000000000000000000000' + + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Address: 0x1000 + Relocations: + - Offset: 0 + Symbol: L1 + Type: R_MIPS_GOT16 + - Offset: 4 + Symbol: L1 + Type: R_MIPS_LO16 + - Offset: 8 + Symbol: L2 + Type: R_MIPS_GOT16 + - Offset: 12 + Symbol: L2 + Type: R_MIPS_LO16 + + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x9000 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: L1 + Type: STT_OBJECT + Section: .data + Value: 0x00 + Size: 0x8000 + - Name: L2 + Type: STT_OBJECT + Section: .data + Value: 0x8000 + Size: 0x04 + + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x04 diff --git a/test/elf/Mips/got16-micro.test b/test/elf/Mips/got16-micro.test new file mode 100644 index 000000000000..6b77613581ec --- /dev/null +++ b/test/elf/Mips/got16-micro.test @@ -0,0 +1,165 @@ +# REQUIRES: mips + +# Check handling of global/local R_MICROMIPS_GOT16 relocations. +# RUN: llvm-mc -triple=mipsel -mattr=micromips -relocation-model=pic \ +# RUN: -filetype=obj -o=%t.o %s +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec \ +# RUN: --output-filetype=yaml %t.o \ +# RUN: | FileCheck -check-prefix YAML %s +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec -o %t2 %t.o +# RUN: llvm-objdump -t -disassemble -mattr=micromips %t2 \ +# RUN: | FileCheck -check-prefix RAW %s + +# Function glob +# YAML: - name: main +# YAML: scope: global +# YAML: content: [ 5C, FC, 00, 00, 42, 30, 00, 00, 5C, FC, 00, 00, +# YAML: 42, 30, 00, 00, 5C, FC, 00, 00, 5C, FC, 00, 00, +# YAML: 5C, FC, 00, 00 ] +# YAML: alignment: 4 mod 2^4 +# YAML: code-model: mips-micro +# YAML: references: +# YAML-NEXT: - kind: R_MICROMIPS_GOT16 +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: L000 +# YAML-NEXT: - kind: R_MICROMIPS_LO16 +# YAML-NEXT: offset: 4 +# YAML-NEXT: target: data_1 +# YAML-NEXT: - kind: R_MICROMIPS_GOT16 +# YAML-NEXT: offset: 8 +# YAML-NEXT: target: L001 +# YAML-NEXT: - kind: R_MICROMIPS_LO16 +# YAML-NEXT: offset: 12 +# YAML-NEXT: target: data_2 +# YAML-NEXT: - kind: R_MICROMIPS_GOT16 +# YAML-NEXT: offset: 16 +# YAML-NEXT: target: L002 +# YAML-NEXT: - kind: R_MICROMIPS_CALL16 +# YAML-NEXT: offset: 20 +# YAML-NEXT: target: L003 +# YAML-NEXT: - kind: R_MICROMIPS_CALL16 +# YAML-NEXT: offset: 24 +# YAML-NEXT: target: L004 + +# Local GOT entries: +# YAML: - ref-name: L000 +# YAML-NEXT: type: got +# YAML-NEXT: content: [ 00, 00, 00, 00 ] +# YAML-NEXT: alignment: 2^2 +# YAML-NEXT: section-choice: custom-required +# YAML-NEXT: section-name: .got +# YAML-NEXT: permissions: rw- +# YAML-NEXT: references: +# YAML-NEXT: - kind: LLD_R_MIPS_32_HI16 +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: data_1 +# YAML-NEXT: - ref-name: L001 +# YAML-NEXT: type: got +# YAML-NEXT: content: [ 00, 00, 00, 00 ] +# YAML-NEXT: alignment: 2^2 +# YAML-NEXT: section-choice: custom-required +# YAML-NEXT: section-name: .got +# YAML-NEXT: permissions: rw- +# YAML-NEXT: references: +# YAML-NEXT: - kind: LLD_R_MIPS_32_HI16 +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: data_2 +# YAML-NEXT: - ref-name: L002 +# YAML-NEXT: type: got +# YAML-NEXT: content: [ 00, 00, 00, 00 ] +# YAML-NEXT: alignment: 2^2 +# YAML-NEXT: section-choice: custom-required +# YAML-NEXT: section-name: .got +# YAML-NEXT: permissions: rw- +# YAML-NEXT: references: +# YAML-NEXT: - kind: R_MIPS_32 +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: data_h + +# Global GOT entries: +# YAML-NEXT: - ref-name: L003 +# YAML-NEXT: type: got +# YAML-NEXT: content: [ 00, 00, 00, 00 ] +# YAML-NEXT: alignment: 2^2 +# YAML-NEXT: section-choice: custom-required +# YAML-NEXT: section-name: .got +# YAML-NEXT: permissions: rw- +# YAML-NEXT: references: +# YAML-NEXT: - kind: LLD_R_MIPS_GLOBAL_GOT +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: bar +# YAML-NEXT: - kind: R_MIPS_32 +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: bar +# YAML-NEXT: - ref-name: L004 +# YAML-NEXT: type: got +# YAML-NEXT: content: [ 00, 00, 00, 00 ] +# YAML-NEXT: alignment: 2^2 +# YAML-NEXT: section-choice: custom-required +# YAML-NEXT: section-name: .got +# YAML-NEXT: permissions: rw- +# YAML-NEXT: references: +# YAML-NEXT: - kind: LLD_R_MIPS_GLOBAL_GOT +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: foo + +# RAW: Disassembly of section .text: +# RAW: main: +# RAW-NEXT: {{[0x0-9a-f]+}}: 5c fc 18 80 lw $2, -32744($gp) +# RAW-NEXT: {{[0x0-9a-f]+}}: 42 30 40 10 addiu $2, $2, 4160 +# RAW-NEXT: {{[0x0-9a-f]+}}: 5c fc 1c 80 lw $2, -32740($gp) +# RAW-NEXT: {{[0x0-9a-f]+}}: 42 30 60 20 addiu $2, $2, 8288 +# RAW-NEXT: {{[0x0-9a-f]+}}: 5c fc 20 80 lw $2, -32736($gp) +# RAW-NEXT: {{[0x0-9a-f]+}}: 5c fc 24 80 lw $2, -32732($gp) +# RAW-NEXT: {{[0x0-9a-f]+}}: 5c fc 28 80 lw $2, -32728($gp) + +# RAW: SYMBOL TABLE: +# RAW: {{[0x0-9a-f]+}} *UND* 00000000 +# RAW: {{[0x0-9a-f]+}} l .data 00000000 data_1 +# RAW: {{[0x0-9a-f]+}} l .data 00000001 data_2 +# RAW: {{[0x0-9a-f]+}} g F .text 00000004 bar +# RAW: {{[0x0-9a-f]+}} g F .text 0000001c main +# RAW: {{[0x0-9a-f]+}} g .data 00000001 data_h + + .data + .type data_1, @object + .size data_1, 4128 +data_1: + .byte 1 + .space 4127 + .type data_2, @object + .size data_2, 1 +data_2: + .byte 2 + .hidden data_h + .globl data_h + .type data_h, @object + .size data_h, 1 +data_h: + .byte 3 + + .text + .globl bar + .set micromips + .ent bar + .type bar, @function +bar: + nop + .end bar + .size bar, .-bar + + .globl main + .set micromips + .ent main + .type main, @function +main: + lw $2,%got(data_1)($28) + addiu $2,$2,%lo(data_1) + lw $2,%got(data_2)($28) + addiu $2,$2,%lo(data_2) + lw $2,%got(data_h)($28) + lw $2,%call16(bar)($28) + lw $2,%call16(foo)($28) + + .end main + .size main, .-main diff --git a/test/elf/Mips/got16.test b/test/elf/Mips/got16.test new file mode 100644 index 000000000000..9090d3003c14 --- /dev/null +++ b/test/elf/Mips/got16.test @@ -0,0 +1,196 @@ +# REQUIRES: mips + +# Check handling of global/local GOT16 relocations. +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec \ +# RUN: --output-filetype=yaml %t.o \ +# RUN: | FileCheck -check-prefix YAML %s +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec -o %t2 %t.o +# RUN: llvm-objdump -t -disassemble %t2 | FileCheck -check-prefix RAW %s + +# Function glob +# YAML: - name: glob +# YAML: scope: global +# YAML: content: [ 00, 00, 84, 8F, 00, 00, 84, 24, 01, 00, 84, 8F, +# YAML: 00, 02, 84, 24, 00, 00, 84, 8F, 00, 00, 84, 8F, +# YAML: 00, 00, 84, 8F ] +# YAML: alignment: 2^2 +# YAML: references: +# YAML: - kind: R_MIPS_GOT16 +# YAML: offset: 0 +# YAML: target: L000 +# YAML: - kind: R_MIPS_LO16 +# YAML: offset: 4 +# YAML: target: L009 +# YAML: - kind: R_MIPS_GOT16 +# YAML: offset: 8 +# YAML: target: L002 +# YAML: addend: 66048 +# YAML: - kind: R_MIPS_LO16 +# YAML: offset: 12 +# YAML: target: L009 +# YAML: addend: 512 +# YAML: - kind: R_MIPS_GOT16 +# YAML: offset: 16 +# YAML: target: L004 +# YAML: - kind: R_MIPS_CALL16 +# YAML: offset: 20 +# YAML: target: L005 +# YAML: - kind: R_MIPS_CALL16 +# YAML: offset: 24 +# YAML: target: L006 + +# Local GOT entries: +# YAML: - ref-name: L000 +# YAML-NEXT: type: got +# YAML-NEXT: content: [ 00, 00, 00, 00 ] +# YAML-NEXT: alignment: 2^2 +# YAML-NEXT: section-choice: custom-required +# YAML-NEXT: section-name: .got +# YAML-NEXT: permissions: rw- +# YAML-NEXT: references: +# YAML-NEXT: - kind: LLD_R_MIPS_32_HI16 +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: L009 +# YAML-NEXT: - ref-name: L002 +# YAML-NEXT: type: got +# YAML-NEXT: content: [ 00, 00, 00, 00 ] +# YAML-NEXT: alignment: 2^2 +# YAML-NEXT: section-choice: custom-required +# YAML-NEXT: section-name: .got +# YAML-NEXT: permissions: rw- +# YAML-NEXT: references: +# YAML-NEXT: - kind: LLD_R_MIPS_32_HI16 +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: L009 +# YAML-NEXT: addend: 66048 +# YAML-NEXT: - ref-name: L004 +# YAML-NEXT: type: got +# YAML-NEXT: content: [ 00, 00, 00, 00 ] +# YAML-NEXT: alignment: 2^2 +# YAML-NEXT: section-choice: custom-required +# YAML-NEXT: section-name: .got +# YAML-NEXT: permissions: rw- +# YAML-NEXT: references: +# YAML-NEXT: - kind: R_MIPS_32 +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: hidden + +# Global GOT entries: +# YAML-NEXT: - ref-name: L005 +# YAML-NEXT: type: got +# YAML-NEXT: content: [ 00, 00, 00, 00 ] +# YAML-NEXT: alignment: 2^2 +# YAML-NEXT: section-choice: custom-required +# YAML-NEXT: section-name: .got +# YAML-NEXT: permissions: rw- +# YAML-NEXT: references: +# YAML-NEXT: - kind: LLD_R_MIPS_GLOBAL_GOT +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: glob +# YAML-NEXT: - kind: R_MIPS_32 +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: glob +# YAML-NEXT: - ref-name: L006 +# YAML-NEXT: type: got +# YAML-NEXT: content: [ 00, 00, 00, 00 ] +# YAML-NEXT: alignment: 2^2 +# YAML-NEXT: section-choice: custom-required +# YAML-NEXT: section-name: .got +# YAML-NEXT: permissions: rw- +# YAML-NEXT: references: +# YAML-NEXT: - kind: LLD_R_MIPS_GLOBAL_GOT +# YAML-NEXT: offset: 0 +# YAML-NEXT: target: extern + +# RAW: Disassembly of section .text: +# RAW: glob: +# RAW-NEXT: {{[0x0-9a-f]+}}: 18 80 84 8f lw $4, -32744($gp) +# RAW-NEXT: {{[0x0-9a-f]+}}: 00 20 84 24 addiu $4, $4, 8192 +# RAW-NEXT: {{[0x0-9a-f]+}}: 1c 80 84 8f lw $4, -32740($gp) +# RAW-NEXT: {{[0x0-9a-f]+}}: 00 22 84 24 addiu $4, $4, 8704 +# RAW-NEXT: {{[0x0-9a-f]+}}: 20 80 84 8f lw $4, -32736($gp) +# RAW-NEXT: {{[0x0-9a-f]+}}: 24 80 84 8f lw $4, -32732($gp) +# RAW-NEXT: {{[0x0-9a-f]+}}: 28 80 84 8f lw $4, -32728($gp) + +# RAW: SYMBOL TABLE: +# RAW: {{[0x0-9a-f]+}} *UND* 00000000 +# RAW: {{[0x0-9a-f]+}} l .data 00000000 str1 +# RAW: {{[0x0-9a-f]+}} l .data 00000005 str2 +# RAW: {{[0x0-9a-f]+}} g F .text 0000001c glob +# RAW: {{[0x0-9a-f]+}} g .data 00000004 hidden + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: '0000848F000084240100848F000284240000848F0000848F0000848F' + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: .data + Type: R_MIPS_GOT16 + - Offset: 0x04 + Symbol: .data + Type: R_MIPS_LO16 + - Offset: 0x08 + Symbol: .data + Type: R_MIPS_GOT16 + - Offset: 0x0C + Symbol: .data + Type: R_MIPS_LO16 + - Offset: 0x10 + Symbol: hidden + Type: R_MIPS_GOT16 + - Offset: 0x14 + Symbol: glob + Type: R_MIPS_CALL16 + - Offset: 0x18 + Symbol: extern + Type: R_MIPS_CALL16 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x10209 + +Symbols: + Local: + - Name: str1 + Type: STT_OBJECT + Section: .data + Size: 0x10200 + - Name: str2 + Type: STT_OBJECT + Section: .data + Value: 0x10200 + Size: 0x05 + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + Global: + - Name: glob + Section: .text + - Name: hidden + Type: STT_OBJECT + Section: .data + Value: 0x10205 + Size: 0x04 + Visibility: STV_HIDDEN + - Name: extern diff --git a/test/elf/Mips/gotsym.test b/test/elf/Mips/gotsym.test new file mode 100644 index 000000000000..4581901958aa --- /dev/null +++ b/test/elf/Mips/gotsym.test @@ -0,0 +1,43 @@ +# Check _gp_disp and GOT_OFFSET_TABLE value +# +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec -o %t.so %t.o +# RUN: llvm-objdump -h -t %t.so | FileCheck -check-prefix=SHARED %s + +# SHARED: Sections: +# SHARED: Idx Name Size Address Type +# SHARED: 6 .got 00000008 0000000000001000 DATA +# SHARED: SYMBOL TABLE: +# SHARED: 00001000 g *ABS* 00000000 _GLOBAL_OFFSET_TABLE_ +# SHARED: 00008ff0 g *ABS* 00000000 _gp +# SHARED: 00008ff0 g *ABS* 00000000 _gp_disp + +# RUN: lld -flavor gnu -target mipsel -e main --noinhibit-exec -o %t.exe %t.o +# RUN: llvm-objdump -h -t %t.exe | FileCheck -check-prefix=EXE %s + +# EXE: Sections: +# EXE: Idx Name Size Address Type +# EXE: 7 .got 00000008 0000000000401000 DATA +# EXE: SYMBOL TABLE: +# EXE: 00401000 g *ABS* 00000000 _GLOBAL_OFFSET_TABLE_ +# EXE: 00408ff0 g *ABS* 00000000 _gp +# EXE: 00408ff0 g *ABS* 00000000 _gp_disp + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x04 + +Symbols: + Global: + - Name: main + Section: .text diff --git a/test/elf/Mips/gp-sym-1-micro.test b/test/elf/Mips/gp-sym-1-micro.test new file mode 100644 index 000000000000..76274eaaa8ac --- /dev/null +++ b/test/elf/Mips/gp-sym-1-micro.test @@ -0,0 +1,88 @@ +# Check that microMIPS relocations against __gnu_local_gp +# use "gp" value as target. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -symbols %t.exe | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=SEC %s + +# SYM: Name: _gp (203) +# SYM-NEXT: Value: 0x408FF0 + +# SEC: Contents of section .text: +# SEC-NEXT: 400184 00004100 0000f08f 2000bc00 ..A..... ... +# SEC: Contents of section .got: +# SEC-NEXT: 401000 00000000 00000080 ........ + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 12 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: __gnu_local_gp + Type: R_MICROMIPS_HI16 + - Offset: 0x04 + Symbol: __gnu_local_gp + Type: R_MICROMIPS_LO16 + - Offset: 0x08 + Symbol: T1 + Type: R_MICROMIPS_26_S1 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x08 + Other: [ STO_MIPS_MICROMIPS ] + - Name: __gnu_local_gp + - Name: T1 +... diff --git a/test/elf/Mips/gp-sym-1.test b/test/elf/Mips/gp-sym-1.test new file mode 100644 index 000000000000..6c2ffb62629d --- /dev/null +++ b/test/elf/Mips/gp-sym-1.test @@ -0,0 +1,86 @@ +# Check that relocations against __gnu_local_gp use "gp" value as target. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -symbols %t.exe | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=SEC %s + +# SYM: Name: _gp (203) +# SYM-NEXT: Value: 0x408FF0 + +# SEC: Contents of section .text: +# SEC-NEXT: 400190 41000000 f08f0000 60001000 +# SEC: Contents of section .got: +# SEC-NEXT: 401000 00000000 00000080 + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 12 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: __gnu_local_gp + Type: R_MIPS_HI16 + - Offset: 0x04 + Symbol: __gnu_local_gp + Type: R_MIPS_LO16 + - Offset: 0x08 + Symbol: T1 + Type: R_MIPS_26 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x08 + - Name: __gnu_local_gp + - Name: T1 +... diff --git a/test/elf/Mips/gp-sym-2.test b/test/elf/Mips/gp-sym-2.test new file mode 100644 index 000000000000..6b9e5a5e52d9 --- /dev/null +++ b/test/elf/Mips/gp-sym-2.test @@ -0,0 +1,103 @@ +# Check that R_MIPS32 relocation against __gnu_local_gp causes emitting +# of R_MIPS_REL32 relocation in case of shared library file linking +# and does not produce any dynamic relocation in case of linking a non-shared +# executable file. + +# Now the test failed because the __gnu_local_gp symbol becomes defined +# absolute symbol and we do not generate R_MIPS_REL32 in case of shared +# library linking. +# XFAIL: * + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t-1.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t-1.so +# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=EXE %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t-2.so %t-o.o %t-1.so +# RUN: llvm-readobj -r %t-2.so | FileCheck -check-prefix=SO %s + +# EXE: Relocations [ +# EXE-NEXT: ] + +# SO: Relocations [ +# SO-NEXT: Section (5) .rel.dyn { +# SO-NEXT: 0x0 R_MIPS_NONE - 0x0 +# SO-NEXT: 0x2EC R_MIPS_REL32 __gnu_local_gp 0x0 +# SO-NEXT: } +# SO-NEXT: ] + +# so.so +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 12 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: __gnu_local_gp + Type: R_MIPS_32 + - Offset: 0x04 + Symbol: T1 + Type: R_MIPS_LO16 + - Offset: 0x08 + Symbol: T2 + Type: R_MIPS_CALL16 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x08 + - Name: __gnu_local_gp + - Name: T1 + - Name: T2 +... diff --git a/test/elf/Mips/hilo16-1.test b/test/elf/Mips/hilo16-1.test new file mode 100644 index 000000000000..c2863408c888 --- /dev/null +++ b/test/elf/Mips/hilo16-1.test @@ -0,0 +1,44 @@ +# REQUIRES: mips + +# Check handling multiple HI16 relocation followed by a single LO16 relocation. +# +# RUN: llvm-mc -triple=mipsel -filetype=obj -o=%t-obj %s +# RUN: lld -flavor gnu -target mipsel -e glob1 -o %t-exe %t-obj +# RUN: llvm-objdump -t -disassemble %t-exe | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK: glob1: +# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 42 00 08 3c lui $8, 66 +# CHECK-NEXT: {{[0-9a-f]+}}: 3e 00 08 3c lui $8, 62 +# CHECK-NEXT: {{[0-9a-f]+}}: 40 02 08 3c lui $8, 576 +# CHECK-NEXT: {{[0-9a-f]+}}: 40 fe 08 3c lui $8, 65088 +# CHECK-NEXT: {{[0-9a-f]+}}: 55 01 08 85 lh $8, 341($8) + +# CHECK: SYMBOL TABLE: +# CHECK: {{[0-9a-f]+}} g F .text 00000024 glob1 +# CHECK: {{[0-9a-f]+}} g F .text 00000004 glob2 + + .global glob1 + .ent glob1 +glob1: + lui $t0,%hi(glob2+0x1) + lui $t0,%hi(glob2+(-0x1)) + lui $t0,%hi(glob2+0x1ff) + lui $t0,%hi(glob2+(-0x1ff)) + lui $t0,%hi(glob2+0x1ffff) + lui $t0,%hi(glob2+(-0x1ffff)) + lui $t0,%hi(glob2+0x1ffffff) + lui $t0,%hi(glob2+(-0x1ffffff)) + + lh $t0,%lo(glob2+(-0x1ffffff))($t0) + .end glob1 + + .global glob2 + .ent glob2 +glob2: + nop + .end glob2 diff --git a/test/elf/Mips/hilo16-2.test b/test/elf/Mips/hilo16-2.test new file mode 100644 index 000000000000..68cb26eec788 --- /dev/null +++ b/test/elf/Mips/hilo16-2.test @@ -0,0 +1,68 @@ +# REQUIRES: mips + +# Check handling of HI16 and LO16 relocations for regular symbol. +# +# R_MIPS_HI16: (AHL + S) - (short)(AHL + S) +# R_MIPS_LO16: AHL + S +# where AHL = (AHI << 16) + ALO +# +# RUN: llvm-mc -triple=mipsel -filetype=obj -o=%t-obj %s +# RUN: lld -flavor gnu -target mipsel -e glob1 -o %t-exe %t-obj +# RUN: llvm-objdump -t -disassemble %t-exe | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK: glob1: +# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 71 01 08 85 lh $8, 369($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 6f 01 08 85 lh $8, 367($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 6f 03 08 85 lh $8, 879($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 71 ff 08 85 lh $8, -143($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 42 00 08 3c lui $8, 66 +# CHECK-NEXT: {{[0-9a-f]+}}: 6f 01 08 85 lh $8, 367($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 3e 00 08 3c lui $8, 62 +# CHECK-NEXT: {{[0-9a-f]+}}: 71 01 08 85 lh $8, 369($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 40 02 08 3c lui $8, 576 +# CHECK-NEXT: {{[0-9a-f]+}}: 6f 01 08 85 lh $8, 367($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 40 fe 08 3c lui $8, 65088 +# CHECK-NEXT: {{[0-9a-f]+}}: 71 01 08 85 lh $8, 369($8) + +# CHECK: SYMBOL TABLE: +# CHECK: {{[0-9a-f]+}} g F .text 00000040 glob1 +# CHECK: {{[0-9a-f]+}} g F .text 00000004 glob2 + + .global glob1 + .ent glob1 +glob1: + lui $t0,%hi(glob2+0x1) + lh $t0,%lo(glob2+0x1)($t0) + + lui $t0,%hi(glob2+(-0x1)) + lh $t0,%lo(glob2+(-0x1))($t0) + + lui $t0,%hi(glob2+0x1ff) + lh $t0,%lo(glob2+0x1ff)($t0) + + lui $t0,%hi(glob2+(-0x1ff)) + lh $t0,%lo(glob2+(-0x1ff))($t0) + + lui $t0,%hi(glob2+0x1ffff) + lh $t0,%lo(glob2+0x1ffff)($t0) + + lui $t0,%hi(glob2+(-0x1ffff)) + lh $t0,%lo(glob2+(-0x1ffff))($t0) + + lui $t0,%hi(glob2+0x1ffffff) # truncate + lh $t0,%lo(glob2+0x1ffffff)($t0) + + lui $t0,%hi(glob2+(-0x1ffffff)) # truncate + lh $t0,%lo(glob2+(-0x1ffffff))($t0) + .end glob1 + + .global glob2 + .ent glob2 +glob2: + nop + .end glob2 diff --git a/test/elf/Mips/hilo16-3.test b/test/elf/Mips/hilo16-3.test new file mode 100644 index 000000000000..daf4807d719a --- /dev/null +++ b/test/elf/Mips/hilo16-3.test @@ -0,0 +1,45 @@ +# REQUIRES: mips + +# Check handling of HI16 and LO16 relocations for _gp_disp. +# +# R_MIPS_HI16: (AHL + GP - P) - (short)(AHL + GP - P) +# R_MIPS_LO16: AHL + GP - P + 4 +# where AHL = (AHI << 16) + ALO +# +# RUN: llvm-mc -triple=mipsel -filetype=obj -o=%t-obj %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t-so %t-obj +# RUN: llvm-objdump -t -disassemble %t-so | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK: glob1: +# CHECK-NEXT: {{[0-9a-f]+}}: 01 00 08 3c lui $8, 1 +# CHECK-NEXT: {{[0-9a-f]+}}: 01 8f 08 85 lh $8, -28927($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 01 00 08 3c lui $8, 1 +# CHECK-NEXT: {{[0-9a-f]+}}: f7 8e 08 85 lh $8, -28937($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 01 00 08 3c lui $8, 1 +# CHECK-NEXT: {{[0-9a-f]+}}: ef 90 08 85 lh $8, -28433($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 01 00 08 3c lui $8, 1 +# CHECK-NEXT: {{[0-9a-f]+}}: e9 8c 08 85 lh $8, -29463($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 03 00 08 3c lui $8, 3 +# CHECK-NEXT: {{[0-9a-f]+}}: df 8e 08 85 lh $8, -28961($8) + +# CHECK: SYMBOL TABLE: +# CHECK: {{[0-9a-f]+}} g F .text 00000028 glob1 +# CHECK: {{[0-9a-f]+}} g *ABS* 00000000 _gp_disp + + .global glob1 +glob1: + lui $t0,%hi(_gp_disp+0x1) + lh $t0,%lo(_gp_disp+0x1)($t0) + + lui $t0,%hi(_gp_disp+(-0x1)) + lh $t0,%lo(_gp_disp+(-0x1))($t0) + + lui $t0,%hi(_gp_disp+0x1ff) + lh $t0,%lo(_gp_disp+0x1ff)($t0) + + lui $t0,%hi(_gp_disp+(-0x1ff)) + lh $t0,%lo(_gp_disp+(-0x1ff))($t0) + + lui $t0,%hi(_gp_disp+0x1ffff) + lh $t0,%lo(_gp_disp+0x1ffff)($t0) diff --git a/test/elf/Mips/hilo16-4.test b/test/elf/Mips/hilo16-4.test new file mode 100644 index 000000000000..8a13f7b131fd --- /dev/null +++ b/test/elf/Mips/hilo16-4.test @@ -0,0 +1,93 @@ +# REQUIRES: mips + +# Check pairing of R_MIPS_HI16 and R_MIPS_LO16 relocations. +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -e glob1 -o %t-exe %t-obj +# RUN: llvm-objdump -t -disassemble %t-exe | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK: glob1: +# CHECK-NEXT: 400130: 40 00 04 3c lui $4, 64 +# CHECK-NEXT: 400134: ff 9f a6 8c lw $6, -24577($5) + +# CHECK: glob2: +# CHECK-NEXT: 400138: 00 20 c7 80 lb $7, 8192($6) +# CHECK-NEXT: 40013c: 04 20 c8 80 lb $8, 8196($6) + +# CHECK: glob3: +# CHECK-NEXT: 400140: 40 80 05 3c lui $5, 32832 + +# CHECK: SYMBOL TABLE: +# CHECK: 00400130 g F .text 00000008 glob1 +# CHECK: 00400138 g F .text 00000008 glob2 +# CHECK: 00400140 g F .text 00000004 glob3 +# CHECK: 00402000 g .data 0000000c X + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS +# glob1: +# lui $4,%hi(X) # rel A +# lw $6,%lo(X+32767)($5) # rel B +# glob2: +# lb $7,%lo(X)($6) # rel C +# lb $8,%lo(X+4)($6) # rel D +# glob3: +# lui $5,%hi(X+32767) # rel E + Content: "0000043CFF7FA68C0000C7800400C880FF7F053C" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Content: "000000000000000000000000" + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x10 # rel E + Symbol: X + Type: R_MIPS_HI16 + - Offset: 0x04 # rel B + Symbol: X + Type: R_MIPS_LO16 + - Offset: 0x00 # rel A + Symbol: X + Type: R_MIPS_HI16 + - Offset: 0x0C # rel D + Symbol: X + Type: R_MIPS_LO16 + - Offset: 0x08 # rel C + Symbol: X + Type: R_MIPS_LO16 + +Symbols: + Global: + - Name: glob1 + Section: .text + Value: 0x0 + Size: 8 + - Name: glob2 + Section: .text + Value: 0x8 + Size: 8 + - Name: glob3 + Section: .text + Value: 0x10 + Size: 4 + - Name: X + Section: .data + Value: 0x0 + Size: 12 diff --git a/test/elf/Mips/hilo16-5.test b/test/elf/Mips/hilo16-5.test new file mode 100644 index 000000000000..91aca8b1c366 --- /dev/null +++ b/test/elf/Mips/hilo16-5.test @@ -0,0 +1,103 @@ +# Check that linker shows a warning when +# there is orphaned R_MIPS_HI16 relocation. + +# RUN: yaml2obj -format=elf -o %t-so.o -docnum 1 %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -o %t-o.o -docnum 2 %s +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so 2>&1 \ +# RUN: | FileCheck -check-prefix=DIAG %s +# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=DATA %s + +# DIAG: lld warning: cannot matching LO16 relocation +# DIAG: lld warning: cannot matching LO16 relocation + +# DATA: Contents of section .data: +# DATA-NEXT: 402000 40000000 10200000 40000000 @.... ..@... + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .data + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "00000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Content: "000000000000000000000000" + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: D1 + Type: R_MIPS_HI16 + - Offset: 0x08 + Symbol: D2 + Type: R_MIPS_HI16 + - Offset: 0x04 + Symbol: D1 + Type: R_MIPS_LO16 + - Offset: 0x08 + Symbol: .text + Type: R_MIPS_HI16 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: D1 + - Name: D2 +... diff --git a/test/elf/Mips/hilo16-8-micro.test b/test/elf/Mips/hilo16-8-micro.test new file mode 100644 index 000000000000..3248804f8f54 --- /dev/null +++ b/test/elf/Mips/hilo16-8-micro.test @@ -0,0 +1,81 @@ +# REQUIRES: mips + +# Check calculation of AHL addendums for R_MICROMIPS_HI16 / R_MICROMIPS_LO16 +# relocations for a regular symbol. +# +# RUN: llvm-mc -triple=mipsel -mattr=micromips -filetype=obj -o=%t-obj %s +# RUN: lld -flavor gnu -target mipsel -e glob1 -o %t-exe %t-obj +# RUN: llvm-objdump -t -d -mattr=micromips %t-exe | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK-NEXT: glob1: +# CHECK-NEXT: 400130: a8 41 40 00 lui $8, 64 +# CHECK-NEXT: 400134: 08 3d 6a 01 lh $8, 362($8) +# CHECK-NEXT: 400138: a8 41 41 00 lui $8, 65 +# CHECK-NEXT: 40013c: 08 3d 68 81 lh $8, -32408($8) +# CHECK-NEXT: 400140: a8 41 41 00 lui $8, 65 +# CHECK-NEXT: 400144: 08 3d e9 81 lh $8, -32279($8) +# CHECK-NEXT: 400148: a8 41 42 00 lui $8, 66 +# CHECK-NEXT: 40014c: 08 3d 69 81 lh $8, -32407($8) +# CHECK-NEXT: 400150: a8 41 40 40 lui $8, 16448 +# CHECK-NEXT: 400154: 08 3d 69 01 lh $8, 361($8) +# CHECK-NEXT: 400158: a8 41 40 80 lui $8, 32832 +# CHECK-NEXT: 40015c: 08 3d 69 01 lh $8, 361($8) +# CHECK-NEXT: 400160: a8 41 c1 80 lui $8, 32961 +# CHECK-NEXT: 400164: 08 3d e9 81 lh $8, -32279($8) + +# CHECK: glob2: +# CHECK-NEXT: 400168: a8 41 40 00 lui $8, 64 +# CHECK-NEXT: 40016c: a8 41 40 00 lui $8, 64 +# CHECK-NEXT: 400170: a8 41 41 00 lui $8, 65 +# CHECK-NEXT: 400174: a8 41 42 00 lui $8, 66 +# CHECK-NEXT: 400178: a8 41 40 40 lui $8, 16448 +# CHECK-NEXT: 40017c: a8 41 40 80 lui $8, 32832 +# CHECK-NEXT: 400180: a8 41 c1 80 lui $8, 32961 +# CHECK-NEXT: 400184: 08 3d b1 81 lh $8, -32335($8) + +# CHECK: SYMBOL TABLE: +# CHECK: 00400130 g F .text 00000038 glob1 +# CHECK: 00400168 g F .text 00000020 glob2 + + .globl glob1 + .type glob1, @function + .set micromips + .ent glob1 +glob1: + lui $t0,%hi(glob2+0x00000001) + lh $t0,%lo(glob2+0x00000001)($t0) + + lui $t0,%hi(glob2+0x00007fff) + lh $t0,%lo(glob2+0x00007fff)($t0) + + lui $t0,%hi(glob2+0x00008080) + lh $t0,%lo(glob2+0x00008080)($t0) + + lui $t0,%hi(glob2+0x00018000) + lh $t0,%lo(glob2+0x00018000)($t0) + + lui $t0,%hi(glob2+0x40000000) + lh $t0,%lo(glob2+0x40000000)($t0) + + lui $t0,%hi(glob2+0x80000000) + lh $t0,%lo(glob2+0x80000000)($t0) + + lui $t0,%hi(glob2+0x80808080) + lh $t0,%lo(glob2+0x80808080)($t0) + .end glob1 + + .globl glob2 + .type glob2, @function + .set micromips + .ent glob2 +glob2: + lui $t0,%hi(glob1+0x00000001) + lui $t0,%hi(glob1+0x00007fff) + lui $t0,%hi(glob1+0x00008080) + lui $t0,%hi(glob1+0x00018000) + lui $t0,%hi(glob1+0x40000000) + lui $t0,%hi(glob1+0x80000000) + lui $t0,%hi(glob1+0x80808080) + lh $t0,%lo(glob1+0x80808080)($t0) + .end glob2 diff --git a/test/elf/Mips/hilo16-9-micro.test b/test/elf/Mips/hilo16-9-micro.test new file mode 100644 index 000000000000..30ad10ce0dd4 --- /dev/null +++ b/test/elf/Mips/hilo16-9-micro.test @@ -0,0 +1,68 @@ +# REQUIRES: mips + +# Check calculation of AHL addendums for R_MICROMIPS_HI16 / R_MICROMIPS_LO16 +# relocations for the _gp_disp symbol. +# +# RUN: llvm-mc -triple=mipsel -mattr=micromips -filetype=obj -o=%t-obj %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t-so %t-obj +# RUN: llvm-objdump -t -d -mattr=micromips %t-so | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK-NEXT: glob1: +# CHECK-NEXT: 130: a8 41 01 00 lui $8, 1 +# CHECK-NEXT: 134: 08 3d c0 9e lh $8, -24896($8) +# CHECK-NEXT: 138: a8 41 01 00 lui $8, 1 +# CHECK-NEXT: 13c: 08 3d b6 1e lh $8, 7862($8) +# CHECK-NEXT: 140: a8 41 01 00 lui $8, 1 +# CHECK-NEXT: 144: 08 3d 2f 1f lh $8, 7983($8) +# CHECK-NEXT: 148: a8 41 02 00 lui $8, 2 +# CHECK-NEXT: 14c: 08 3d a7 1e lh $8, 7847($8) +# CHECK-NEXT: 150: a8 41 01 40 lui $8, 16385 +# CHECK-NEXT: 154: 08 3d 9f 9e lh $8, -24929($8) + +# CHECK: glob2: +# CHECK-NEXT: 158: a8 41 01 00 lui $8, 1 +# CHECK-NEXT: 15c: a8 41 01 00 lui $8, 1 +# CHECK-NEXT: 160: a8 41 02 00 lui $8, 2 +# CHECK-NEXT: 164: a8 41 03 00 lui $8, 3 +# CHECK-NEXT: 168: a8 41 01 40 lui $8, 16385 +# CHECK-NEXT: 16c: 08 3d 87 9e lh $8, -24953($8) + +# CHECK: SYMBOL TABLE: +# CHECK: 00000130 g F .text 00000028 glob1 +# CHECK: 00000158 g F .text 00000018 glob2 +# CHECK: 00009ff0 g *ABS* 00000000 _gp_disp + + .globl glob1 + .type glob1, @function + .set micromips + .ent glob1 +glob1: + lui $t0,%hi(_gp_disp+0x00000001) + lh $t0,%lo(_gp_disp+0x00000001)($t0) + + lui $t0,%hi(_gp_disp+0x00007fff) + lh $t0,%lo(_gp_disp+0x00007fff)($t0) + + lui $t0,%hi(_gp_disp+0x00008080) + lh $t0,%lo(_gp_disp+0x00008080)($t0) + + lui $t0,%hi(_gp_disp+0x00018000) + lh $t0,%lo(_gp_disp+0x00018000)($t0) + + lui $t0,%hi(_gp_disp+0x40000000) + lh $t0,%lo(_gp_disp+0x40000000)($t0) + .end glob1 + + .globl glob2 + .type glob2, @function + .set micromips + .ent glob2 +glob2: + lui $t0,%hi(_gp_disp+0x00000001) + lui $t0,%hi(_gp_disp+0x00007fff) + lui $t0,%hi(_gp_disp+0x00008080) + lui $t0,%hi(_gp_disp+0x00018000) + lui $t0,%hi(_gp_disp+0x40000000) + lh $t0,%lo(_gp_disp+0x40000000)($t0) + .end glob2 diff --git a/test/elf/Mips/initfini-micro.test b/test/elf/Mips/initfini-micro.test new file mode 100644 index 000000000000..ba30e89ade21 --- /dev/null +++ b/test/elf/Mips/initfini-micro.test @@ -0,0 +1,45 @@ +# Check that if _init/_fini symbols are microMIPS encoded, DT_INIT/DT_FINI tags +# use adjusted values with set the last bit. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t.o +# RUN: llvm-readobj -symbols -dynamic-table %t.so | FileCheck %s + +# CHECK: Name: _init (1) +# CHECK-NEXT: Value: 0xF5 +# CHECK: Name: _fini (7) +# CHECK-NEXT: Value: 0xF9 +# +# CHECK: 0x0000000C INIT 0xF5 +# CHECK: 0x0000000D FINI 0xF9 + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x18 + +Symbols: + Global: + - Name: _init + Type: STT_FUNC + Section: .text + Value: 0x0 + Size: 0x4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: _fini + Type: STT_FUNC + Section: .text + Value: 0x4 + Size: 0x4 + Other: [ STO_MIPS_MICROMIPS ] +... diff --git a/test/elf/Mips/interpreter-64.test b/test/elf/Mips/interpreter-64.test new file mode 100644 index 000000000000..3ece3e6a467a --- /dev/null +++ b/test/elf/Mips/interpreter-64.test @@ -0,0 +1,26 @@ +# Check program interpreter setup. +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mips64el -e main -o %t.exe %t.o +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# CHECK: Contents of section .interp: +# CHECK-NEXT: {{[0-9a-f]+}} 2f6c6962 36342f6c 642e736f 2e3100 /lib64/ld.so.1. + +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64 ] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x08 + +Symbols: + Global: + - Name: main + Section: .text diff --git a/test/elf/Mips/interpreter.test b/test/elf/Mips/interpreter.test new file mode 100644 index 000000000000..5355f7709fbd --- /dev/null +++ b/test/elf/Mips/interpreter.test @@ -0,0 +1,26 @@ +# Check program interpreter setup. +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -e main -o %t.exe %t.o +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# CHECK: Contents of section .interp: +# CHECK-NEXT: {{[0-9a-f]+}} 2f6c6962 2f6c642e 736f2e31 00 /lib/ld.so.1. + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x04 + +Symbols: + Global: + - Name: main + Section: .text diff --git a/test/elf/Mips/invalid-reginfo.test b/test/elf/Mips/invalid-reginfo.test new file mode 100644 index 000000000000..d56223bf2e04 --- /dev/null +++ b/test/elf/Mips/invalid-reginfo.test @@ -0,0 +1,28 @@ +# Check that LLD shows an error if .reginfo section has invalid size + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: not lld -flavor gnu -target mipsel -o %t.exe %t.o 2>&1 | FileCheck %s + +# CHECK: Invalid size of MIPS_REGINFO section + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + - Name: .reginfo + Type: SHT_MIPS_REGINFO + Flags: [ SHF_ALLOC ] + AddressAlign: 0x01 + Size: 0x25 +Symbols: + Global: + - Name: main + Section: .text diff --git a/test/elf/Mips/jalx-align-err.test b/test/elf/Mips/jalx-align-err.test new file mode 100644 index 000000000000..3db18fc98fac --- /dev/null +++ b/test/elf/Mips/jalx-align-err.test @@ -0,0 +1,46 @@ +# Check that LLD shows an error if jalx target value is not word-aligned. + +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: not lld -flavor gnu -target mipsel -e T0 -o %t-exe %t-obj 2>&1 \ +# RUN: | FileCheck %s + +# CHECK: The jalx target 0x400116 is not word-aligned + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, + EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 8 + AddressAlign: 16 + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MICROMIPS_26_S1 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 6 + Size: 2 diff --git a/test/elf/Mips/jump-fix-err.test b/test/elf/Mips/jump-fix-err.test new file mode 100644 index 000000000000..981179938397 --- /dev/null +++ b/test/elf/Mips/jump-fix-err.test @@ -0,0 +1,45 @@ +# Check that LLD shows an error in case +# of replacing an unknown unstruction by jalx. + +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: not lld -flavor gnu -target mipsel -o %t-exe %t-obj 2>&1 | FileCheck %s + +# CHECK: Unsupported jump opcode (0x0) for ISA modes cross call + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, + EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 8 + AddressAlign: 16 + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: T0 + Type: R_MICROMIPS_26_S1 + +Symbols: + Global: + - Name: __start + Section: .text + Type: STT_FUNC + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 4 + Size: 4 diff --git a/test/elf/Mips/la25-stub-micro.test b/test/elf/Mips/la25-stub-micro.test new file mode 100644 index 000000000000..d41297a0ddc3 --- /dev/null +++ b/test/elf/Mips/la25-stub-micro.test @@ -0,0 +1,140 @@ +# Check microMIPS LA25 stubs creation when PIC code +# is called from non-PIC routines. + +# Build executable from pic and non-pic code. +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-npic.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-pic.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-main.o +# RUN: lld -flavor gnu -target mipsel -e glob -o %t.exe \ +# RUN: %t-npic.o %t-pic.o %t-main.o + +# RUN: llvm-readobj -t %t.exe | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=ASM %s + +# SYM: Name: loc (13) +# SYM-NEXT: Value: 0x400135 +# SYM: Name: T1N (1) +# SYM-NEXT: Value: 0x400111 +# SYM: Name: T1 (5) +# SYM-NEXT: Value: 0x400121 +# SYM: Name: glob (8) +# SYM-NEXT: Value: 0x400125 + +# ASM: Contents of section .text: +# ASM-NEXT: 400110 00000000 00000000 00000000 00000000 +# ASM-NEXT: 400120 00000000 00000000 00000000 10f04900 +# 0x100049 << 2 == 0x400125 (jalx glob) --^ +# ASM-NEXT: 400130 00000000 20f49200 00000000 20f48800 +# ^-- 0x100049 << 2 == 0x400124 (jal glob) +# 0x100044 << 2 == 0x400110 (jal T1N) --^ +# ASM-NEXT: 400140 00000000 20f4a800 00000000 00000000 +# ^-- 0x100054 << 2 == 0x400150 (jal T1 stub) +# ASM-NEXT: 400150 b9414000 20d49000 39332101 00000000 +# ^-- j 0x400120 (T1) + +# npic.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, + EF_MIPS_CPIC, EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x04 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1N + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + +# pic.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, + EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x04 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + +# main.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, + EF_MIPS_CPIC, EF_MIPS_MICROMIPS ] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: '000000000000000000f400000000000000f400000000000000f400000000000000f4000000000000' +# jal loc jal glob jal T1N jal T1 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x08 + Symbol: .text + Type: R_MICROMIPS_26_S1 + - Offset: 0x10 + Symbol: glob + Type: R_MICROMIPS_26_S1 + - Offset: 0x18 + Symbol: T1N + Type: R_MICROMIPS_26_S1 + - Offset: 0x20 + Symbol: T1 + Type: R_MICROMIPS_26_S1 + +Symbols: + Local: + - Name: loc + Section: .text + Value: 0x10 + Size: 0x18 + Other: [ STO_MIPS_MICROMIPS ] + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + Size: 0x10 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 + - Name: T1N +... diff --git a/test/elf/Mips/la25-stub.test b/test/elf/Mips/la25-stub.test new file mode 100644 index 000000000000..2c4b26452cec --- /dev/null +++ b/test/elf/Mips/la25-stub.test @@ -0,0 +1,133 @@ +# Check LA25 stubs creation when PIC code is called from non-PIC routines. + +# Build executable from pic and non-pic code. +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-npic.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-pic.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-main.o +# RUN: lld -flavor gnu -target mipsel -e glob -o %t.exe \ +# RUN: %t-npic.o %t-pic.o %t-main.o + +# RUN: llvm-readobj -t %t.exe | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=ASM %s + +# SYM: Name: loc (13) +# SYM-NEXT: Value: 0x400134 +# SYM: Name: T1N (1) +# SYM-NEXT: Value: 0x400110 +# SYM: Name: T1 (5) +# SYM-NEXT: Value: 0x400120 +# SYM: Name: glob (8) +# SYM-NEXT: Value: 0x400124 + +# ASM: Contents of section .text: +# ASM-NEXT: 400110 00000000 00000000 00000000 00000000 +# ASM-NEXT: 400120 00000000 00000000 00000000 49001000 +# 0x100049 << 2 == 0x400124 (glob) --^ +# ASM-NEXT: 400130 00000000 49001000 00000000 44001000 +# ^-- 0x100049 << 2 == 0x400124 (glob) +# 0x100044 << 2 == 0x400110 (T1N) --^ +# ASM-NEXT: 400140 00000000 54001000 00000000 00000000 +# ^-- 0x100054 << 2 == 0x400150 (T1 stub) +# ASM-NEXT: 400150 4000193c 48001008 20013927 00000000 +# ^-- j 0x400120 (T1) + +# npic.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x04 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1N + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# pic.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_PIC ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x04 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# main.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC ] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x28 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x08 + Symbol: .text + Type: R_MIPS_26 + Addend: 0 + - Offset: 0x10 + Symbol: glob + Type: R_MIPS_26 + Addend: 0 + - Offset: 0x18 + Symbol: T1N + Type: R_MIPS_26 + Addend: 0 + - Offset: 0x20 + Symbol: T1 + Type: R_MIPS_26 + Addend: 0 + +Symbols: + Local: + - Name: loc + Section: .text + Value: 0x10 + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + - Name: T1 + - Name: T1N +... diff --git a/test/elf/Mips/mips-options-gp0.test b/test/elf/Mips/mips-options-gp0.test new file mode 100644 index 000000000000..339ab97253b6 --- /dev/null +++ b/test/elf/Mips/mips-options-gp0.test @@ -0,0 +1,78 @@ +# Check reading GP0 value from .MIPS.options section +# +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -e G1 -shared -o %t.so %t.o +# RUN: llvm-readobj -symbols %t.so | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=SEC %s + +# SYM: Name: L1 (1) +# SYM-NEXT: Value: 0xCC +# SYM-NEXT: Size: 4 +# SYM-NEXT: Binding: Local (0x0) +# SYM-NEXT: Type: Function (0x2) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: .text (0x4) + +# SYM: Name: _gp (34) +# SYM-NEXT: Value: 0x8FF0 +# SYM-NEXT: Size: 0 +# SYM-NEXT: Binding: Global (0x1) +# SYM-NEXT: Type: Object (0x1) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: Absolute (0xFFF1) + +# 0xffff80dc == 0x0 (addend) + 0x00cc (L1) + 0x1000 (GP0) - 0x8ff0 (_gp) +# SEC: Contents of section .rodata: +# SEC-NEXT: 00d4 dc80ffff 00000000 00000000 00000000 ................ + +!ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: +- Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + +- Name: .rodata + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x04 + Size: 16 + +- Name: .rel.rodata + Type: SHT_REL + Link: .symtab + Info: .rodata + AddressAlign: 0x04 + Relocations: + - Offset: 0 + Symbol: L1 + Type: R_MIPS_GPREL32 + +- Name: .MIPS.options + Type: SHT_MIPS_OPTIONS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x01 + Content: "0128000000000000000000000000000000000000000000000000000000100000" + +Symbols: + Local: + - Name: L1 + Section: .text + Value: 0x00 + Size: 0x04 + - Name: .rodata + Type: STT_SECTION + Section: .rodata + Global: + - Name: G1 + Section: .text + Value: 0x04 + Size: 0x04 diff --git a/test/elf/Mips/n64-rel-chain.test b/test/elf/Mips/n64-rel-chain.test new file mode 100644 index 000000000000..0ae7af73ae83 --- /dev/null +++ b/test/elf/Mips/n64-rel-chain.test @@ -0,0 +1,134 @@ +# Check handling MIPS N64 ABI relocation "chains". + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mips64el -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 1200001d0 01000000 00000000 208e0000 00000000 ........ ....... +# CHECK-NEXT: 1200001e0 20800000 f8010000 28800000 00000000 .......(....... +# CHECK: Contents of section .pdr: +# CHECK-NEXT: 0000 d0010020 e0010020 ... ... + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 16 + Size: 8 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + + Global: + - Name: T1 + Type: STT_FUNC + Section: .text + Value: 0 + Size: 8 + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 16 + Size: 32 + + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 8 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: LT1 + Type: R_MIPS_GPREL16 + Type2: R_MIPS_SUB + Type3: R_MIPS_HI16 + - Offset: 0x08 + Symbol: LT1 + Type: R_MIPS_GPREL16 + Type2: R_MIPS_SUB + Type3: R_MIPS_LO16 + - Offset: 0x10 + Symbol: .rodata + Type: R_MIPS_GOT_PAGE + Addend: 8 + - Offset: 0x14 + Symbol: .rodata + Type: R_MIPS_GOT_OFST + Addend: 8 + - Offset: 0x18 + Symbol: T1 + Type: R_MIPS_CALL16 + + - Name: .pdr + Type: SHT_PROGBITS + AddressAlign: 4 + Size: 8 + + - Name: .rela.pdr + Type: SHT_RELA + Link: .symtab + AddressAlign: 8 + Info: .pdr + Relocations: + - Offset: 0x00 + Symbol: LT1 + Type: R_MIPS_32 + - Offset: 0x04 + Symbol: T0 + Type: R_MIPS_32 + + - Name: .rodata + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 16 + Size: 16 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .rodata + Type: STT_SECTION + Section: .rodata + - Name: .pdr + Type: STT_SECTION + Section: .pdr + + Global: + - Name: LT1 + Type: STT_FUNC + Section: .text + Value: 0x00 + Size: 0x10 + - Name: T0 + Type: STT_FUNC + Section: .text + Value: 0x10 + Size: 0x10 + - Name: T1 +... diff --git a/test/elf/Mips/opt-emulation.test b/test/elf/Mips/opt-emulation.test new file mode 100644 index 000000000000..2d1e7142c386 --- /dev/null +++ b/test/elf/Mips/opt-emulation.test @@ -0,0 +1,41 @@ +# Check MIPS specific arguments of the -m command line option. + +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -m elf32ltsmip -o %t-exe %t-obj +# RUN: llvm-readobj -file-headers %t-exe | FileCheck -check-prefix=LE-O32 %s + +# LE-O32: Class: 32-bit (0x1) +# LE-O32: DataEncoding: LittleEndian (0x1) +# LE-O32: FileVersion: 1 +# LE-O32: OS/ABI: SystemV (0x0) +# LE-O32: ABIVersion: 0 +# LE-O32: Machine: EM_MIPS (0x8) +# LE-O32: Version: 1 +# LE-O32: Flags [ (0x70001005) +# LE-O32-NEXT: EF_MIPS_ABI_O32 (0x1000) +# LE-O32-NEXT: EF_MIPS_ARCH_32R2 (0x70000000) +# LE-O32-NEXT: EF_MIPS_CPIC (0x4) +# LE-O32-NEXT: EF_MIPS_NOREORDER (0x1) +# LE-O32-NEXT: ] + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "00000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: __start + Section: .text + Value: 0x0 + Size: 4 diff --git a/test/elf/Mips/pc23-range.test b/test/elf/Mips/pc23-range.test new file mode 100644 index 000000000000..7166176c4628 --- /dev/null +++ b/test/elf/Mips/pc23-range.test @@ -0,0 +1,56 @@ +# Check that LLD shows an error if ADDIUPC immediate is out of range. + +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj 2>&1 | FileCheck %s + +# CHECK: The addiupc instruction immediate 0x02000008 is out of range + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, + EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "0000000080780100" +# ^ PC23: 1 << 2 = 4 => T0 + 4 - 4 = T0 + AddressAlign: 16 + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + +- Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x4000000 + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 4 + Symbol: T0 + Type: R_MICROMIPS_PC23_S2 + +Symbols: + Global: + - Name: __start + Section: .text + Type: STT_FUNC + Size: 8 + Other: [ STO_MIPS_MICROMIPS ] + - Name: TZ + Section: .data + Type: STT_FUNC + Value: 0 + Size: 0x2000000 + - Name: T0 + Section: .data + Type: STT_FUNC + Value: 0x2000000 + Size: 4 diff --git a/test/elf/Mips/plt-entry-mixed-1.test b/test/elf/Mips/plt-entry-mixed-1.test new file mode 100644 index 000000000000..bc45763fa16d --- /dev/null +++ b/test/elf/Mips/plt-entry-mixed-1.test @@ -0,0 +1,114 @@ +# REQUIRES: mips + +# Conditions: +# a) Object file contains both R_MIPS_26 and microMIPS non-jal relocations. +# b) The R_MIPS_26 relocation handled first. +# Check: +# a) PLT contains the only regular entry. + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t.so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t.o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o.o %t.so +# RUN: llvm-objdump -d %t.exe | FileCheck %s + +# CHECK: Disassembly of section .plt: +# CHECK-NEXT: .plt: +# CHECK-NEXT: 400170: 40 00 1c 3c lui $gp, 64 +# CHECK-NEXT: 400174: 00 20 99 8f lw $25, 8192($gp) +# CHECK-NEXT: 400178: 00 20 9c 27 addiu $gp, $gp, 8192 +# CHECK-NEXT: 40017c: 23 c0 1c 03 subu $24, $24, $gp +# CHECK-NEXT: 400180: 21 78 e0 03 move $15, $ra +# CHECK-NEXT: 400184: 82 c0 18 00 srl $24, $24, 2 +# CHECK-NEXT: 400188: 09 f8 20 03 jalr $25 +# CHECK-NEXT: 40018c: fe ff 18 27 addiu $24, $24, -2 +# CHECK-NEXT: 400190: 40 00 0f 3c lui $15, 64 +# CHECK-NEXT: 400194: 08 20 f9 8d lw $25, 8200($15) +# CHECK-NEXT: 400198: 08 00 20 03 jr $25 +# CHECK-NEXT: 40019c: 08 20 f8 25 addiu $24, $15, 8200 + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "0000000C00000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x0 + Symbol: T1 + Type: R_MIPS_26 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MICROMIPS_HI16 + - Offset: 0x00 + Symbol: T1 + Type: R_MICROMIPS_LO16 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 0x8 + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: T1 +... diff --git a/test/elf/Mips/plt-entry-mixed-2.test b/test/elf/Mips/plt-entry-mixed-2.test new file mode 100644 index 000000000000..5aec7d7a328a --- /dev/null +++ b/test/elf/Mips/plt-entry-mixed-2.test @@ -0,0 +1,93 @@ +# REQUIRES: mips + +# Conditions: +# a) Object file contains both R_MIPS_26 and R_MICROMIPS_26_S1 relocations. +# Check: +# a) PLT contains both regular and compressed PLT entries + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t.so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t.o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o.o %t.so +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# FIXME (simon): Check the disassembler output when llvm-objdump starts +# to support microMIPS instruction encoding. + +# CHECK: Contents of section .plt: +# CHECK-NEXT: 400170 40001c3c 0020998f 00209c27 23c01c03 @..<. ... .'#... +# CHECK-NEXT: 400180 2178e003 82c01800 09f82003 feff1827 !x........ ....' +# CHECK-NEXT: 400190 40000f3c 0820f98d 08002003 0820f825 @..<. .... .. .% +# CHECK-NEXT: 4001a0 00799a07 22ff0000 9945020f .y.."....E.. + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "0000000C000000000000000000000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x0 + Symbol: T2 + Type: R_MIPS_26 + - Offset: 0x8 + Symbol: T2 + Type: R_MICROMIPS_26_S1 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 0x8 + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x8 + Size: 0x8 + Other: [STO_MIPS_MICROMIPS] + - Name: T2 +... diff --git a/test/elf/Mips/plt-entry-mixed-3.test b/test/elf/Mips/plt-entry-mixed-3.test new file mode 100644 index 000000000000..c61991b4b139 --- /dev/null +++ b/test/elf/Mips/plt-entry-mixed-3.test @@ -0,0 +1,98 @@ +# REQUIRES: mips + +# Conditions: +# a) Object file contains microMIPS instructions. +# b) There is a relocation refers arbitrary symbols and requires a PLT entry. +# Check: +# a) PLT contains a compressed entry. + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t.so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t.o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o.o %t.so +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# FIXME (simon): Check the disassembler output when llvm-objdump starts +# to support microMIPS instruction encoding. + +# CHECK: Contents of section .plt: +# CHECK-NEXT: 400170 8079a407 23ff0000 35052525 0233feff .y..#...5.%%.3.. +# CHECK-NEXT: 400180 ff0df945 830f000c 0079a007 22ff0000 ...E.....y.."... +# CHECK-NEXT: 400190 9945020f .E.. + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 16 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MICROMIPS_HI16 + - Offset: 0x00 + Symbol: T1 + Type: R_MICROMIPS_LO16 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 16 + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: T1 +... diff --git a/test/elf/Mips/plt-entry-mixed-4.test b/test/elf/Mips/plt-entry-mixed-4.test new file mode 100644 index 000000000000..acf5060621f6 --- /dev/null +++ b/test/elf/Mips/plt-entry-mixed-4.test @@ -0,0 +1,85 @@ +# REQUIRES: mips + +# Conditions: +# a) Object file contains R_MIPS_26 relocation refers to the microMIPS symbol. +# Check: +# a) PLT contains a regular non-compressed entry. + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t.so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t.o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o.o %t.so +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# FIXME (simon): Check the disassembler output when llvm-objdump starts +# to support microMIPS instruction encoding. + +# CHECK: Contents of section .plt: +# CHECK-NEXT: 400170 40001c3c 0020998f 00209c27 23c01c03 @..<. ... .'#... +# CHECK-NEXT: 400180 2178e003 82c01800 09f82003 feff1827 !x........ ....' +# CHECK-NEXT: 400190 40000f3c 0820f98d 08002003 0820f825 @..<. .... .. .% + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + Other: [STO_MIPS_MICROMIPS] + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "0000000C00000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x0 + Symbol: T1 + Type: R_MIPS_26 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 0x8 + - Name: T1 +... diff --git a/test/elf/Mips/plt-entry-r6.test b/test/elf/Mips/plt-entry-r6.test new file mode 100644 index 000000000000..bb05531487ff --- /dev/null +++ b/test/elf/Mips/plt-entry-r6.test @@ -0,0 +1,109 @@ +# REQUIRES: mips + +# Check generation of PLT entries in case of R6 target ABI. + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-objdump -d %t.exe | FileCheck %s + +# CHECK: Disassembly of section .plt: +# CHECK-NEXT: .plt: +# CHECK-NEXT: 400160: 40 00 1c 3c lui $gp, 64 +# CHECK-NEXT: 400164: 00 20 99 8f lw $25, 8192($gp) +# CHECK-NEXT: 400168: 00 20 9c 27 addiu $gp, $gp, 8192 +# CHECK-NEXT: 40016c: 23 c0 1c 03 subu $24, $24, $gp +# CHECK-NEXT: 400170: 21 78 e0 03 move $15, $ra +# CHECK-NEXT: 400174: 82 c0 18 00 srl $24, $24, 2 +# CHECK-NEXT: 400178: 09 f8 20 03 jalr $25 +# CHECK-NEXT: 40017c: fe ff 18 27 addiu $24, $24, -2 +# CHECK-NEXT: 400180: 40 00 0f 3c lui $15, 64 +# CHECK-NEXT: 400184: 08 20 f9 8d lw $25, 8200($15) +# CHECK-NEXT: 400188: 09 00 20 03 jr $25 +# CHECK-NEXT: 40018c: 08 20 f8 25 addiu $24, $15, 8200 + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "0000000C00000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x0 + Symbol: T1 + Type: R_MIPS_26 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_HI16 + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_LO16 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 0x8 + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: T1 +... diff --git a/test/elf/Mips/plt-header-micro.test b/test/elf/Mips/plt-header-micro.test new file mode 100644 index 000000000000..ce042741cd32 --- /dev/null +++ b/test/elf/Mips/plt-header-micro.test @@ -0,0 +1,108 @@ +# REQUIRES: mips + +# Check initialization of .plt header entries +# if all PLT entries use microMIPS encoding. + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so +# RUN: llvm-objdump -d -mattr=micromips %t.exe | FileCheck -check-prefix=DIS %s +# RUN: llvm-objdump -section-headers %t.exe | FileCheck -check-prefix=EXE %s + +# DIS: Disassembly of section .plt: +# DIS-NEXT: .plt: +# DIS-NEXT: 400170: 80 79 a4 07 addiupc $3, 7824 +# DIS-NEXT: 400174: 23 ff 00 00 lw $25, 0($3) +# DIS-NEXT: 400178: 35 05 subu16 $2, $2, $3 +# DIS-NEXT: 40017a: 25 25 srl16 $2, $2, 2 +# DIS-NEXT: 40017c: 02 33 fe ff addiu $24, $2, -2 +# DIS-NEXT: 400180: ff 0d move $15, $ra +# DIS-NEXT: 400182: f9 45 jalrs16 $25 +# DIS-NEXT: 400184: 83 0f move $gp, $3 +# DIS-NEXT: 400186: 00 0c nop + +# DIS-NEXT: 400188: 00 79 a0 07 addiupc $2, 7808 +# DIS-NEXT: 40018c: 22 ff 00 00 lw $25, 0($2) +# DIS-NEXT: 400190: 99 45 jr16 $25 +# DIS-NEXT: 400192: 02 0f move $24, $2 + +# EXE: Sections: +# EXE: Idx Name Size Address Type +# EXE: 6 .plt 00000024 0000000000400170 TEXT DATA +# EXE: 10 .got.plt 0000000c 0000000000402000 DATA + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: '000000000000000000f4000000000000f400000000000000f400000000000000' +# jal .text jal glob jal T1 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x08 + Symbol: .text + Type: R_MICROMIPS_26_S1 + - Offset: 0x10 + Symbol: glob + Type: R_MICROMIPS_26_S1 + - Offset: 0x18 + Symbol: T1 + Type: R_MICROMIPS_26_S1 + +Symbols: + Local: + - Name: loc + Section: .text + Value: 0x10 + Other: [ STO_MIPS_MICROMIPS ] + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 +... diff --git a/test/elf/Mips/plt-header-mixed.test b/test/elf/Mips/plt-header-mixed.test new file mode 100644 index 000000000000..0d3af19ee593 --- /dev/null +++ b/test/elf/Mips/plt-header-mixed.test @@ -0,0 +1,105 @@ +# REQUIRES: mips + +# Check initialization of .plt header entries if there are both regular +# and microMIPS encoded PLT entries. Check that R_MIPS_26 and R_MICROMIPS_26_S1 +# relocation with the same target cause generation of two distinct PLT entries. + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e globR -o %t.exe %t-o.o %t.so +# RUN: llvm-objdump -d %t.exe | FileCheck -check-prefix=DIS %s +# RUN: llvm-objdump -section-headers %t.exe | FileCheck -check-prefix=EXE %s + +# DIS: Disassembly of section .plt: +# DIS-NEXT: .plt: +# DIS-NEXT: 400170: 40 00 1c 3c lui $gp, 64 +# DIS-NEXT: 400174: 00 20 99 8f lw $25, 8192($gp) +# DIS-NEXT: 400178: 00 20 9c 27 addiu $gp, $gp, 8192 +# DIS-NEXT: 40017c: 23 c0 1c 03 subu $24, $24, $gp +# DIS-NEXT: 400180: 21 78 e0 03 move $15, $ra +# DIS-NEXT: 400184: 82 c0 18 00 srl $24, $24, 2 +# DIS-NEXT: 400188: 09 f8 20 03 jalr $25 +# DIS-NEXT: 40018c: fe ff 18 27 addiu $24, $24, -2 + +# DIS-NEXT: 400190: 40 00 0f 3c lui $15, 64 +# DIS-NEXT: 400194: 08 20 f9 8d lw $25, 8200($15) +# DIS-NEXT: 400198: 08 00 20 03 jr $25 +# DIS-NEXT: 40019c: 08 20 f8 25 addiu $24, $15, 8200 + +# FIXME (simon): Check micromips PLT entry +# DIS-NEXT: 4001a8: 99 45 02 0f jal 201922148 + +# EXE: Sections: +# EXE: Idx Name Size Address Type +# EXE: 6 .plt 0000003c 0000000000400170 TEXT DATA +# EXE: 10 .got.plt 0000000c 0000000000402000 DATA + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x8 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x0 + Symbol: T1 + Type: R_MIPS_26 + - Offset: 0x4 + Symbol: T1 + Type: R_MICROMIPS_26_S1 + +Symbols: + Global: + - Name: globR + Section: .text + Value: 0x0 + Size: 0x4 + - Name: globM + Section: .text + Value: 0x4 + Size: 0x4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 +... diff --git a/test/elf/Mips/plt-header.test b/test/elf/Mips/plt-header.test new file mode 100644 index 000000000000..caf7e83ea5e2 --- /dev/null +++ b/test/elf/Mips/plt-header.test @@ -0,0 +1,99 @@ +# REQUIRES: mips + +# Check initialization of .plt header entries. + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so +# RUN: llvm-objdump -section-headers -disassemble %t.exe | \ +# RUN: FileCheck -check-prefix=EXE %s + +# EXE: Disassembly of section .plt: +# EXE: .plt: +# PLT0 entry. Points to the .got.plt[0] +# EXE-NEXT: 400160: 40 00 1c 3c lui $gp, 64 +# EXE-NEXT: 400164: 00 20 99 8f lw $25, 8192($gp) +# EXE-NEXT: 400168: 00 20 9c 27 addiu $gp, $gp, 8192 +# EXE-NEXT: 40016c: 23 c0 1c 03 subu $24, $24, $gp +# EXE-NEXT: 400170: 21 78 e0 03 move $15, $ra +# EXE-NEXT: 400174: 82 c0 18 00 srl $24, $24, 2 +# EXE-NEXT: 400178: 09 f8 20 03 jalr $25 +# EXE-NEXT: 40017c: fe ff 18 27 addiu $24, $24, -2 + +# EXE: Sections: +# EXE: Idx Name Size Address Type +# EXE: 6 .plt 00000030 0000000000400160 TEXT DATA +# EXE: 10 .got.plt 0000000c 0000000000402000 DATA + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x20 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x08 + Symbol: .text + Type: R_MIPS_26 + - Offset: 0x10 + Symbol: glob + Type: R_MIPS_26 + - Offset: 0x18 + Symbol: T1 + Type: R_MIPS_26 + +Symbols: + Local: + - Name: loc + Section: .text + Value: 0x10 + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + - Name: T1 +... diff --git a/test/elf/Mips/r26-1-micro.test b/test/elf/Mips/r26-1-micro.test new file mode 100644 index 000000000000..629754febc7e --- /dev/null +++ b/test/elf/Mips/r26-1-micro.test @@ -0,0 +1,131 @@ +# REQUIRES: mips + +# Check handling of R_MICROMIPS_26_S1 relocation. + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: llvm-readobj -relocations %t-o.o | \ +# RUN: FileCheck -check-prefix=OBJ-REL %s +# RUN: lld -flavor gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -relocations %t.exe | FileCheck -check-prefix=EXE-REL %s +# RUN: llvm-objdump -section-headers %t.exe | FileCheck -check-prefix=EXE %s +# RUN: llvm-objdump -s -d -mattr=micromips %t.exe | \ +# RUN: FileCheck -check-prefix=DIS %s + +# Object file has three R_MICROMIPS_26_S1 relocations +# OBJ-REL: Relocations [ +# OBJ-REL-NEXT: Section (2) .rel.text { +# OBJ-REL-NEXT: 0x8 R_MICROMIPS_26_S1 loc 0x0 +# OBJ-REL-NEXT: 0x10 R_MICROMIPS_26_S1 glob 0x0 +# OBJ-REL-NEXT: 0x18 R_MICROMIPS_26_S1 T1 0x0 +# OBJ-REL-NEXT: } +# OBJ-REL-NEXT: ] + +# Executable file has the only relocation for external symbol +# EXE-REL: Relocations [ +# EXE-REL-NEXT: Section (5) .rel.plt { +# EXE-REL-NEXT: 0x402008 R_MIPS_JUMP_SLOT T1 0x0 +# EXE-REL-NEXT: } +# EXE-REL-NEXT: ] + +# EXE: Sections: +# EXE: Idx Name Size Address Type +# EXE: 6 .plt 00000024 0000000000400160 TEXT DATA +# EXE: 10 .got.plt 0000000c 0000000000402000 DATA + +# DIS: Disassembly of section .plt: +# DIS-NEXT: .plt: +# DIS-NEXT: 400160: 80 79 a8 07 addiupc $3, 7840 +# DIS-NEXT: 400164: 23 ff 00 00 lw $25, 0($3) +# DIS-NEXT: 400168: 35 05 subu16 $2, $2, $3 +# DIS-NEXT: 40016a: 25 25 srl16 $2, $2, 2 +# DIS-NEXT: 40016c: 02 33 fe ff addiu $24, $2, -2 +# DIS-NEXT: 400170: ff 0d move $15, $ra +# DIS-NEXT: 400172: f9 45 jalrs16 $25 +# DIS-NEXT: 400174: 83 0f move $gp, $3 +# DIS-NEXT: 400176: 00 0c nop + +# DIS-NEXT: 400178: 00 79 a4 07 addiupc $2, 7824 +# DIS-NEXT: 40017c: 22 ff 00 00 lw $25, 0($2) +# DIS-NEXT: 400180: 99 45 jr16 $25 +# DIS-NEXT: 400182: 02 0f move $24, $2 + +# DIS: Contents of section .text: +# DIS-NEXT: 400184 09f82003 00000000 2400ca0c 00000000 .. .....$....... +# DIS-NEXT: 400194 2000c20c 00000000 2000bc0c 00000000 ....... ....... + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: '09F82003000000000400000C000000000000000C000000000000000C00000000' + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x08 + Symbol: loc + Type: R_MICROMIPS_26_S1 + - Offset: 0x10 + Symbol: glob + Type: R_MICROMIPS_26_S1 + - Offset: 0x18 + Symbol: T1 + Type: R_MICROMIPS_26_S1 + +Symbols: + Local: + - Name: loc + Section: .text + Value: 0x10 + Other: [ STO_MIPS_MICROMIPS ] + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 +... diff --git a/test/elf/Mips/r26-1.test b/test/elf/Mips/r26-1.test new file mode 100644 index 000000000000..abc0a7ce5a81 --- /dev/null +++ b/test/elf/Mips/r26-1.test @@ -0,0 +1,132 @@ +# REQUIRES: mips + +# Check handling of R_MIPS_26 relocation. + +# Build shared library +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Build executable +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: llvm-readobj -relocations %t-o.o | \ +# RUN: FileCheck -check-prefix=OBJ-REL %s +# RUN: lld -flavor gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so +# RUN: llvm-objdump -section-headers -disassemble %t.exe | \ +# RUN: FileCheck -check-prefix=EXE %s +# RUN: llvm-readobj -relocations %t.exe | FileCheck -check-prefix=EXE-REL %s + +# Object file has three R_MIPS_26 relocations +# OBJ-REL: Relocations [ +# OBJ-REL-NEXT: Section (2) .rel.text { +# OBJ-REL-NEXT: 0x8 R_MIPS_26 .text 0x0 +# OBJ-REL-NEXT: 0x10 R_MIPS_26 glob 0x0 +# OBJ-REL-NEXT: 0x18 R_MIPS_26 T1 0x0 +# OBJ-REL-NEXT: } +# OBJ-REL-NEXT: ] + +# Executable file has the only relocation for external symbol +# EXE-REL: Relocations [ +# EXE-REL-NEXT: Section (5) .rel.plt { +# EXE-REL-NEXT: 0x402008 R_MIPS_JUMP_SLOT T1 0x0 +# EXE-REL-NEXT: } +# EXE-REL-NEXT: ] + +# EXE: Disassembly of section .plt: +# EXE: .plt: +# PLTA entry. Points to the .got.plt[1] +# EXE: 400180: 40 00 0f 3c lui $15, 64 +# EXE-NEXT: 400184: 08 20 f9 8d lw $25, 8200($15) +# EXE-NEXT: 400188: 08 00 20 03 jr $25 +# EXE-NEXT: 40018c: 08 20 f8 25 addiu $24, $15, 8200 + +# EXE: Disassembly of section .text: +# EXE: glob: +# EXE-NEXT: 400190: 09 f8 20 03 jalr $25 +# EXE-NEXT: 400194: 00 00 00 00 nop +# +# Jump to 'loc' label address +# EXE-NEXT: 400198: 68 00 10 0c jal 4194720 +# EXE-NEXT: 40019c: 00 00 00 00 nop +# +# EXE: loc: +# Jump to 'glob' label address +# EXE-NEXT: 4001a0: 64 00 10 0c jal 4194704 +# EXE-NEXT: 4001a4: 00 00 00 00 nop +# +# Jump to the first PLT entry (.plt + 32) for T1 entry +# EXE-NEXT: 4001a8: 60 00 10 0c jal 4194688 +# EXE-NEXT: 4001ac: 00 00 00 00 nop + +# EXE: Sections: +# EXE: Idx Name Size Address Type +# EXE: 6 .plt 00000030 0000000000400160 TEXT DATA +# EXE: 10 .got.plt 0000000c 0000000000402000 DATA + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: '09F82003000000000400000C000000000000000C000000000000000C00000000' + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x08 + Symbol: .text + Type: R_MIPS_26 + - Offset: 0x10 + Symbol: glob + Type: R_MIPS_26 + - Offset: 0x18 + Symbol: T1 + Type: R_MIPS_26 + +Symbols: + Local: + - Name: loc + Section: .text + Value: 0x10 + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: glob + Section: .text + - Name: T1 +... diff --git a/test/elf/Mips/r26-2-micro.test b/test/elf/Mips/r26-2-micro.test new file mode 100644 index 000000000000..b92b9acf4c84 --- /dev/null +++ b/test/elf/Mips/r26-2-micro.test @@ -0,0 +1,88 @@ +# REQUIRES: mips + +# Check reading addendum for R_MICROMIPS_26_S1 relocation. +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj +# RUN: llvm-objdump -d -mattr=micromips %t-exe | FileCheck -check-prefix=DIS %s +# RUN: llvm-objdump -t %t-exe | FileCheck %s + +# DIS: Disassembly of section .text: +# DIS-NEXT: loc0: +# DIS-NEXT: 400110: 00 00 00 00 nop + +# DIS: __start: +# DIS-NEXT: 400114: 20 f4 8e e0 jal 4309276 +# DIS-NEXT: 400118: 00 00 00 00 nop +# DIS-NEXT: 40011c: 20 f4 9a e0 jal 4309300 +# DIS-NEXT: 400120: 00 00 00 00 nop + +# DIS: loc1: +# DIS-NEXT: 400124: 20 f4 89 00 jal 4194578 +# DIS-NEXT: 400128: 00 00 00 00 nop +# DIS-NEXT: 40012c: 20 f4 91 00 jal 4194594 +# DIS-NEXT: 400130: 00 00 00 00 nop + +# CHECK: SYMBOL TABLE: +# CHECK: 00400124 l F .text 00000010 loc1 +# CHECK: 00400114 g F .text 00000010 __start + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: +- Name: .text + Type: SHT_PROGBITS +# nop +# jal __start + 0x1C000 +# nop +# jal loc + 0x1C000 +# nop +# jal __start + 7FFFFE2 +# nop +# jal loc + 7FFFFEA +# nop + Content: "0000000000f404e00000000000f408e000000000FFF7FFFF00000000FFF7FFFF00000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x4 + Symbol: __start + Type: R_MICROMIPS_26_S1 + - Offset: 0xC + Symbol: loc1 + Type: R_MICROMIPS_26_S1 + - Offset: 0x14 + Symbol: __start + Type: R_MICROMIPS_26_S1 + - Offset: 0x1C + Symbol: loc1 + Type: R_MICROMIPS_26_S1 + +Symbols: + Global: + - Name: __start + Section: .text + Value: 0x4 + Size: 8 + Other: [ STO_MIPS_MICROMIPS ] + Local: + - Name: loc0 + Section: .text + Value: 0 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: loc1 + Section: .text + Value: 0x14 + Size: 8 + Other: [ STO_MIPS_MICROMIPS ] diff --git a/test/elf/Mips/r26-2.test b/test/elf/Mips/r26-2.test new file mode 100644 index 000000000000..0f0063ae1334 --- /dev/null +++ b/test/elf/Mips/r26-2.test @@ -0,0 +1,82 @@ +# REQUIRES: mips + +# Check reading addendum for R_MIPS_26 relocation. +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj +# RUN: llvm-objdump -t -disassemble %t-exe | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK-NEXT: __start: +# CHECK-NEXT: 400110: 00 00 00 00 nop +# CHECK-NEXT: 400114: 44 70 10 0c jal 4309264 +# 0x107044 << 2 = 0x41C110 = _start + (0x7000 << 2) +# CHECK-NEXT: 400118: 00 00 00 00 nop +# +# CHECK: loc: +# CHECK-NEXT: 40011c: 47 70 10 0c jal 4309276 +# 0x107047 << 2 = 0x41C11C = loc + (0x7000 << 2) +# CHECK-NEXT: 400120: 00 00 00 00 nop +# CHECK-NEXT: 400124: 43 00 10 0c jal 4194572 +# 0x100043 << 2 = 0x40010C = _start - 4 +# CHECK-NEXT: 400128: 00 00 00 00 nop +# CHECK-NEXT: 40012c: 46 00 10 0c jal 4194584 +# 0x100046 << 2 = 0x400118 = loc - 4 +# CHECK-NEXT: 400130: 00 00 00 00 nop + +# CHECK: SYMBOL TABLE: +# CHECK: 0040011c l F .text 00000018 loc +# CHECK: 00400110 g F .text 0000000c __start + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS +# nop +# jal __start + 0x1C000 +# nop +# jal loc + 0x1C000 +# nop +# jal __start - 1 +# nop +# jal loc - 1 +# nop + Content: "000000000070000C000000000070000C00000000FFFFFF0F00000000FFFFFF0F00000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x4 + Symbol: __start + Type: R_MIPS_26 + - Offset: 0xC + Symbol: loc + Type: R_MIPS_26 + - Offset: 0x14 + Symbol: __start + Type: R_MIPS_26 + - Offset: 0x1C + Symbol: loc + Type: R_MIPS_26 + +Symbols: + Global: + - Name: __start + Section: .text + Value: 0x0 + Size: 4 + Local: + - Name: loc + Section: .text + Value: 0xc + Size: 4 diff --git a/test/elf/Mips/rel-32.test b/test/elf/Mips/rel-32.test new file mode 100644 index 000000000000..beefde59b7b1 --- /dev/null +++ b/test/elf/Mips/rel-32.test @@ -0,0 +1,59 @@ +# Check handling of R_MIPS_32 relocation. +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj +# RUN: llvm-objdump -s -t %t-exe | FileCheck %s + +# CHECK: Contents of section .data: +# CHECK-NEXT: 402000 00000000 09204080 05204080 ..... @.. @. +# ^^ data2 + 0x80000001 = 0x80402009 +# ^^ data1 + 0x80000001 = 0x80402005 +# CHECK: SYMBOL TABLE: +# CHECK: 00402004 g .data 00000004 data1 +# CHECK: 00402008 g .data 00000004 data2 + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "00000000" + AddressAlign: 16 + Flags: [SHF_ALLOC] +- Name: .data + Type: SHT_PROGBITS + Content: "000000000100008001000080" + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_WRITE] + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x4 + Symbol: data2 + Type: R_MIPS_32 + - Offset: 0x8 + Symbol: data1 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: __start + Section: .text + Value: 0x0 + Size: 4 + - Name: data1 + Section: .data + Value: 0x4 + Size: 4 + - Name: data2 + Section: .data + Value: 0x8 + Size: 4 diff --git a/test/elf/Mips/rel-64.test b/test/elf/Mips/rel-64.test new file mode 100644 index 000000000000..e05b75687038 --- /dev/null +++ b/test/elf/Mips/rel-64.test @@ -0,0 +1,61 @@ +# Check handling of R_MIPS_64 relocation. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mips64el -o %t.exe %t.o +# RUN: llvm-objdump -s -t %t.exe | FileCheck %s + +# CHECK: Contents of section .data: +# CHECK-NEXT: 120002000 d1010020 01000000 d0010020 01000100 ... ....... .... +# ^^ __start + 1 = 0x1200001d1 +# ^^ __start + 0x1000000000000 +# = 0x10001200001d0 +# CHECK: SYMBOL TABLE: +# CHECK: 00000001200001d0 g .rodata 00000008 __start + +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_ALLOC] +- Name: .data + Type: SHT_PROGBITS + Size: 0x10 + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_WRITE] + +- Name: .rela.data + Type: SHT_RELA + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x0 + Symbol: __start + Type: R_MIPS_64 + Addend: 1 + - Offset: 0x8 + Symbol: __start + Type: R_MIPS_64 + Addend: 0x1000000000000 + +Symbols: + Global: + - Name: __start + Section: .text + Value: 0x0 + Size: 8 + - Name: data1 + Section: .data + Value: 0x0 + Size: 8 + - Name: data2 + Section: .data + Value: 0x8 + Size: 8 diff --git a/test/elf/Mips/rel-copy-micro.test b/test/elf/Mips/rel-copy-micro.test new file mode 100644 index 000000000000..afa99198e37f --- /dev/null +++ b/test/elf/Mips/rel-copy-micro.test @@ -0,0 +1,159 @@ +# Check R_MIPS_COPY relocation emitting +# when linking non-shared executable file. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so1.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t1.so %t-so1.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-so2.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t2.so %t-so2.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t1.so %t2.so +# RUN: llvm-readobj -dt -r -dynamic-table %t.exe | FileCheck %s + +# CHECK: Relocations [ +# CHECK-NEXT: Section (5) .rel.dyn { +# CHECK-NEXT: 0x402010 R_MIPS_COPY D1 0x0 +# CHECK-NEXT: 0x402018 R_MIPS_COPY D2 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSymbols [ +# 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: D1@ (1) +# CHECK-NEXT: Value: 0x402010 +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .bss (0xA) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D2@ (4) +# CHECK-NEXT: Value: 0x402018 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .bss (0xA) +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSection [ ({{.*}} entries) +# CHECK: 0x00000001 NEEDED SharedLibrary (rel-copy-micro.test.tmp1.so) +# CHECK: 0x00000001 NEEDED SharedLibrary (rel-copy-micro.test.tmp2.so) +# CHECK-NEXT: 0x00000000 NULL 0x0 +# CHECK-NEXT: ] + +# so1.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + +# so2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .data + Type: SHT_PROGBITS + Size: 0x04 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: D1 + Type: R_MICROMIPS_HI16 + - Offset: 0x00 + Symbol: D1 + Type: R_MICROMIPS_LO16 + - Offset: 0x08 + Symbol: D2 + Type: R_MICROMIPS_HI16 + - Offset: 0x08 + Symbol: D2 + Type: R_MICROMIPS_LO16 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + Other: [ STO_MIPS_MICROMIPS ] + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 +... diff --git a/test/elf/Mips/rel-copy-pc.test b/test/elf/Mips/rel-copy-pc.test new file mode 100644 index 000000000000..2dd702334fed --- /dev/null +++ b/test/elf/Mips/rel-copy-pc.test @@ -0,0 +1,113 @@ +# Check R_MIPS_COPY relocation emitting caused by R_MIPS_PCHI16 / R_MIPS_PCLO16 +# relocations when linking non-shared executable file. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dt -r -dynamic-table %t.exe | FileCheck %s + +# CHECK: Relocations [ +# CHECK-NEXT: Section (5) .rel.dyn { +# CHECK-NEXT: 0x402008 R_MIPS_COPY D1 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSymbols [ +# 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: D1@ (1) +# CHECK-NEXT: Value: 0x402008 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .bss (0xA) +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSection [ ({{.*}} entries) +# CHECK: 0x00000001 NEEDED SharedLibrary (rel-copy-pc.test.tmp.so) +# CHECK-NEXT: 0x00000000 NULL 0x0 +# CHECK-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: +- Name: .data + Type: SHT_PROGBITS + Size: 4 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 4 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 4 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: D1 + Type: R_MIPS_PCHI16 + - Offset: 0 + Symbol: D1 + Type: R_MIPS_PCLO16 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0 + Size: 4 + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0 + Size: 4 + - Name: D1 +... diff --git a/test/elf/Mips/rel-copy.test b/test/elf/Mips/rel-copy.test new file mode 100644 index 000000000000..648a25e22ae7 --- /dev/null +++ b/test/elf/Mips/rel-copy.test @@ -0,0 +1,177 @@ +# Check R_MIPS_COPY relocation emitting +# when linking non-shared executable file. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so1.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t1.so %t-so1.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-so2.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t2.so %t-so2.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t1.so %t2.so +# RUN: llvm-readobj -dt -r -dynamic-table %t.exe | FileCheck %s + +# CHECK: Relocations [ +# CHECK-NEXT: Section (5) .rel.dyn { +# CHECK-NEXT: 0x402004 R_MIPS_REL32 D2 0x0 +# CHECK-NEXT: 0x402010 R_MIPS_COPY D1 0x0 +# CHECK-NEXT: 0x402018 R_MIPS_COPY D3 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSymbols [ +# 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: D1@ (1) +# CHECK-NEXT: Value: 0x402010 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .bss (0xA) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D3@ (4) +# CHECK-NEXT: Value: 0x402018 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .bss (0xA) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D2@ (7) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSection [ ({{.*}} entries) +# CHECK: 0x00000001 NEEDED SharedLibrary (rel-copy.test.tmp1.so) +# CHECK: 0x00000001 NEEDED SharedLibrary (rel-copy.test.tmp2.so) +# CHECK-NEXT: 0x00000000 NULL 0x0 +# CHECK-NEXT: ] + +# so1.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 4 + +# so2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .data + Type: SHT_PROGBITS + Size: 0x04 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: D3 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: D1 + Type: R_MIPS_HI16 + - Offset: 0x00 + Symbol: D1 + Type: R_MIPS_LO16 + - Offset: 0x04 + Symbol: D2 + Type: R_MIPS_32 + - Offset: 0x08 + Symbol: D3 + Type: R_MIPS_HI16 + - Offset: 0x08 + Symbol: D3 + Type: R_MIPS_LO16 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + - Name: D3 +... diff --git a/test/elf/Mips/rel-dynamic-01-micro.test b/test/elf/Mips/rel-dynamic-01-micro.test new file mode 100644 index 000000000000..6e0a41bf2606 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-01-micro.test @@ -0,0 +1,201 @@ +# REQUIRES: mips + +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are symbols defined in the shared object. +# Check: +# a) Emitting R_MIPS_COPY, R_MIPS_JUMP_SLOT relocations. +# b) PLT entries creation. +# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require +# a pointer equality. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-objdump -d -mattr=micromips %t.exe | FileCheck -check-prefix=DIS %s +# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s + +# DIS: Disassembly of section .plt: +# DIS-NEXT: .plt: +# DIS-NEXT: 4001b0: 80 79 94 07 addiupc $3, 7760 +# DIS-NEXT: 4001b4: 23 ff 00 00 lw $25, 0($3) +# DIS-NEXT: 4001b8: 35 05 subu16 $2, $2, $3 +# DIS-NEXT: 4001ba: 25 25 srl16 $2, $2, 2 +# DIS-NEXT: 4001bc: 02 33 fe ff addiu $24, $2, -2 +# DIS-NEXT: 4001c0: ff 0d move $15, $ra +# DIS-NEXT: 4001c2: f9 45 jalrs16 $25 +# DIS-NEXT: 4001c4: 83 0f move $gp, $3 +# DIS-NEXT: 4001c6: 00 0c nop + +# DIS-NEXT: 4001c8: 00 79 90 07 addiupc $2, 7744 +# DIS-NEXT: 4001cc: 22 ff 00 00 lw $25, 0($2) +# DIS-NEXT: 4001d0: 99 45 jr16 $25 +# DIS-NEXT: 4001d2: 02 0f move $24, $2 + +# DIS-NEXT: 4001d4: 00 79 8e 07 addiupc $2, 7736 +# DIS-NEXT: 4001d8: 22 ff 00 00 lw $25, 0($2) +# DIS-NEXT: 4001dc: 99 45 jr16 $25 +# DIS-NEXT: 4001de: 02 0f move $24, $2 + +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: Section (5) .rel.dyn { +# PLT-SYM-NEXT: 0x402018 R_MIPS_COPY D1 0x0 +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Section (6) .rel.plt { +# PLT-SYM-NEXT: 0x402008 R_MIPS_JUMP_SLOT T3 0x0 +# PLT-SYM-NEXT: 0x40200C R_MIPS_JUMP_SLOT T1 0x0 +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +# PLT-SYM: DynamicSymbols [ +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: @ (0) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Local (0x0) +# PLT-SYM-NEXT: Type: None (0x0) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: D1@ (1) +# PLT-SYM-NEXT: Value: 0x402018 +# PLT-SYM-NEXT: Size: 8 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Object (0x1) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: .bss (0xD) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: T1@ (4) +# PLT-SYM-NEXT: Value: 0x4001D5 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Function (0x2) +# PLT-SYM-NEXT: Other: 8 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: T3@ (7) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Function (0x2) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T3 + Section: .text + Type: STT_FUNC + Value: 0x8 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + +# o.o +--- +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x04 + Symbol: T3 + Type: R_MICROMIPS_26_S1 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MICROMIPS_HI16 + - Offset: 0x00 + Symbol: T1 + Type: R_MICROMIPS_LO16 + - Offset: 0x04 + Symbol: D1 + Type: R_MICROMIPS_HI16 + - Offset: 0x04 + Symbol: D1 + Type: R_MICROMIPS_LO16 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 + Type: STT_FUNC + - Name: T3 + Type: STT_FUNC + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: D1 + Type: STT_OBJECT +... diff --git a/test/elf/Mips/rel-dynamic-01.test b/test/elf/Mips/rel-dynamic-01.test new file mode 100644 index 000000000000..ca4619668bd2 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-01.test @@ -0,0 +1,237 @@ +# REQUIRES: mips + +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are symbols defined in the shared object. +# Check: +# a) Emitting R_MIPS_REL32, R_MIPS_COPY, R_MIPS_JUMP_SLOT relocations. +# b) PLT entries creation. +# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require +# a pointer equality. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-objdump -disassemble %t.exe | FileCheck -check-prefix=PLT %s +# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s + +# PLT: Disassembly of section .plt: +# PLT-NEXT: .plt: +# PLT-NEXT: 4001f0: 40 00 1c 3c lui $gp, 64 +# PLT-NEXT: 4001f4: 00 20 99 8f lw $25, 8192($gp) +# PLT-NEXT: 4001f8: 00 20 9c 27 addiu $gp, $gp, 8192 +# PLT-NEXT: 4001fc: 23 c0 1c 03 subu $24, $24, $gp +# PLT-NEXT: 400200: 21 78 e0 03 move $15, $ra +# PLT-NEXT: 400204: 82 c0 18 00 srl $24, $24, 2 +# PLT-NEXT: 400208: 09 f8 20 03 jalr $25 +# PLT-NEXT: 40020c: fe ff 18 27 addiu $24, $24, -2 +# +# PLT-NEXT: 400210: 40 00 0f 3c lui $15, 64 +# PLT-NEXT: 400214: 08 20 f9 8d lw $25, 8200($15) +# PLT-NEXT: 400218: 08 00 20 03 jr $25 +# PLT-NEXT: 40021c: 08 20 f8 25 addiu $24, $15, 8200 +# +# PLT-NEXT: 400220: 40 00 0f 3c lui $15, 64 +# PLT-NEXT: 400224: 0c 20 f9 8d lw $25, 8204($15) +# PLT-NEXT: 400228: 08 00 20 03 jr $25 +# PLT-NEXT: 40022c: 0c 20 f8 25 addiu $24, $15, 8204 + +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: Section (5) .rel.dyn { +# PLT-SYM-NEXT: 0x402014 R_MIPS_REL32 T2 0x0 +# PLT-SYM-NEXT: 0x402014 R_MIPS_REL32 D2 0x0 +# PLT-SYM-NEXT: 0x402018 R_MIPS_COPY D1 0x0 +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Section (6) .rel.plt { +# PLT-SYM-NEXT: 0x402008 R_MIPS_JUMP_SLOT T3 0x0 +# PLT-SYM-NEXT: 0x40200C R_MIPS_JUMP_SLOT T1 0x0 +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +# PLT-SYM: DynamicSymbols [ +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: @ (0) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Local (0x0) +# PLT-SYM-NEXT: Type: None (0x0) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: D1@ (1) +# PLT-SYM-NEXT: Value: 0x402018 +# PLT-SYM-NEXT: Size: 4 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Object (0x1) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: .bss (0xD) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: T1@ (4) +# PLT-SYM-NEXT: Value: 0x400220 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Function (0x2) +# PLT-SYM-NEXT: Other: 8 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: T3@ (10) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Function (0x2) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: T2@ (7) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Function (0x2) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: D2@ (13) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 4 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Object (0x1) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: T3 + Section: .text + Type: STT_FUNC + Value: 0x8 + Size: 4 + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 4 + +# o.o +--- +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x04 + Symbol: T3 + Type: R_MIPS_26 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_HI16 + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_LO16 + - Offset: 0x04 + Symbol: T2 + Type: R_MIPS_32 + + - Offset: 0x04 + Symbol: D1 + Type: R_MIPS_HI16 + - Offset: 0x04 + Symbol: D1 + Type: R_MIPS_LO16 + - Offset: 0x04 + Symbol: D2 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: T2 + Type: STT_FUNC + - Name: T3 + Type: STT_FUNC + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + Type: STT_OBJECT +... diff --git a/test/elf/Mips/rel-dynamic-02.test b/test/elf/Mips/rel-dynamic-02.test new file mode 100644 index 000000000000..4de86383482c --- /dev/null +++ b/test/elf/Mips/rel-dynamic-02.test @@ -0,0 +1,82 @@ +# Conditions: +# a) Linking a shared library. +# b) Relocations' targets are undefined symbols. +# Check: +# a) Emitting R_MIPS_REL32 relocations for both undefined symbols. +# b) There should be no PLT entries. +# +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec -o %t1-so %t-obj +# RUN: llvm-readobj -dt -r -s %t1-so | FileCheck -check-prefix=PLT-SYM %s + +# PLT-SYM: Sections [ +# PLT-SYM: Section { +# PLT-SYM-NOT: Name: .plt ({{[0-9]+}}) +# +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: Section (4) .rel.dyn { +# PLT-SYM-NEXT: 0x140 R_MIPS_REL32 T1 0x0 +# PLT-SYM-NEXT: 0x2000 R_MIPS_REL32 T1 0x0 +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] +# +# PLT-SYM: Name: T1@ (7) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: None (0x0) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_32 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T1 + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 diff --git a/test/elf/Mips/rel-dynamic-03-micro.test b/test/elf/Mips/rel-dynamic-03-micro.test new file mode 100644 index 000000000000..5de2cdcdc131 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-03-micro.test @@ -0,0 +1,133 @@ +# REQUIRES: mips + +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' target is a symbol defined in the shared object. +# c) The target symbol is referenced by both branch (R_MICROMIPS_26_S1) +# and regular (R_MIPS_32) relocations. +# Check: +# a) There should be no R_MIPS_REL32 relocation. +# b) Linker creates a single PLT entry. +# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require +# a pointer equality. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-objdump -d -mattr=micromips %t.exe | FileCheck -check-prefix=DIS %s +# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s + +# DIS: Disassembly of section .plt: +# DIS-NEXT: .plt: +# DIS-NEXT: 400170: 80 79 a4 07 addiupc $3, 7824 +# DIS-NEXT: 400174: 23 ff 00 00 lw $25, 0($3) +# DIS-NEXT: 400178: 35 05 subu16 $2, $2, $3 +# DIS-NEXT: 40017a: 25 25 srl16 $2, $2, 2 +# DIS-NEXT: 40017c: 02 33 fe ff addiu $24, $2, -2 +# DIS-NEXT: 400180: ff 0d move $15, $ra +# DIS-NEXT: 400182: f9 45 jalrs16 $25 +# DIS-NEXT: 400184: 83 0f move $gp, $3 +# DIS-NEXT: 400186: 00 0c nop + +# DIS-NEXT: 400188: 00 79 a0 07 addiupc $2, 7808 +# DIS-NEXT: 40018c: 22 ff 00 00 lw $25, 0($2) +# DIS-NEXT: 400190: 99 45 jr16 $25 +# DIS-NEXT: 400192: 02 0f move $24, $2 + +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: Section (5) .rel.plt { +# PLT-SYM-NEXT: 0x402008 R_MIPS_JUMP_SLOT T1 0x0 +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +# PLT-SYM: Name: T1@ (1) +# PLT-SYM-NEXT: Value: 0x400189 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Function (0x2) +# PLT-SYM-NEXT: Other: 8 +# PLT-SYM-NEXT: Section: Undefined (0x0) + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + +# o.o +--- +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x04 + Symbol: T1 + Type: R_MICROMIPS_26_S1 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x04 + Symbol: T1 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 + Type: STT_FUNC + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 +... diff --git a/test/elf/Mips/rel-dynamic-03.test b/test/elf/Mips/rel-dynamic-03.test new file mode 100644 index 000000000000..cc791b051748 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-03.test @@ -0,0 +1,129 @@ +# REQUIRES: mips + +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' target is a symbol defined in the shared object. +# c) The target symbol is referenced by both branch (R_MIPS_26) +# and regular (R_MIPS_32) relocations. +# Check: +# a) There should be no R_MIPS_REL32 relocation. +# b) Linker creates a single PLT entry. +# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require +# a pointer equality. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-objdump -disassemble %t.exe | FileCheck -check-prefix=PLT %s +# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s + +# PLT: Disassembly of section .plt: +# PLT-NEXT: .plt: +# PLT-NEXT: 400160: 40 00 1c 3c lui $gp, 64 +# PLT-NEXT: 400164: 00 20 99 8f lw $25, 8192($gp) +# PLT-NEXT: 400168: 00 20 9c 27 addiu $gp, $gp, 8192 +# PLT-NEXT: 40016c: 23 c0 1c 03 subu $24, $24, $gp +# PLT-NEXT: 400170: 21 78 e0 03 move $15, $ra +# PLT-NEXT: 400174: 82 c0 18 00 srl $24, $24, 2 +# PLT-NEXT: 400178: 09 f8 20 03 jalr $25 +# PLT-NEXT: 40017c: fe ff 18 27 addiu $24, $24, -2 +# +# PLT-NEXT: 400180: 40 00 0f 3c lui $15, 64 +# PLT-NEXT: 400184: 08 20 f9 8d lw $25, 8200($15) +# PLT-NEXT: 400188: 08 00 20 03 jr $25 +# PLT-NEXT: 40018c: 08 20 f8 25 addiu $24, $15, 8200 +# +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: Section (5) .rel.plt { +# PLT-SYM-NEXT: 0x402008 R_MIPS_JUMP_SLOT T1 0x0 +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +# PLT-SYM: Name: T1@ (1) +# PLT-SYM-NEXT: Value: 0x400180 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Function (0x2) +# PLT-SYM-NEXT: Other: 8 +# PLT-SYM-NEXT: Section: Undefined (0x0) + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x04 + Symbol: T1 + Type: R_MIPS_26 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x04 + Symbol: T1 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 +... diff --git a/test/elf/Mips/rel-dynamic-04-micro.test b/test/elf/Mips/rel-dynamic-04-micro.test new file mode 100644 index 000000000000..1c58efdf5f70 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-04-micro.test @@ -0,0 +1,211 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are symbols defined in the shared object. +# c) Relocations modify a writable section. +# d) The first symbol is referenced by R_MIPS32 relocation only +# e) The second symbol is referenced by R_MIPS_32 +# and R_MICROMIPS_26_S1 relocations. +# f) The third symbol is referenced by R_MICROMIPS_26_S1 +# and R_MIPS_32 relocations. +# Check: +# a) There should be the only R_MIPS_REL32 relocation. +# b) Linker creates a couple of PLT entry for both symbols referenced +# by the R_MICROMIPS_26_S1 branch relocation. +# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require +# a pointer equality. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT %s + +# PLT: Section { +# PLT: Index: 5 +# PLT-NEXT: Name: .rel.dyn (31) +# PLT-NEXT: Type: SHT_REL (0x9) +# PLT-NEXT: Flags [ (0x2) +# PLT-NEXT: SHF_ALLOC (0x2) +# PLT-NEXT: ] +# PLT-NEXT: Address: 0x4010A0 +# PLT-NEXT: Offset: 0x10A0 +# PLT-NEXT: Size: 8 +# PLT-NEXT: Link: 3 +# PLT-NEXT: Info: 0 +# PLT-NEXT: AddressAlignment: 4 +# PLT-NEXT: EntrySize: 8 +# PLT-NEXT: } +# PLT-NEXT: Section { +# PLT-NEXT: Index: 6 +# PLT-NEXT: Name: .rel.plt (40) +# PLT-NEXT: Type: SHT_REL (0x9) +# PLT-NEXT: Flags [ (0x2) +# PLT-NEXT: SHF_ALLOC (0x2) +# PLT-NEXT: ] +# PLT-NEXT: Address: 0x4010A8 +# PLT-NEXT: Offset: 0x10A8 +# PLT-NEXT: Size: 16 +# PLT-NEXT: Link: 3 +# PLT-NEXT: Info: 0 +# PLT-NEXT: AddressAlignment: 4 +# PLT-NEXT: EntrySize: 8 +# PLT-NEXT: } +# PLT-NEXT: Section { +# PLT-NEXT: Index: 7 +# PLT-NEXT: Name: .plt (49) +# PLT-NEXT: Type: SHT_PROGBITS (0x1) +# PLT-NEXT: Flags [ (0x6) +# PLT-NEXT: SHF_ALLOC (0x2) +# PLT-NEXT: SHF_EXECINSTR (0x4) +# PLT-NEXT: ] +# PLT-NEXT: Address: 0x4010C0 +# PLT-NEXT: Offset: 0x10C0 +# PLT-NEXT: Size: 48 +# PLT-NEXT: Link: 0 +# PLT-NEXT: Info: 0 +# PLT-NEXT: AddressAlignment: 16 +# PLT-NEXT: EntrySize: 0 +# PLT-NEXT: } + +# PLT: Relocations [ +# PLT-NEXT: Section (5) .rel.dyn { +# PLT-NEXT: 0x400120 R_MIPS_REL32 T1 0x0 +# PLT-NEXT: } +# PLT-NEXT: Section (6) .rel.plt { +# PLT-NEXT: 0x403008 R_MIPS_JUMP_SLOT T2 0x0 +# PLT-NEXT: 0x40300C R_MIPS_JUMP_SLOT T3 0x0 +# PLT-NEXT: } +# PLT-NEXT: ] + +# PLT: DynamicSymbols [ +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: @ (0) +# PLT-NEXT: Value: 0x0 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Local (0x0) +# PLT-NEXT: Type: None (0x0) +# PLT-NEXT: Other: 0 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T2@ (4) +# PLT-NEXT: Value: 0x4010D9 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 8 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T3@ (7) +# PLT-NEXT: Value: 0x4010E5 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 8 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T1@ (1) +# PLT-NEXT: Value: 0x0 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 0 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: T3 + Section: .text + Type: STT_FUNC + Value: 0x8 + Size: 4 + +# o.o +--- +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x14 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + # There is no branch relocation for T1. + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_32 + # The R_MIPS_32 relocation for T2 might produce R_MIPS_REL32 ... + - Offset: 0x04 + Symbol: T2 + Type: R_MIPS_32 + # ... but R_MICROMIPS_26_S1 creates PLT entry + # and makes R_MIPS_REL32 redundant. + - Offset: 0x08 + Symbol: T2 + Type: R_MICROMIPS_26_S1 + # Create PLT entry for T3 symbol. + - Offset: 0x0c + Symbol: T3 + Type: R_MICROMIPS_26_S1 + # Take in account existing PLT entry and do not create R_MIPS_REL32. + - Offset: 0x10 + Symbol: T3 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 0x14 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 + Type: STT_FUNC + - Name: T2 + Type: STT_FUNC + - Name: T3 + Type: STT_FUNC +... diff --git a/test/elf/Mips/rel-dynamic-04.test b/test/elf/Mips/rel-dynamic-04.test new file mode 100644 index 000000000000..5b5bcce01cd8 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-04.test @@ -0,0 +1,206 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are symbols defined in the shared object. +# c) Relocations modify a writable section. +# d) The first symbol is referenced by R_MIPS32 relocation only +# e) The second symbol is referenced by R_MIPS_32 and R_MIPS26 relocations. +# f) The third symbol is referenced by R_MIPS26 and R_MIPS_32 relocations. +# Check: +# a) There should be the only R_MIPS_REL32 relocation. +# b) Linker creates a couple of PLT entry for both symbols referenced +# by the R_MIPS_26 branch relocation. +# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require +# a pointer equality. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT %s + +# PLT: Section { +# PLT: Index: 5 +# PLT-NEXT: Name: .rel.dyn (31) +# PLT-NEXT: Type: SHT_REL (0x9) +# PLT-NEXT: Flags [ (0x2) +# PLT-NEXT: SHF_ALLOC (0x2) +# PLT-NEXT: ] +# PLT-NEXT: Address: 0x40109C +# PLT-NEXT: Offset: 0x109C +# PLT-NEXT: Size: 8 +# PLT-NEXT: Link: 3 +# PLT-NEXT: Info: 0 +# PLT-NEXT: AddressAlignment: 4 +# PLT-NEXT: EntrySize: 8 +# PLT-NEXT: } +# PLT-NEXT: Section { +# PLT-NEXT: Index: 6 +# PLT-NEXT: Name: .rel.plt (40) +# PLT-NEXT: Type: SHT_REL (0x9) +# PLT-NEXT: Flags [ (0x2) +# PLT-NEXT: SHF_ALLOC (0x2) +# PLT-NEXT: ] +# PLT-NEXT: Address: 0x4010A4 +# PLT-NEXT: Offset: 0x10A4 +# PLT-NEXT: Size: 16 +# PLT-NEXT: Link: 3 +# PLT-NEXT: Info: 0 +# PLT-NEXT: AddressAlignment: 4 +# PLT-NEXT: EntrySize: 8 +# PLT-NEXT: } +# PLT-NEXT: Section { +# PLT-NEXT: Index: 7 +# PLT-NEXT: Name: .plt (49) +# PLT-NEXT: Type: SHT_PROGBITS (0x1) +# PLT-NEXT: Flags [ (0x6) +# PLT-NEXT: SHF_ALLOC (0x2) +# PLT-NEXT: SHF_EXECINSTR (0x4) +# PLT-NEXT: ] +# PLT-NEXT: Address: 0x4010C0 +# PLT-NEXT: Offset: 0x10C0 +# PLT-NEXT: Size: 64 +# PLT-NEXT: Link: 0 +# PLT-NEXT: Info: 0 +# PLT-NEXT: AddressAlignment: 16 +# PLT-NEXT: EntrySize: 0 +# PLT-NEXT: } + +# PLT: Relocations [ +# PLT-NEXT: Section (5) .rel.dyn { +# PLT-NEXT: 0x400120 R_MIPS_REL32 T1 0x0 +# PLT-NEXT: } +# PLT-NEXT: Section (6) .rel.plt { +# PLT-NEXT: 0x403008 R_MIPS_JUMP_SLOT T2 0x0 +# PLT-NEXT: 0x40300C R_MIPS_JUMP_SLOT T3 0x0 +# PLT-NEXT: } +# PLT-NEXT: ] + +# PLT: DynamicSymbols [ +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: @ (0) +# PLT-NEXT: Value: 0x0 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Local (0x0) +# PLT-NEXT: Type: None (0x0) +# PLT-NEXT: Other: 0 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T2@ (4) +# PLT-NEXT: Value: 0x4010E0 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 8 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T3@ (7) +# PLT-NEXT: Value: 0x4010F0 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 8 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T1@ (1) +# PLT-NEXT: Value: 0x0 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 0 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: T3 + Section: .text + Type: STT_FUNC + Value: 0x8 + Size: 4 + +# o.o +--- +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + # There is no branch relocation for T1. + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_32 + # The R_MIPS_32 relocation for T2 might produce R_MIPS_REL32 ... + - Offset: 0x00 + Symbol: T2 + Type: R_MIPS_32 + # ... but R_MIPS_26 creates PLT entry and makes R_MIPS_REL32 redundant. + - Offset: 0x04 + Symbol: T2 + Type: R_MIPS_26 + # Create PLT entry for T3 symbol. + - Offset: 0x00 + Symbol: T3 + Type: R_MIPS_26 + # Take in account existing PLT entry and do not create R_MIPS_REL32. + - Offset: 0x04 + Symbol: T3 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: T2 + Type: STT_FUNC + - Name: T3 + Type: STT_FUNC +... diff --git a/test/elf/Mips/rel-dynamic-05-micro.test b/test/elf/Mips/rel-dynamic-05-micro.test new file mode 100644 index 000000000000..d1c87076b596 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-05-micro.test @@ -0,0 +1,192 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are symbols defined in the shared object. +# c) Relocations modify a read-only section. +# d) The first symbol is referenced by R_MIPS32 relocation only +# e) The second symbol is referenced by R_MIPS_32 +# and R_MICROMIPS_26_S1 relocations. +# f) The third symbol is referenced by R_MICROMIPS_26_S1 +# and R_MIPS_32 relocations. +# Check: +# a) There should be no R_MIPS_REL32 relocations. +# b) Linker creates PLT entries for all three relocations. +# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require +# a pointer equality. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT %s + +# PLT: Section { +# PLT: Index: 5 +# PLT-NEXT: Name: .rel.plt (31) +# PLT-NEXT: Type: SHT_REL (0x9) +# PLT-NEXT: Flags [ (0x2) +# PLT-NEXT: SHF_ALLOC (0x2) +# PLT-NEXT: ] +# PLT-NEXT: Address: 0x400194 +# PLT-NEXT: Offset: 0x194 +# PLT-NEXT: Size: 24 +# PLT-NEXT: Link: 3 +# PLT-NEXT: Info: 0 +# PLT-NEXT: AddressAlignment: 4 +# PLT-NEXT: EntrySize: 8 +# PLT-NEXT: } +# PLT-NEXT: Section { +# PLT-NEXT: Index: 6 +# PLT-NEXT: Name: .plt (40) +# PLT-NEXT: Type: SHT_PROGBITS (0x1) +# PLT-NEXT: Flags [ (0x6) +# PLT-NEXT: SHF_ALLOC (0x2) +# PLT-NEXT: SHF_EXECINSTR (0x4) +# PLT-NEXT: ] +# PLT-NEXT: Address: 0x4001B0 +# PLT-NEXT: Offset: 0x1B0 +# PLT-NEXT: Size: 60 +# PLT-NEXT: Link: 0 +# PLT-NEXT: Info: 0 +# PLT-NEXT: AddressAlignment: 16 +# PLT-NEXT: EntrySize: 0 +# PLT-NEXT: } + +# PLT: Relocations [ +# PLT-NEXT: Section (5) .rel.plt { +# PLT-NEXT: 0x402008 R_MIPS_JUMP_SLOT T1 0x0 +# PLT-NEXT: 0x40200C R_MIPS_JUMP_SLOT T2 0x0 +# PLT-NEXT: 0x402010 R_MIPS_JUMP_SLOT T3 0x0 +# PLT-NEXT: } +# PLT-NEXT: ] + +# PLT: DynamicSymbols [ +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: @ (0) +# PLT-NEXT: Value: 0x0 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Local (0x0) +# PLT-NEXT: Type: None (0x0) +# PLT-NEXT: Other: 0 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T1@ (1) +# PLT-NEXT: Value: 0x4001C9 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 8 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T2@ (4) +# PLT-NEXT: Value: 0x4001D5 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 8 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T3@ (7) +# PLT-NEXT: Value: 0x4001E1 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 8 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: T3 + Section: .text + Type: STT_FUNC + Value: 0x8 + Size: 4 + +# o.o +--- +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x14 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + # There is no branch relocation for T1. + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_32 + # The R_MIPS_32 relocation for T2 might produce R_MIPS_REL32 ... + - Offset: 0x04 + Symbol: T2 + Type: R_MIPS_32 + # ... but R_MICROMIPS_26_S1 creates PLT entry and makes R_MIPS_REL32 redundant. + - Offset: 0x08 + Symbol: T2 + Type: R_MICROMIPS_26_S1 + # Create PLT entry for T3 symbol. + - Offset: 0x0C + Symbol: T3 + Type: R_MICROMIPS_26_S1 + # Take in account existing PLT entry and do not create R_MIPS_REL32. + - Offset: 0x10 + Symbol: T3 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 0x14 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 + Type: STT_FUNC + - Name: T2 + Type: STT_FUNC + - Name: T3 + Type: STT_FUNC +... diff --git a/test/elf/Mips/rel-dynamic-05.test b/test/elf/Mips/rel-dynamic-05.test new file mode 100644 index 000000000000..3bfbd3f6efdb --- /dev/null +++ b/test/elf/Mips/rel-dynamic-05.test @@ -0,0 +1,188 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are symbols defined in the shared object. +# c) Relocations modify a read-only section. +# d) The first symbol is referenced by R_MIPS32 relocation only +# e) The second symbol is referenced by R_MIPS_32 and R_MIPS26 relocations. +# f) The third symbol is referenced by R_MIPS26 and R_MIPS_32 relocations. +# Check: +# a) There should be no R_MIPS_REL32 relocations. +# b) Linker creates PLT entries for all three relocations. +# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require +# a pointer equality. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT %s + +# PLT: Section { +# PLT: Index: 5 +# PLT-NEXT: Name: .rel.plt (31) +# PLT-NEXT: Type: SHT_REL (0x9) +# PLT-NEXT: Flags [ (0x2) +# PLT-NEXT: SHF_ALLOC (0x2) +# PLT-NEXT: ] +# PLT-NEXT: Address: 0x400190 +# PLT-NEXT: Offset: 0x190 +# PLT-NEXT: Size: 24 +# PLT-NEXT: Link: 3 +# PLT-NEXT: Info: 0 +# PLT-NEXT: AddressAlignment: 4 +# PLT-NEXT: EntrySize: 8 +# PLT-NEXT: } +# PLT-NEXT: Section { +# PLT-NEXT: Index: 6 +# PLT-NEXT: Name: .plt (40) +# PLT-NEXT: Type: SHT_PROGBITS (0x1) +# PLT-NEXT: Flags [ (0x6) +# PLT-NEXT: SHF_ALLOC (0x2) +# PLT-NEXT: SHF_EXECINSTR (0x4) +# PLT-NEXT: ] +# PLT-NEXT: Address: 0x4001B0 +# PLT-NEXT: Offset: 0x1B0 +# PLT-NEXT: Size: 80 +# PLT-NEXT: Link: 0 +# PLT-NEXT: Info: 0 +# PLT-NEXT: AddressAlignment: 16 +# PLT-NEXT: EntrySize: 0 +# PLT-NEXT: } + +# PLT: Relocations [ +# PLT-NEXT: Section (5) .rel.plt { +# PLT-NEXT: 0x402008 R_MIPS_JUMP_SLOT T1 0x0 +# PLT-NEXT: 0x40200C R_MIPS_JUMP_SLOT T2 0x0 +# PLT-NEXT: 0x402010 R_MIPS_JUMP_SLOT T3 0x0 +# PLT-NEXT: } +# PLT-NEXT: ] + +# PLT: DynamicSymbols [ +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: @ (0) +# PLT-NEXT: Value: 0x0 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Local (0x0) +# PLT-NEXT: Type: None (0x0) +# PLT-NEXT: Other: 0 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T1@ (1) +# PLT-NEXT: Value: 0x4001D0 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 8 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T2@ (4) +# PLT-NEXT: Value: 0x4001E0 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 8 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: Symbol { +# PLT-NEXT: Name: T3@ (7) +# PLT-NEXT: Value: 0x4001F0 +# PLT-NEXT: Size: 0 +# PLT-NEXT: Binding: Global (0x1) +# PLT-NEXT: Type: Function (0x2) +# PLT-NEXT: Other: 8 +# PLT-NEXT: Section: Undefined (0x0) +# PLT-NEXT: } +# PLT-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: T3 + Section: .text + Type: STT_FUNC + Value: 0x8 + Size: 4 + +# o.o +--- +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + # There is no branch relocation for T1. + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_32 + # The R_MIPS_32 relocation for T2 might produce R_MIPS_REL32 ... + - Offset: 0x00 + Symbol: T2 + Type: R_MIPS_32 + # ... but R_MIPS_26 creates PLT entry and makes R_MIPS_REL32 redundant. + - Offset: 0x04 + Symbol: T2 + Type: R_MIPS_26 + # Create PLT entry for T3 symbol. + - Offset: 0x00 + Symbol: T3 + Type: R_MIPS_26 + # Take in account existing PLT entry and do not create R_MIPS_REL32. + - Offset: 0x04 + Symbol: T3 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: T2 + Type: STT_FUNC + - Name: T3 + Type: STT_FUNC +... diff --git a/test/elf/Mips/rel-dynamic-06-64.test b/test/elf/Mips/rel-dynamic-06-64.test new file mode 100644 index 000000000000..c153eb22af4c --- /dev/null +++ b/test/elf/Mips/rel-dynamic-06-64.test @@ -0,0 +1,101 @@ +# Conditions: +# a) Linking a shared library. +# b) The first relocation modifies a regular .text section. +# c) The second relocation modifies a .pdr section without SHF_ALLOC flag. +# Check: +# a) There should be no PLT entries. +# b) Linker creates a single R_MIPS_REL32 relocation. +# +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t.o +# RUN: llvm-readobj -dt -r -s %t.so | FileCheck -check-prefix=CHECK %s + +# CHECK: Sections [ +# CHECK: Section { +# CHECK-NOT: Name: .plt ({{[0-9]+}}) + +# CHECK: Relocations [ +# CHECK-NEXT: Section (4) .rel.dyn { +# CHECK-NEXT: 0x170 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T0 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSymbols [ +# 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: T1@ (4) +# CHECK-NEXT: Value: 0x174 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text (0x5) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T0@ (1) +# CHECK-NEXT: Value: 0x170 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text (0x5) +# CHECK-NEXT: } +# CHECK-NEXT: ] + +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 8 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_RELA + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: T0 + Type: R_MIPS_64 + +- Name: .pdr + Type: SHT_PROGBITS + Size: 8 + AddressAlign: 16 + +- Name: .rel.pdr + Type: SHT_RELA + Info: .pdr + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MIPS_64 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 4 + Size: 4 diff --git a/test/elf/Mips/rel-dynamic-06.test b/test/elf/Mips/rel-dynamic-06.test new file mode 100644 index 000000000000..433eb5fadf59 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-06.test @@ -0,0 +1,103 @@ +# Conditions: +# a) Linking a shared library. +# b) The first relocation modifies a regular .text section. +# c) The second relocation modifies a .pdr section without SHF_ALLOC flag. +# Check: +# a) There should be no PLT entries. +# b) Linker creates a single R_MIPS_REL32 relocation. +# +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -shared -o %t1-so %t-obj +# RUN: llvm-readobj -dt -r -s %t1-so | FileCheck -check-prefix=PLT1 %s + +# PLT1-SYM: Sections [ +# PLT1-SYM: Section { +# PLT1-SYM-NOT: Name: .plt ({{[0-9]+}}) + +# PLT1: Relocations [ +# PLT1-NEXT: Section (4) .rel.dyn { +# PLT1-NEXT: 0x100 R_MIPS_REL32 T0 0x0 +# PLT1-NEXT: } +# PLT1-NEXT: ] + +# PLT1: DynamicSymbols [ +# PLT1-NEXT: Symbol { +# PLT1-NEXT: Name: @ (0) +# PLT1-NEXT: Value: 0x0 +# PLT1-NEXT: Size: 0 +# PLT1-NEXT: Binding: Local (0x0) +# PLT1-NEXT: Type: None (0x0) +# PLT1-NEXT: Other: 0 +# PLT1-NEXT: Section: Undefined (0x0) +# PLT1-NEXT: } +# PLT1-NEXT: Symbol { +# PLT1-NEXT: Name: T1@ (4) +# PLT1-NEXT: Value: 0x104 +# PLT1-NEXT: Size: 4 +# PLT1-NEXT: Binding: Global (0x1) +# PLT1-NEXT: Type: Function (0x2) +# PLT1-NEXT: Other: 0 +# PLT1-NEXT: Section: .text (0x5) +# PLT1-NEXT: } +# PLT1-NEXT: Symbol { +# PLT1-NEXT: Name: T0@ (1) +# PLT1-NEXT: Value: 0x100 +# PLT1-NEXT: Size: 4 +# PLT1-NEXT: Binding: Global (0x1) +# PLT1-NEXT: Type: Function (0x2) +# PLT1-NEXT: Other: 0 +# PLT1-NEXT: Section: .text (0x5) +# PLT1-NEXT: } +# PLT1-NEXT: ] + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T0 + Type: R_MIPS_32 + +- Name: .pdr + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [] + +- Name: .rel.pdr + Type: SHT_REL + Info: .pdr + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 diff --git a/test/elf/Mips/rel-dynamic-07-64.test b/test/elf/Mips/rel-dynamic-07-64.test new file mode 100644 index 000000000000..f7a1c4425823 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-07-64.test @@ -0,0 +1,261 @@ +# Conditions: +# a) Linking a shared library. +# b) There ars multiple R_MIPS_64 relocations with various targets. +# Check: +# a) Emitting of R_MIPS_REL32 relocations. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mips64el -shared -o %t1.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mips64el -shared --noinhibit-exec \ +# RUN: -o %t2.so %t-o.o %t1.so +# RUN: llvm-readobj -dt -r -sections %t2.so | FileCheck %s + +# CHECK: Sections [ +# CHECK: Section { +# CHECK-NOT: Name: .plt ({{[0-9]+}}) + +# CHECK: Relocations [ +# CHECK-NEXT: Section (4) .rel.dyn { +# CHECK-NEXT: 0x2000 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T0 0x0 +# CHECK-NEXT: 0x2000 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T4 0x0 +# CHECK-NEXT: 0x2000 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D2 0x0 +# CHECK-NEXT: 0x2004 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T1 0x0 +# CHECK-NEXT: 0x2008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T2 0x0 +# CHECK-NEXT: 0x2004 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D0 0x0 +# CHECK-NEXT: 0x2008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D1 0x0 +# CHECK-NEXT: 0x2004 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D4 0x0 +# CHECK-NEXT: 0x2008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE U1 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSymbols [ +# 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: T0@ (1) +# CHECK-NEXT: Value: 0x324 +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text (0x5) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T4@ (7) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: None (0x0) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D2@ (25) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T1@ (16) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T2@ (19) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D0@ (4) +# CHECK-NEXT: Value: 0x2004 +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .data (0x8) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D1@ (22) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D4@ (10) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: None (0x0) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: U1@ (13) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: None (0x0) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.data + Type: SHT_RELA + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 # T0 is a defined function + Symbol: T0 + Type: R_MIPS_64 + - Offset: 0x04 # T1 is a function from shared lib + Symbol: T1 + Type: R_MIPS_64 + - Offset: 0x08 # T2 has unknown type and defined in shared lib + Symbol: T2 + Type: R_MIPS_64 + - Offset: 0x00 # T4 is an undefined function + Symbol: T4 + Type: R_MIPS_64 + - Offset: 0x04 # D0 is a defined data object + Symbol: D0 + Type: R_MIPS_64 + - Offset: 0x08 # D1 is a data object from shared lib + Symbol: D1 + Type: R_MIPS_64 + - Offset: 0x00 # D2 has unknown type and defined in shared lib + Symbol: D2 + Type: R_MIPS_64 + - Offset: 0x04 # D4 is an undefined data object + Symbol: D4 + Type: R_MIPS_64 + - Offset: 0x08 # U1 is undefined and has unknown type + Symbol: U1 + Type: R_MIPS_64 + +Symbols: + Local: + - Name: LT0 + Section: .text + Type: STT_FUNC + Value: 0 + Size: 4 + - Name: LD0 + Section: .data + Type: STT_OBJECT + Value: 0 + Size: 4 + + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: T2 + - Name: T4 + Type: STT_FUNC + + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + - Name: D4 + Type: STT_OBJECT + - Name: U1 +... diff --git a/test/elf/Mips/rel-dynamic-07.test b/test/elf/Mips/rel-dynamic-07.test new file mode 100644 index 000000000000..fc163b9a12f7 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-07.test @@ -0,0 +1,276 @@ +# Conditions: +# a) Linking a shared library. +# b) There ars multiple R_MIPS_32 relocations with various targets. +# Check: +# a) Emitting of R_MIPS_REL32 relocations. +# b) There should be no R_MIPS_REL32 relocations for the _gp_disp symbol. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t1.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec \ +# RUN: -o %t2.so %t-o.o %t1.so +# RUN: llvm-readobj -dt -r -sections %t2.so | FileCheck %s + +# CHECK: Sections [ +# CHECK: Section { +# CHECK-NOT: Name: .plt ({{[0-9]+}}) + +# CHECK: Relocations [ +# CHECK-NEXT: Section (4) .rel.dyn { +# CHECK-NEXT: 0x2000 R_MIPS_REL32 T0 0x0 +# CHECK-NEXT: 0x2000 R_MIPS_REL32 T4 0x0 +# CHECK-NEXT: 0x2000 R_MIPS_REL32 D2 0x0 +# CHECK-NEXT: 0x2004 R_MIPS_REL32 T1 0x0 +# CHECK-NEXT: 0x2008 R_MIPS_REL32 T2 0x0 +# CHECK-NEXT: 0x2004 R_MIPS_REL32 D0 0x0 +# CHECK-NEXT: 0x2008 R_MIPS_REL32 D1 0x0 +# CHECK-NEXT: 0x2004 R_MIPS_REL32 D4 0x0 +# CHECK-NEXT: 0x2008 R_MIPS_REL32 U1 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSymbols [ +# 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: T0@ (1) +# CHECK-NEXT: Value: 0x214 +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text (0x5) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T4@ (7) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: None (0x0) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D2@ (25) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T1@ (16) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T2@ (19) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D0@ (4) +# CHECK-NEXT: Value: 0x2004 +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .data (0x8) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D1@ (22) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D4@ (10) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: None (0x0) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: U1@ (13) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: None (0x0) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: _gp_disp + Type: R_MIPS_HI16 + - Offset: 0x00 + Symbol: _gp_disp + Type: R_MIPS_LO16 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 # T0 is a defined function + Symbol: T0 + Type: R_MIPS_32 + - Offset: 0x04 # T1 is a function from shared lib + Symbol: T1 + Type: R_MIPS_32 + - Offset: 0x08 # T2 has unknown type and defined in shared lib + Symbol: T2 + Type: R_MIPS_32 + - Offset: 0x00 # T4 is an undefined function + Symbol: T4 + Type: R_MIPS_32 + - Offset: 0x04 # D0 is a defined data object + Symbol: D0 + Type: R_MIPS_32 + - Offset: 0x08 # D1 is a data object from shared lib + Symbol: D1 + Type: R_MIPS_32 + - Offset: 0x00 # D2 has unknown type and defined in shared lib + Symbol: D2 + Type: R_MIPS_32 + - Offset: 0x04 # D4 is an undefined data object + Symbol: D4 + Type: R_MIPS_32 + - Offset: 0x08 # U1 is undefined and has unknown type + Symbol: U1 + Type: R_MIPS_32 + +Symbols: + Local: + - Name: LT0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: LD0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + + Global: + - Name: _gp_disp + Type: STT_OBJECT + + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: T2 + - Name: T4 + Type: STT_FUNC + + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + - Name: D4 + Type: STT_OBJECT + - Name: U1 diff --git a/test/elf/Mips/rel-dynamic-08-64.test b/test/elf/Mips/rel-dynamic-08-64.test new file mode 100644 index 000000000000..d845d7407c1c --- /dev/null +++ b/test/elf/Mips/rel-dynamic-08-64.test @@ -0,0 +1,233 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) There ars multiple R_MIPS_64/R_MIPS_HI16/R_MIPS_LO16 relocations +# with various targets. +# Check: +# a) Emitting of R_MIPS_REL32 relocations. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mips64el -e T0 --noinhibit-exec \ +# RUN: -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dt -r -sections %t.exe | FileCheck %s + +# CHECK: Sections [ +# CHECK: Section { +# CHECK-NOT: Name: .plt ({{[0-9]+}}) + +# CHECK: Relocations [ +# CHECK-NEXT: Section (5) .rel.dyn { +# CHECK-NEXT: 0x120002000 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D2 0x0 +# CHECK-NEXT: 0x120002004 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T1 0x0 +# CHECK-NEXT: 0x120002008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T2 0x0 +# CHECK-NEXT: 0x120002008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D1 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSymbols [ +# 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: D2@ (10) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T1@ (1) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T2@ (4) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D1@ (7) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_RELA + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: _gp_disp + Type: R_MIPS_HI16 + - Offset: 0x00 + Symbol: _gp_disp + Type: R_MIPS_LO16 + +- Name: .rel.data + Type: SHT_RELA + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 # LT0 is a locally defined function + Symbol: LT0 + Type: R_MIPS_64 + - Offset: 0x00 # LD0 is a locally defined data object + Symbol: LD0 + Type: R_MIPS_64 + - Offset: 0x00 # T0 is a defined function + Symbol: T0 + Type: R_MIPS_64 + - Offset: 0x04 # T1 is a function from shared lib + Symbol: T1 + Type: R_MIPS_64 + - Offset: 0x08 # T2 has unknown type and defined in shared lib + Symbol: T2 + Type: R_MIPS_64 + - Offset: 0x00 # T4 is an undefined function + Symbol: T4 + Type: R_MIPS_64 + - Offset: 0x04 # D0 is a defined data object + Symbol: D0 + Type: R_MIPS_64 + - Offset: 0x08 # D1 is a data object from shared lib + Symbol: D1 + Type: R_MIPS_64 + - Offset: 0x00 # D2 has unknown type and defined in shared lib + Symbol: D2 + Type: R_MIPS_64 + - Offset: 0x04 # D4 is an undefined data object + Symbol: D4 + Type: R_MIPS_64 + - Offset: 0x08 # U1 is undefined and has unknown type + Symbol: U1 + Type: R_MIPS_64 + +Symbols: + Local: + - Name: LT0 + Section: .text + Type: STT_FUNC + Value: 0 + Size: 4 + - Name: LD0 + Section: .data + Type: STT_OBJECT + Value: 0 + Size: 4 + + Global: + - Name: _gp_disp + Type: STT_OBJECT + + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: T2 + - Name: T4 + Type: STT_FUNC + + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + - Name: D4 + Type: STT_OBJECT + - Name: U1 +... diff --git a/test/elf/Mips/rel-dynamic-08-micro.test b/test/elf/Mips/rel-dynamic-08-micro.test new file mode 100644 index 000000000000..de0038956086 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-08-micro.test @@ -0,0 +1,236 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) There ars multiple R_MIPS_32/R_MICROMIPS_HI16/R_MICROMIPS_LO16 +# relocations with various targets. +# Check: +# a) Emitting of R_MIPS_REL32 relocations. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 --noinhibit-exec \ +# RUN: -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dt -r -sections %t.exe | FileCheck %s + +# CHECK: Sections [ +# CHECK: Section { +# CHECK-NOT: Name: .plt ({{[0-9]+}}) + +# CHECK: Relocations [ +# CHECK-NEXT: Section (5) .rel.dyn { +# CHECK-NEXT: 0x402000 R_MIPS_REL32 D2 0x0 +# CHECK-NEXT: 0x402004 R_MIPS_REL32 T1 0x0 +# CHECK-NEXT: 0x402008 R_MIPS_REL32 T2 0x0 +# CHECK-NEXT: 0x402008 R_MIPS_REL32 D1 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSymbols [ +# 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: D2@ (10) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T1@ (1) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T2@ (4) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D1@ (7) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: _gp_disp + Type: R_MICROMIPS_HI16 + - Offset: 0x00 + Symbol: _gp_disp + Type: R_MICROMIPS_LO16 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 # LT0 is a locally defined function + Symbol: LT0 + Type: R_MIPS_32 + - Offset: 0x00 # LD0 is a locally defined data object + Symbol: LD0 + Type: R_MIPS_32 + - Offset: 0x00 # T0 is a defined function + Symbol: T0 + Type: R_MIPS_32 + - Offset: 0x04 # T1 is a function from shared lib + Symbol: T1 + Type: R_MIPS_32 + - Offset: 0x08 # T2 has unknown type and defined in shared lib + Symbol: T2 + Type: R_MIPS_32 + - Offset: 0x00 # T4 is an undefined function + Symbol: T4 + Type: R_MIPS_32 + - Offset: 0x04 # D0 is a defined data object + Symbol: D0 + Type: R_MIPS_32 + - Offset: 0x08 # D1 is a data object from shared lib + Symbol: D1 + Type: R_MIPS_32 + - Offset: 0x00 # D2 has unknown type and defined in shared lib + Symbol: D2 + Type: R_MIPS_32 + - Offset: 0x04 # D4 is an undefined data object + Symbol: D4 + Type: R_MIPS_32 + - Offset: 0x08 # U1 is undefined and has unknown type + Symbol: U1 + Type: R_MIPS_32 + +Symbols: + Local: + - Name: LT0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: LD0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + + Global: + - Name: _gp_disp + Type: STT_OBJECT + + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 8 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 + Type: STT_FUNC + - Name: T2 + - Name: T4 + Type: STT_FUNC + + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + - Name: D4 + Type: STT_OBJECT + - Name: U1 +... diff --git a/test/elf/Mips/rel-dynamic-08.test b/test/elf/Mips/rel-dynamic-08.test new file mode 100644 index 000000000000..62f4dc278b05 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-08.test @@ -0,0 +1,233 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) There ars multiple R_MIPS_32/R_MIPS_HI16/R_MIPS_LO16 relocations +# with various targets. +# Check: +# a) Emitting of R_MIPS_REL32 relocations. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 --noinhibit-exec \ +# RUN: -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dt -r -sections %t.exe | FileCheck %s + +# CHECK: Sections [ +# CHECK: Section { +# CHECK-NOT: Name: .plt ({{[0-9]+}}) + +# CHECK: Relocations [ +# CHECK-NEXT: Section (5) .rel.dyn { +# CHECK-NEXT: 0x402000 R_MIPS_REL32 D2 0x0 +# CHECK-NEXT: 0x402004 R_MIPS_REL32 T1 0x0 +# CHECK-NEXT: 0x402008 R_MIPS_REL32 T2 0x0 +# CHECK-NEXT: 0x402008 R_MIPS_REL32 D1 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# CHECK: DynamicSymbols [ +# 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: D2@ (10) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T1@ (1) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: T2@ (4) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D1@ (7) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: _gp_disp + Type: R_MIPS_HI16 + - Offset: 0x00 + Symbol: _gp_disp + Type: R_MIPS_LO16 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 # LT0 is a locally defined function + Symbol: LT0 + Type: R_MIPS_32 + - Offset: 0x00 # LD0 is a locally defined data object + Symbol: LD0 + Type: R_MIPS_32 + - Offset: 0x00 # T0 is a defined function + Symbol: T0 + Type: R_MIPS_32 + - Offset: 0x04 # T1 is a function from shared lib + Symbol: T1 + Type: R_MIPS_32 + - Offset: 0x08 # T2 has unknown type and defined in shared lib + Symbol: T2 + Type: R_MIPS_32 + - Offset: 0x00 # T4 is an undefined function + Symbol: T4 + Type: R_MIPS_32 + - Offset: 0x04 # D0 is a defined data object + Symbol: D0 + Type: R_MIPS_32 + - Offset: 0x08 # D1 is a data object from shared lib + Symbol: D1 + Type: R_MIPS_32 + - Offset: 0x00 # D2 has unknown type and defined in shared lib + Symbol: D2 + Type: R_MIPS_32 + - Offset: 0x04 # D4 is an undefined data object + Symbol: D4 + Type: R_MIPS_32 + - Offset: 0x08 # U1 is undefined and has unknown type + Symbol: U1 + Type: R_MIPS_32 + +Symbols: + Local: + - Name: LT0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: LD0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + + Global: + - Name: _gp_disp + Type: STT_OBJECT + + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: T2 + - Name: T4 + Type: STT_FUNC + + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + - Name: D4 + Type: STT_OBJECT + - Name: U1 +... diff --git a/test/elf/Mips/rel-dynamic-09-micro.test b/test/elf/Mips/rel-dynamic-09-micro.test new file mode 100644 index 000000000000..07ffce9eb074 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-09-micro.test @@ -0,0 +1,109 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are undefined symbols. +# Check: +# a) There should be no dynamic relocations. +# b) There should be no PLT entries. +# +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel --noinhibit-exec -e T0 -o %t2-exe %t-obj +# RUN: llvm-readobj -dt -r -s %t2-exe | FileCheck -check-prefix=PLT-SYM %s + +# PLT-SYM: Sections [ +# PLT-SYM: Section { +# PLT-SYM-NOT: Name: .plt ({{[0-9]+}}) + +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: ] + +# PLT-SYM: DynamicSymbols [ +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: @ (0) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Local (0x0) +# PLT-SYM-NEXT: Type: None (0x0) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x04 + Symbol: T3 + Type: R_MICROMIPS_26_S1 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MICROMIPS_HI16 + - Offset: 0x00 + Symbol: T1 + Type: R_MICROMIPS_LO16 + - Offset: 0x04 + Symbol: T2 + Type: R_MIPS_32 + + - Offset: 0x04 + Symbol: D1 + Type: R_MICROMIPS_HI16 + - Offset: 0x04 + Symbol: D1 + Type: R_MICROMIPS_LO16 + - Offset: 0x04 + Symbol: D2 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 + Type: STT_FUNC + - Name: T2 + Type: STT_FUNC + - Name: T3 + Type: STT_FUNC + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + Type: STT_OBJECT diff --git a/test/elf/Mips/rel-dynamic-09.test b/test/elf/Mips/rel-dynamic-09.test new file mode 100644 index 000000000000..18eeb9dd33d8 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-09.test @@ -0,0 +1,107 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are undefined symbols. +# Check: +# a) There should be no dynamic relocations. +# b) There should be no PLT entries. +# +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel --noinhibit-exec -e T0 -o %t2-exe %t-obj +# RUN: llvm-readobj -dt -r -s %t2-exe | FileCheck -check-prefix=PLT-SYM %s + +# PLT-SYM: Sections [ +# PLT-SYM: Section { +# PLT-SYM-NOT: Name: .plt ({{[0-9]+}}) + +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: ] + +# PLT-SYM: DynamicSymbols [ +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: @ (0) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Local (0x0) +# PLT-SYM-NEXT: Type: None (0x0) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x04 + Symbol: T3 + Type: R_MIPS_26 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_HI16 + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_LO16 + - Offset: 0x04 + Symbol: T2 + Type: R_MIPS_32 + + - Offset: 0x04 + Symbol: D1 + Type: R_MIPS_HI16 + - Offset: 0x04 + Symbol: D1 + Type: R_MIPS_LO16 + - Offset: 0x04 + Symbol: D2 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: T2 + Type: STT_FUNC + - Name: T3 + Type: STT_FUNC + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + Type: STT_OBJECT diff --git a/test/elf/Mips/rel-dynamic-10-micro.test b/test/elf/Mips/rel-dynamic-10-micro.test new file mode 100644 index 000000000000..6b3f2af3db32 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-10-micro.test @@ -0,0 +1,166 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are symbols defined in the other object. +# Check: +# a) There should be no dynamic relocations. +# b) There should be no PLT entries. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-o1.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o2.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o1.o %t-o2.o +# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT-SYM %s + +# PLT-SYM: Sections [ +# PLT-SYM: Section { +# PLT-SYM-NOT: Name: .plt ({{[0-9]+}}) + +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: ] + +# PLT-SYM: DynamicSymbols [ +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: @ (0) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Local (0x0) +# PLT-SYM-NEXT: Type: None (0x0) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +# o1.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T3 + Section: .text + Type: STT_FUNC + Value: 0x8 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 4 + +# o2.o +--- +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, + EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x04 + Symbol: T3 + Type: R_MICROMIPS_26_S1 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MICROMIPS_HI16 + - Offset: 0x00 + Symbol: T1 + Type: R_MICROMIPS_LO16 + - Offset: 0x04 + Symbol: T2 + Type: R_MIPS_32 + + - Offset: 0x04 + Symbol: D1 + Type: R_MICROMIPS_HI16 + - Offset: 0x04 + Symbol: D1 + Type: R_MICROMIPS_LO16 + - Offset: 0x04 + Symbol: D2 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 + Type: STT_FUNC + - Name: T2 + Type: STT_FUNC + - Name: T3 + Type: STT_FUNC + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + Type: STT_OBJECT +... diff --git a/test/elf/Mips/rel-dynamic-10.test b/test/elf/Mips/rel-dynamic-10.test new file mode 100644 index 000000000000..4df558167fc7 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-10.test @@ -0,0 +1,160 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are symbols defined in the other object. +# Check: +# a) There should be no dynamic relocations. +# b) There should be no PLT entries. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-o1.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o2.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o1.o %t-o2.o +# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT-SYM %s + +# PLT-SYM: Sections [ +# PLT-SYM: Section { +# PLT-SYM-NOT: Name: .plt ({{[0-9]+}}) + +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: ] + +# PLT-SYM: DynamicSymbols [ +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: @ (0) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Local (0x0) +# PLT-SYM-NEXT: Type: None (0x0) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +# o1.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: T3 + Section: .text + Type: STT_FUNC + Value: 0x8 + Size: 4 + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 4 + +# o2.o +--- +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x04 + Symbol: T3 + Type: R_MIPS_26 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_HI16 + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_LO16 + - Offset: 0x04 + Symbol: T2 + Type: R_MIPS_32 + + - Offset: 0x04 + Symbol: D1 + Type: R_MIPS_HI16 + - Offset: 0x04 + Symbol: D1 + Type: R_MIPS_LO16 + - Offset: 0x04 + Symbol: D2 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: T2 + Type: STT_FUNC + - Name: T3 + Type: STT_FUNC + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + Type: STT_OBJECT +... diff --git a/test/elf/Mips/rel-dynamic-11.test b/test/elf/Mips/rel-dynamic-11.test new file mode 100644 index 000000000000..20295396cd08 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-11.test @@ -0,0 +1,110 @@ +# Conditions: +# a) Linking a shared library. +# b) Relocations' targets are symbols defined in the other shared object. +# Check: +# a) Emitting R_MIPS_REL32 relocations for both symbols. +# b) There should be no PLT entries. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t1.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t2.so %t-o.o %t1.so +# RUN: llvm-readobj -dt -r -s %t2.so | FileCheck -check-prefix=PLT-SYM %s + +# PLT-SYM: Sections [ +# PLT-SYM: Section { +# PLT-SYM-NOT: Name: .plt ({{[0-9]+}}) +# +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: Section (4) .rel.dyn { +# PLT-SYM-NEXT: 0x150 R_MIPS_REL32 T1 0x0 +# PLT-SYM-NEXT: 0x2000 R_MIPS_REL32 T1 0x0 +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] +# +# PLT-SYM: Name: T1@ (7) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Function (0x2) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_32 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T1 + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 +... diff --git a/test/elf/Mips/rel-dynamic-12.test b/test/elf/Mips/rel-dynamic-12.test new file mode 100644 index 000000000000..2a4061ab4035 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-12.test @@ -0,0 +1,213 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are symbols defined in the shared object. +# c) Relocations are R_MIPS_PCHI16 / R_MIPS_PCLO16. +# Check: +# a) Emitting R_MIPS_REL32, R_MIPS_COPY, R_MIPS_JUMP_SLOT relocations. +# b) STO_MIPS_PLT flag in the dynamic symbol table for symbols require +# a pointer equality. +# +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s + +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: Section (5) .rel.dyn { +# PLT-SYM-NEXT: 0x402014 R_MIPS_REL32 T2 0x0 +# PLT-SYM-NEXT: 0x402014 R_MIPS_REL32 D2 0x0 +# PLT-SYM-NEXT: 0x402018 R_MIPS_COPY D1 0x0 +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Section (6) .rel.plt { +# PLT-SYM-NEXT: 0x402008 R_MIPS_JUMP_SLOT T3 0x0 +# PLT-SYM-NEXT: 0x40200C R_MIPS_JUMP_SLOT T1 0x0 +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +# PLT-SYM: DynamicSymbols [ +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: @ (0) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Local (0x0) +# PLT-SYM-NEXT: Type: None (0x0) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: D1@ (1) +# PLT-SYM-NEXT: Value: 0x402018 +# PLT-SYM-NEXT: Size: 4 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Object (0x1) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: .bss (0xD) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: T1@ (4) +# PLT-SYM-NEXT: Value: 0x400220 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Function (0x2) +# PLT-SYM-NEXT: Other: 8 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: T3@ (10) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Function (0x2) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: T2@ (7) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 0 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Function (0x2) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: D2@ (13) +# PLT-SYM-NEXT: Value: 0x0 +# PLT-SYM-NEXT: Size: 4 +# PLT-SYM-NEXT: Binding: Global (0x1) +# PLT-SYM-NEXT: Type: Object (0x1) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: ] + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x0C + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 + - Name: T3 + Section: .text + Type: STT_FUNC + Value: 0x8 + Size: 4 + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 4 + - Name: D2 + Section: .data + Type: STT_OBJECT + Value: 0x4 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x04 + Symbol: T3 + Type: R_MIPS_26 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_PCHI16 + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_PCLO16 + - Offset: 0x04 + Symbol: T2 + Type: R_MIPS_32 + + - Offset: 0x04 + Symbol: D1 + Type: R_MIPS_PCHI16 + - Offset: 0x04 + Symbol: D1 + Type: R_MIPS_PCLO16 + - Offset: 0x04 + Symbol: D2 + Type: R_MIPS_32 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: T2 + Type: STT_FUNC + - Name: T3 + Type: STT_FUNC + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: D1 + Type: STT_OBJECT + - Name: D2 + Type: STT_OBJECT +... diff --git a/test/elf/Mips/rel-gprel16.test b/test/elf/Mips/rel-gprel16.test new file mode 100644 index 000000000000..dc188ea6825a --- /dev/null +++ b/test/elf/Mips/rel-gprel16.test @@ -0,0 +1,104 @@ +# Check R_MIPS_GPREL16 relocation handling. +# +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -e G1 -shared -o %t.so %t-obj +# RUN: llvm-readobj -symbols %t.so | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=SEC %s + +# SYM: Name: L1 (1) +# SYM-NEXT: Value: 0xCC +# SYM-NEXT: Size: 4 +# SYM-NEXT: Binding: Local (0x0) +# SYM-NEXT: Type: Function (0x2) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: .text (0x4) + +# SYM: Name: G1 (4) +# SYM-NEXT: Value: 0xD0 +# SYM-NEXT: Size: 4 +# SYM-NEXT: Binding: Global (0x1) +# SYM-NEXT: Type: Function (0x2) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: .text (0x4) + +# SYM: Name: _gp (34) +# SYM-NEXT: Value: 0x8FF0 +# SYM-NEXT: Size: 0 +# SYM-NEXT: Binding: Global (0x1) +# SYM-NEXT: Type: Object (0x1) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: Absolute (0xFFF1) + +# 0x160db == 0xffff (addend) + 0x00cc (L1) + 0x01f000 (GP0) - 0x8ff0 (_gp) +# SEC: Contents of section .rodata: +# SEC-NEXT: 00d4 db600008 00000000 00000000 00000000 .`.............. + +!ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: +- Type: SHT_PROGBITS + Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + +- Type: SHT_REL + Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0 + Symbol: .rodata + Type: R_MIPS_GOT16 + - Offset: 4 + Symbol: .rodata + Type: R_MIPS_LO16 + +- Type: SHT_PROGBITS + Name: .rodata + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x04 + Content: ffff0008000000000000000000000000 + +- Type: SHT_REL + Name: .rel.rodata + Type: SHT_REL + Link: .symtab + Info: .rodata + AddressAlign: 0x04 + Relocations: + - Offset: 0 + Symbol: L1 + Type: R_MIPS_GPREL16 + +- Type: SHT_MIPS_REGINFO + Name: .reginfo + Type: SHT_MIPS_REGINFO + Flags: [ SHF_ALLOC ] + AddressAlign: 0x01 + Content: 000000000000000000000000000000000000000000f00100 + +Symbols: + Local: + - Name: L1 + Section: .text + Value: 0x00 + Size: 0x04 + - Name: .rodata + Type: STT_SECTION + Section: .rodata + Global: + - Name: G1 + Section: .text + Value: 0x04 + Size: 0x04 diff --git a/test/elf/Mips/rel-gprel32-64.test b/test/elf/Mips/rel-gprel32-64.test new file mode 100644 index 000000000000..723c8e1ee738 --- /dev/null +++ b/test/elf/Mips/rel-gprel32-64.test @@ -0,0 +1,70 @@ +# Check R_MIPS_GPREL32/R_MIPS_64 relocations handling. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mips64el -e T0 -o %t.exe %t.o +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 1200001a0 c871ffff ffffffff c871ffff c871ffff .q.......q...q.. +# CHECK-NEXT: 1200001b0 c871ffff ffffffff 00000000 00000000 .q.............. + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 16 + Size: 32 + + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 8 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: LT1 + Type: R_MIPS_GPREL16 + Type2: R_MIPS_64 + Type3: R_MIPS_NONE + - Offset: 0x08 + Symbol: LT1 + Type: R_MIPS_GPREL16 + Type2: R_MIPS_64 + Type3: R_MIPS_NONE + - Offset: 0x0C + Symbol: LT1 + Type: R_MIPS_GPREL32 + Type2: R_MIPS_64 + Type3: R_MIPS_NONE + - Offset: 0x10 + Symbol: LT1 + Type: R_MIPS_GPREL32 + Type2: R_MIPS_64 + Type3: R_MIPS_NONE + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + + Global: + - Name: LT1 + Type: STT_FUNC + Section: .text + Value: 0x18 + Size: 0x8 + - Name: T0 + Type: STT_FUNC + Section: .text + Value: 0x0 + Size: 0x18 +... diff --git a/test/elf/Mips/rel-gprel32.test b/test/elf/Mips/rel-gprel32.test new file mode 100644 index 000000000000..73ae6f161979 --- /dev/null +++ b/test/elf/Mips/rel-gprel32.test @@ -0,0 +1,84 @@ +# Check R_MIPS_GPREL32 relocation handling. +# +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj +# RUN: llvm-readobj -symbols %t-exe | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t-exe | FileCheck -check-prefix=SEC %s + +# SYM: Name: $L1 (1) +# SYM-NEXT: Value: 0x400108 +# SYM-NEXT: Size: 4 +# SYM-NEXT: Binding: Local (0x0) +# SYM-NEXT: Type: Function (0x2) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: .text (0x5) +# +# SYM: Name: _gp (212) +# SYM-NEXT: Value: 0x408FF0 +# SYM-NEXT: Size: 0 +# SYM-NEXT: Binding: Global (0x1) +# SYM-NEXT: Type: Object (0x1) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: Absolute (0xFFF1) + +# 0x08FF711B == 0x8000001 (addend) + 0x400108 ($L1) + +# 0x1000002 (GP0) - 0x408FF0 (_gp) +# SEC: Contents of section .rodata: +# SEC-NEXT: 400118 1b71ff08 00000000 00000000 00000000 .q.............. + +!ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: +- Type: SHT_PROGBITS + Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: 00000000000000000000000000000000 + +- Type: SHT_PROGBITS + Name: .rodata + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x04 + Content: 01000008000000000000000000000000 + +- Type: SHT_REL + Name: .rel.rodata + Type: SHT_REL + Link: .symtab + Info: .rodata + AddressAlign: 0x04 + Relocations: + - Offset: 0 + Symbol: $L1 + Type: R_MIPS_GPREL32 + +- Type: SHT_MIPS_REGINFO + Name: .reginfo + Type: SHT_MIPS_REGINFO + Flags: [ SHF_ALLOC ] + AddressAlign: 0x01 + Content: 000000000000000000000000000000000000000002000001 + +Symbols: + Local: + - Name: $L1 + Section: .text + Value: 0x00 + - Name: .rodata + Type: STT_SECTION + Section: .rodata + Global: + - Name: __start + Section: .text + Type: STT_FUNC + Value: 0x04 + Size: 12 + - Name: _gp_disp diff --git a/test/elf/Mips/rel-pc-hilo.test b/test/elf/Mips/rel-pc-hilo.test new file mode 100644 index 000000000000..89cd2b121797 --- /dev/null +++ b/test/elf/Mips/rel-pc-hilo.test @@ -0,0 +1,70 @@ +# Check handling of R_MIPS_PCHI16 / R_MIPS_PCLO16 relocations. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o +# RUN: llvm-objdump -s -t %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 400110 01000000 02000000 03000000 00000000 +# ^ +# A = 0x10000 - 1 == 0xffff +# V = (T1 + 0xffff - T0) >> 16 => +# V => 0x1000b >> 16 = 1 +# ^ +# A = 0x20000 - 1 == 0x1ffff +# V = (T1 + 0x1ffff - T0 - 4) >> 16 => +# V => 0x20007 >> 16 = 2 +# ^ +# A = 0xffff == -1 +# V = T1 - 1 - T0 - 8 = 3 + +# CHECK: SYMBOL TABLE: +# CHECK: 00400110 g F .text 0000000c T0 +# CHECK: 0040011c g F .text 00000004 T1 + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "0100000002000000ffff000000000000" +# ^ T0 +# ^ A := 0x1 == 0x10000 +# ^ A := 0x2 == 0x20000 +# ^ A := 0xffff == -1 +# ^ T1 + AddressAlign: 16 + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MIPS_PCHI16 + - Offset: 4 + Symbol: T1 + Type: R_MIPS_PCHI16 + - Offset: 8 + Symbol: T1 + Type: R_MIPS_PCLO16 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0 + Size: 12 + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 12 + Size: 4 diff --git a/test/elf/Mips/rel-pc18-s3.test b/test/elf/Mips/rel-pc18-s3.test new file mode 100644 index 000000000000..5d5d5c7ce658 --- /dev/null +++ b/test/elf/Mips/rel-pc18-s3.test @@ -0,0 +1,54 @@ +# Check handling of R_MIPS_PC18_S3 relocation. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o +# RUN: llvm-objdump -s -t %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 400110 00000000 01000000 00000000 00000000 +# ^ V +# A = -1 << 3 = -8 => +# V = (T1 - 8 - (T0|7)^7) >> 3 => +# V => 8 >> 3 = 1 + +# CHECK: SYMBOL TABLE: +# CHECK: 00400110 g F .text 00000010 T0 +# CHECK: 00400120 g F .text 00000004 T1 + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "00000000ffff0300000000000000000000000000" +# ^ T1 +# ^ T0 ^ A := 0x3ffff == -1 + AddressAlign: 16 + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 4 + Symbol: T1 + Type: R_MIPS_PC18_S3 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0 + Size: 16 + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 16 + Size: 4 diff --git a/test/elf/Mips/rel-pc19-s2.test b/test/elf/Mips/rel-pc19-s2.test new file mode 100644 index 000000000000..479965df814f --- /dev/null +++ b/test/elf/Mips/rel-pc19-s2.test @@ -0,0 +1,54 @@ +# Check handling of R_MIPS_PC19_S2 relocation. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o +# RUN: llvm-objdump -s -t %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 400110 01000000 00000000 00000000 +# ^ V +# A = -1 << 2 = -4 => +# V = (T1 - 4 - T0) >> 2 => +# V => 4 >> 2 = 1 + +# CHECK: SYMBOL TABLE: +# CHECK: 00400110 g F .text 00000008 T0 +# CHECK: 00400118 g F .text 00000004 T1 + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "ffff07000000000000000000" +# ^ T1 +# ^ T0 A := 0x7ffff == -1 + AddressAlign: 16 + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MIPS_PC19_S2 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0 + Size: 8 + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 8 + Size: 4 diff --git a/test/elf/Mips/rel-pc21-s2.test b/test/elf/Mips/rel-pc21-s2.test new file mode 100644 index 000000000000..44d840e94c32 --- /dev/null +++ b/test/elf/Mips/rel-pc21-s2.test @@ -0,0 +1,54 @@ +# Check handling of R_MIPS_PC21_S2 relocation. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o +# RUN: llvm-objdump -s -t %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 400110 01000000 00000000 00000000 +# ^ V +# A = -1 << 2 = -4 => +# V = (T1 - 4 - T0) >> 2 => +# V => 4 >> 2 = 1 + +# CHECK: SYMBOL TABLE: +# CHECK: 00400110 g F .text 00000008 T0 +# CHECK: 00400118 g F .text 00000004 T1 + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "ffff1f000000000000000000" +# ^ T1 +# ^ T0 A := 0x1fffff + AddressAlign: 16 + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MIPS_PC21_S2 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0 + Size: 8 + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 8 + Size: 4 diff --git a/test/elf/Mips/rel-pc26-s2.test b/test/elf/Mips/rel-pc26-s2.test new file mode 100644 index 000000000000..abd05040f0c3 --- /dev/null +++ b/test/elf/Mips/rel-pc26-s2.test @@ -0,0 +1,54 @@ +# Check handling of R_MIPS_PC26_S2 relocation. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o +# RUN: llvm-objdump -s -t %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 400110 01000000 00000000 00000000 +# ^ V +# A = -1 << 2 = -4 => +# V = (T1 - 4 - T0) >> 2 => +# V => 4 >> 2 = 1 + +# CHECK: SYMBOL TABLE: +# CHECK: 00400110 g F .text 00000008 T0 +# CHECK: 00400118 g F .text 00000004 T1 + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "ffffff030000000000000000" +# ^ T1 +# ^ T0 A := 0x3ffffff == -1 + AddressAlign: 16 + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MIPS_PC26_S2 + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0 + Size: 8 + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 8 + Size: 4 diff --git a/test/elf/Mips/rel-pc32.test b/test/elf/Mips/rel-pc32.test new file mode 100644 index 000000000000..e448e8afc30e --- /dev/null +++ b/test/elf/Mips/rel-pc32.test @@ -0,0 +1,59 @@ +# Check handling of R_MIPS_PC32 relocation. +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj +# RUN: llvm-objdump -s -t %t-exe | FileCheck %s + +# CHECK: Contents of section .data: +# CHECK-NEXT: 402000 00000000 05000080 fdffff7f ............ +# ^^ data2 + 0x80000001 - data1 +# ^^ data1 + 0x80000001 - data2 +# CHECK: SYMBOL TABLE: +# CHECK: 00402004 g .data 00000004 data1 +# CHECK: 00402008 g .data 00000004 data2 + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "00000000" + AddressAlign: 16 + Flags: [SHF_ALLOC] +- Name: .data + Type: SHT_PROGBITS + Content: "000000000100008001000080" + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_WRITE] + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x4 + Symbol: data2 + Type: R_MIPS_PC32 + - Offset: 0x8 + Symbol: data1 + Type: R_MIPS_PC32 + +Symbols: + Global: + - Name: __start + Section: .text + Value: 0x0 + Size: 4 + - Name: data1 + Section: .data + Value: 0x4 + Size: 4 + - Name: data2 + Section: .data + Value: 0x8 + Size: 4 diff --git a/test/elf/Mips/rel-pc7-10-16-23.test b/test/elf/Mips/rel-pc7-10-16-23.test new file mode 100644 index 000000000000..c38b9eed2a5e --- /dev/null +++ b/test/elf/Mips/rel-pc7-10-16-23.test @@ -0,0 +1,86 @@ +# Check handling of R_MICROMIPS_PC7_S1, R_MICROMIPS_PC10_S1, +# R_MICROMIPS_PC16_S1, and R_MICROMIPS_PC23_S2 relocations. + +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj +# RUN: llvm-objdump -s -t %t-exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 400110 00000000 80780500 a240fcff 000c03cc .....x...@...... +# ^^ addiu s1,$pc,20 +# ^^ bnezc v0,400114 <__start+0x4> +# ^^ b 400126 <L1> +# CHECK-NEXT: 400120 000c03ad 00000000 00000000 00000000 ................ +# ^^ bnez v0,40012a <L2> +# CHECK: SYMBOL TABLE: +# CHECK: 00400124 l F .text 00000002 L0 +# CHECK: 00400126 l F .text 00000004 L1 +# CHECK: 0040012a l F .text 00000004 L2 +# CHECK: 0040012e l F .text 00000002 L3 +# CHECK: 00400110 g F .text 00000014 __start + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, + EF_MIPS_MICROMIPS ] + +Sections: +- Name: .text + Type: SHT_PROGBITS +# v nop v nop v L0 + Content: "0000000080780100a240f5ff000cfdcf000c7dad000000000000000000000000" +# ^ PC23 ^ PC16 ^ PC10 ^ PC7 ^ L1 ^ L2 ^ L3 +# 7d << 1 = -6 => L3 + 2 - 6 = L2 +# 3fd << 1 = -6 => L2 + 2 - 6 = L1 +# fff5 << 1 = -22 => L1 + 2 - 22 = __start +# 1 << 2 = 4 => L0 + 4 - 4 = L0 + AddressAlign: 16 + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 4 + Symbol: L0 + Type: R_MICROMIPS_PC23_S2 + - Offset: 8 + Symbol: L1 + Type: R_MICROMIPS_PC16_S1 + - Offset: 14 + Symbol: L2 + Type: R_MICROMIPS_PC10_S1 + - Offset: 18 + Symbol: L3 + Type: R_MICROMIPS_PC7_S1 + +Symbols: + Local: + - Name: L0 + Section: .text + Value: 20 + Other: [ STO_MIPS_MICROMIPS ] + - Name: L1 + Section: .text + Value: 22 + Other: [ STO_MIPS_MICROMIPS ] + - Name: L2 + Section: .text + Value: 26 + Other: [ STO_MIPS_MICROMIPS ] + - Name: L3 + Section: .text + Value: 30 + Other: [ STO_MIPS_MICROMIPS ] + Global: + - Name: __start + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 32 + Other: [ STO_MIPS_MICROMIPS ] diff --git a/test/elf/Mips/rel-sub.test b/test/elf/Mips/rel-sub.test new file mode 100644 index 000000000000..93e569a22035 --- /dev/null +++ b/test/elf/Mips/rel-sub.test @@ -0,0 +1,61 @@ +# Check handling of R_MIPS_SUB relocation. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mips64el -o %t.exe %t.o +# RUN: llvm-objdump -s -t %t.exe | FileCheck %s + +# CHECK: Contents of section .data: +# CHECK-NEXT: 120002000 cf010020 01000000 d0010020 0100ffff ... ....... .... +# ^^ __start - 1 = 0x1200001cf +# ^^ __start - 0x1000000000000 +# = 0Xffff0001200001d0 +# CHECK: SYMBOL TABLE: +# CHECK: 00000001200001d0 g .rodata 00000008 __start + +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_ALLOC] +- Name: .data + Type: SHT_PROGBITS + Size: 0x10 + AddressAlign: 16 + Flags: [SHF_ALLOC, SHF_WRITE] + +- Name: .rela.data + Type: SHT_RELA + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0x0 + Symbol: __start + Type: R_MIPS_SUB + Addend: 1 + - Offset: 0x8 + Symbol: __start + Type: R_MIPS_SUB + Addend: 0x1000000000000 + +Symbols: + Global: + - Name: __start + Section: .text + Value: 0x0 + Size: 8 + - Name: data1 + Section: .data + Value: 0x0 + Size: 8 + - Name: data2 + Section: .data + Value: 0x8 + Size: 8 diff --git a/test/elf/Mips/st-other.test b/test/elf/Mips/st-other.test new file mode 100644 index 000000000000..8d15e75676b0 --- /dev/null +++ b/test/elf/Mips/st-other.test @@ -0,0 +1,90 @@ +# Check STO_MICROMIPS flag handling. microMIPS symbol records in a dynamic +# symbol table should not have STO_MICROMIPS flag but their value field +# must be odd. microMIPS symbol records in a regular symbol table should +# have the STO_MICROMIPS flag. + +# RUN: yaml2obj -format=elf %s > %t-micro.o + +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-micro.o +# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck -check-prefix=SO %s + +# RUN: lld -flavor gnu -target mipsel -e S0 -o %t.exe %t-micro.o +# RUN: llvm-readobj -symbols %t.exe | FileCheck -check-prefix=EXE-SYM %s +# RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck -check-prefix=EXE-DSYM %s + +# SO: Symbol { +# SO: Name: S0@ (1) +# SO-NEXT: Value: 0xEC +# SO-NEXT: Size: 4 +# SO-NEXT: Binding: Global (0x1) +# SO-NEXT: Type: Function (0x2) +# SO-NEXT: Other: 0 +# SO-NEXT: Section: .text (0x4) +# SO-NEXT: } + +# SO: Symbol { +# SO: Name: S1@ (4) +# SO-NEXT: Value: 0xF1 +# SO-NEXT: Size: 4 +# SO-NEXT: Binding: Global (0x1) +# SO-NEXT: Type: Function (0x2) +# SO-NEXT: Other: 0 +# SO-NEXT: Section: .text (0x4) +# SO-NEXT: } + +# EXE-SYM: Symbol { +# EXE-SYM: Name: S0 (1) +# EXE-SYM-NEXT: Value: 0x400108 +# EXE-SYM-NEXT: Size: 4 +# EXE-SYM-NEXT: Binding: Global (0x1) +# EXE-SYM-NEXT: Type: Function (0x2) +# EXE-SYM-NEXT: Other: 0 +# EXE-SYM-NEXT: Section: .text (0x5) +# EXE-SYM-NEXT: } + +# EXE-SYM: Symbol { +# EXE-SYM: Name: S1 (4) +# EXE-SYM-NEXT: Value: 0x40010D +# EXE-SYM-NEXT: Size: 4 +# EXE-SYM-NEXT: Binding: Global (0x1) +# EXE-SYM-NEXT: Type: Function (0x2) +# EXE-SYM-NEXT: Other: 128 +# EXE-SYM-NEXT: Section: .text (0x5) +# EXE-SYM-NEXT: } + +# EXE-DSYM-NOT: Name: S1 (4) + +# micro.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + +Symbols: + Global: + - Name: S0 + Type: STT_FUNC + Section: .text + Size: 0x04 + Value: 0x00 + Visibility: STV_DEFAULT + Other: [ ] + + - Name: S1 + Type: STT_FUNC + Section: .text + Size: 0x04 + Value: 0x04 + Visibility: STV_DEFAULT + Other: [ STO_MIPS_MICROMIPS ] +... diff --git a/test/elf/Mips/tls-1-micro.test b/test/elf/Mips/tls-1-micro.test new file mode 100644 index 000000000000..bd962b4e9e80 --- /dev/null +++ b/test/elf/Mips/tls-1-micro.test @@ -0,0 +1,65 @@ +# Check handling of R_MICROMIPS_TLS_TPREL_HI16 / R_MICROMIPS_TLS_TPREL_LO16 +# relocations. + +# RUN: yaml2obj -format=elf -o %t.o %s +# RUN: lld -flavor gnu -target mipsel -e L0 -o %t.exe %t.o +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK: 400150 00000000 00000100 00000380 00000480 ................ + +!ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Content: '00000100000002000000030000000400' + - Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: L1 + Type: R_MICROMIPS_TLS_TPREL_HI16 + - Offset: 0x04 + Symbol: L2 + Type: R_MICROMIPS_TLS_TPREL_HI16 + - Offset: 0x08 + Symbol: L2 + Type: R_MICROMIPS_TLS_TPREL_LO16 + - Offset: 0x0C + Symbol: L1 + Type: R_MICROMIPS_TLS_TPREL_LO16 + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Address: 0x1000 + Size: 0x20000 + +Symbols: + Global: + - Name: L0 + Type: STT_FUNC + Section: .text + Size: 0x58 + Other: [ STO_MIPS_MICROMIPS ] + - Name: L1 + Type: STT_TLS + Section: .tdata + Value: 0x00 + Size: 0x04 + - Name: L2 + Type: STT_TLS + Section: .tdata + Value: 0x10000 + Size: 0x04 diff --git a/test/elf/Mips/tls-1.test b/test/elf/Mips/tls-1.test new file mode 100644 index 000000000000..99176e69171d --- /dev/null +++ b/test/elf/Mips/tls-1.test @@ -0,0 +1,63 @@ +# Check handling of R_MIPS_TLS_TPREL_HI16 / R_MIPS_TLS_TPREL_LO16 relocations. + +# RUN: yaml2obj -format=elf -o %t.o %s +# RUN: lld -flavor gnu -target mipsel -e L0 -o %t.exe %t.o +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK: 400150 00000000 01000000 03800000 04800000 ................ + +!ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Content: '01000000020000000300000004000000' + - Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: L1 + Type: R_MIPS_TLS_TPREL_HI16 + - Offset: 0x04 + Symbol: L2 + Type: R_MIPS_TLS_TPREL_HI16 + - Offset: 0x08 + Symbol: L2 + Type: R_MIPS_TLS_TPREL_LO16 + - Offset: 0x0C + Symbol: L1 + Type: R_MIPS_TLS_TPREL_LO16 + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Address: 0x1000 + Size: 0x20000 + +Symbols: + Global: + - Name: L0 + Type: STT_FUNC + Section: .text + Size: 0x58 + - Name: L1 + Type: STT_TLS + Section: .tdata + Value: 0x00 + Size: 0x04 + - Name: L2 + Type: STT_TLS + Section: .tdata + Value: 0x10000 + Size: 0x04 diff --git a/test/elf/Mips/tls-2-64.test b/test/elf/Mips/tls-2-64.test new file mode 100644 index 000000000000..a068934aeafa --- /dev/null +++ b/test/elf/Mips/tls-2-64.test @@ -0,0 +1,69 @@ +# Check handling of R_MIPS_TLS_GOTTPREL and R_MIPS_TLS_GD relocations +# and generation of corresponding dynamic relocations R_MIPS_TLS_TPREL64, +# R_MIPS_TLS_DTPMOD64 and R_MIPS_TLS_DTPREL64 in case of shared library. + +# Create a shared library with thread symbol D1. +# RUN: yaml2obj -format=elf -o %t-so.o %s +# RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t-so.o + +# Check dynamic relocations and GOT in the shared library. +# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=REL %s +# RUN: llvm-readobj -dynamic-table %t.so | FileCheck -check-prefix=DYN %s +# RUN: llvm-readobj -dt %t.so | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=GOT %s + +# REL: Section (4) .rel.dyn { +# REL-NEXT: 0x2010 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE D1 0x0 +# REL-NEXT: 0x2018 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE D1 0x0 +# REL-NEXT: } + +# DYN: 0x000000007000000A MIPS_LOCAL_GOTNO 2 +# DYN: 0x0000000070000013 MIPS_GOTSYM 0x3 + +# SYM: Name: T1@ (1) +# SYM: Name: D1@ (4) + +# GOT: Contents of section .got: +# GOT-NEXT: 2000 00000000 00000000 00000000 00000080 ................ +# GOT-NEXT: 2010 00000000 00000000 00000000 00000000 ................ + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 4 + Size: 4 + - Name: .rel.text + Type: SHT_RELA + Link: .symtab + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: D1 + Type: R_MIPS_TLS_GD + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 4 + Size: 8 + +Symbols: + Global: + - Name: T1 + Type: STT_FUNC + Section: .text + Size: 4 + - Name: D1 + Type: STT_TLS + Section: .tdata + Size: 8 +... diff --git a/test/elf/Mips/tls-2-micro.test b/test/elf/Mips/tls-2-micro.test new file mode 100644 index 000000000000..5a1fe2904ac9 --- /dev/null +++ b/test/elf/Mips/tls-2-micro.test @@ -0,0 +1,70 @@ +# Check handling of R_MICROMIPS_TLS_GOTTPREL and R_MICROMIPS_TLS_GD relocations +# and generation of corresponding dynamic relocations R_MIPS_TLS_TPREL32, +# R_MIPS_TLS_DTPMOD32 and R_MIPS_TLS_DTPREL32 in case of shared library. + +# Create a shared library with thread symbol D1. +# RUN: yaml2obj -format=elf -o %t-so.o %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Check dynamic relocations and GOT in the shared library. +# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=REL %s +# RUN: llvm-readobj -dynamic-table %t.so | FileCheck -check-prefix=DYN %s +# RUN: llvm-readobj -dt %t.so | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=GOT %s + +# REL: Section (4) .rel.dyn { +# REL-NEXT: 0x2008 R_MIPS_TLS_DTPMOD32 D1 0x0 +# REL-NEXT: 0x200C R_MIPS_TLS_DTPREL32 D1 0x0 +# REL-NEXT: } + +# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2 +# DYN: 0x70000013 MIPS_GOTSYM 0x3 + +# SYM: Name: T1@ (1) +# SYM: Name: D1@ (4) + +# GOT: Contents of section .got: +# GOT-NEXT: 2000 00000000 00000080 00000000 00000000 ................ + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: D1 + Type: R_MICROMIPS_TLS_GD + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T1 + Type: STT_FUNC + Section: .text + Size: 0x04 + Other: [ STO_MIPS_MICROMIPS ] + - Name: D1 + Type: STT_TLS + Section: .tdata + Size: 0x04 +... diff --git a/test/elf/Mips/tls-2.test b/test/elf/Mips/tls-2.test new file mode 100644 index 000000000000..32b2bc105112 --- /dev/null +++ b/test/elf/Mips/tls-2.test @@ -0,0 +1,69 @@ +# Check handling of R_MIPS_TLS_GOTTPREL and R_MIPS_TLS_GD relocations +# and generation of corresponding dynamic relocations R_MIPS_TLS_TPREL32, +# R_MIPS_TLS_DTPMOD32 and R_MIPS_TLS_DTPREL32 in case of shared library. + +# Create a shared library with thread symbol D1. +# RUN: yaml2obj -format=elf -o %t-so.o %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Check dynamic relocations and GOT in the shared library. +# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=REL %s +# RUN: llvm-readobj -dynamic-table %t.so | FileCheck -check-prefix=DYN %s +# RUN: llvm-readobj -dt %t.so | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=GOT %s + +# REL: Section (4) .rel.dyn { +# REL-NEXT: 0x2008 R_MIPS_TLS_DTPMOD32 D1 0x0 +# REL-NEXT: 0x200C R_MIPS_TLS_DTPREL32 D1 0x0 +# REL-NEXT: } + +# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2 +# DYN: 0x70000013 MIPS_GOTSYM 0x3 + +# SYM: Name: T1@ (1) +# SYM: Name: D1@ (4) + +# GOT: Contents of section .got: +# GOT-NEXT: 2000 00000000 00000080 00000000 00000000 ................ + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: D1 + Type: R_MIPS_TLS_GD + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T1 + Type: STT_FUNC + Section: .text + Size: 0x04 + - Name: D1 + Type: STT_TLS + Section: .tdata + Size: 0x04 +... diff --git a/test/elf/Mips/tls-3-micro.test b/test/elf/Mips/tls-3-micro.test new file mode 100644 index 000000000000..0e0f3d556f8f --- /dev/null +++ b/test/elf/Mips/tls-3-micro.test @@ -0,0 +1,183 @@ +# Check handling of R_MICROMIPS_TLS_GOTTPREL and R_MICROMIPS_TLS_GD relocations +# and generation of corresponding dynamic relocations R_MIPS_TLS_TPREL32, +# R_MIPS_TLS_DTPMOD32 and R_MIPS_TLS_DTPREL32 in case of executable linking. + +# Create a shared library with thread symbol D1. +# RUN: yaml2obj -format=elf -docnum 1 -o %t-so.o %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Create executable file linked using two object files and the shared library. +# The object files defines thread symbols D0 and D2. +# RUN: yaml2obj -format=elf -docnum 2 -o %t-o1.o %s +# RUN: yaml2obj -format=elf -docnum 3 -o %t-o2.o %s +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o1.o %t-o2.o %t.so + +# Check dynamic relocations and GOT in the executable file. +# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s +# RUN: llvm-readobj -dynamic-table %t.exe | FileCheck -check-prefix=DYN %s +# RUN: llvm-readobj -dt %t.exe | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=GOT %s + +# REL: Section (5) .rel.dyn { +# REL-NEXT: 0x402008 R_MIPS_TLS_TPREL32 D1 0x0 +# REL-NEXT: 0x40200C R_MIPS_TLS_TPREL32 D2 0x0 +# REL-NEXT: } + +# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2 +# DYN: 0x70000013 MIPS_GOTSYM 0x3 + +# SYM: Name: D2@ (1) +# SYM: Name: D1@ (4) + +# GOT: Contents of section .got: +# GOT-NEXT: 402000 00000000 00000080 00000000 00000000 ................ + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: D1 + Type: R_MICROMIPS_TLS_GD + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T1 + Type: STT_FUNC + Section: .text + Size: 0x04 + Other: [ STO_MIPS_MICROMIPS ] + - Name: D1 + Type: STT_TLS + Section: .tdata + Size: 0x04 + +# o1.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: D2 + Type: R_MICROMIPS_TLS_TPREL_HI16 + - Offset: 0x04 + Symbol: D2 + Type: R_MICROMIPS_TLS_TPREL_LO16 + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T2 + Type: STT_FUNC + Section: .text + Size: 0x08 + Other: [ STO_MIPS_MICROMIPS ] + - Name: D2 + Type: STT_TLS + Section: .tdata + Size: 0x04 + +# o2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x10 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: D1 + Type: R_MICROMIPS_TLS_GOTTPREL + Addend: 0 + - Offset: 0x04 + Symbol: D0 + Type: R_MICROMIPS_TLS_TPREL_HI16 + Addend: 0 + - Offset: 0x08 + Symbol: D0 + Type: R_MICROMIPS_TLS_TPREL_LO16 + Addend: 0 + - Offset: 0x0C + Symbol: D2 + Type: R_MICROMIPS_TLS_GOTTPREL + Addend: 0 + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: D0 + Type: STT_TLS + Section: .tdata + Size: 0x04 + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x10 + Other: [ STO_MIPS_MICROMIPS ] + - Name: D1 + Type: STT_TLS + - Name: D2 + Type: STT_TLS +... diff --git a/test/elf/Mips/tls-3.test b/test/elf/Mips/tls-3.test new file mode 100644 index 000000000000..7e54724fade5 --- /dev/null +++ b/test/elf/Mips/tls-3.test @@ -0,0 +1,180 @@ +# Check handling of R_MIPS_TLS_GOTTPREL and R_MIPS_TLS_GD relocations +# and generation of corresponding dynamic relocations R_MIPS_TLS_TPREL32, +# R_MIPS_TLS_DTPMOD32 and R_MIPS_TLS_DTPREL32 in case of executable linking. + +# Create a shared library with thread symbol D1. +# RUN: yaml2obj -format=elf -docnum 1 -o %t-so.o %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o + +# Create executable file linked using two object files and the shared library. +# The object files defines thread symbols D0 and D2. +# RUN: yaml2obj -format=elf -docnum 2 -o %t-o1.o %s +# RUN: yaml2obj -format=elf -docnum 3 -o %t-o2.o %s +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o1.o %t-o2.o %t.so + +# Check dynamic relocations and GOT in the executable file. +# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s +# RUN: llvm-readobj -dynamic-table %t.exe | FileCheck -check-prefix=DYN %s +# RUN: llvm-readobj -dt %t.exe | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=GOT %s + +# REL: Section (5) .rel.dyn { +# REL-NEXT: 0x402008 R_MIPS_TLS_TPREL32 D1 0x0 +# REL-NEXT: 0x40200C R_MIPS_TLS_TPREL32 D2 0x0 +# REL-NEXT: } + +# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2 +# DYN: 0x70000013 MIPS_GOTSYM 0x3 + +# SYM: Name: D2@ (1) +# SYM: Name: D1@ (4) + +# GOT: Contents of section .got: +# GOT-NEXT: 402000 00000000 00000080 00000000 00000000 ................ + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: D1 + Type: R_MIPS_TLS_GD + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T1 + Type: STT_FUNC + Section: .text + Size: 0x04 + - Name: D1 + Type: STT_TLS + Section: .tdata + Size: 0x04 + +# o1.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: D2 + Type: R_MIPS_TLS_TPREL_HI16 + - Offset: 0x04 + Symbol: D2 + Type: R_MIPS_TLS_TPREL_LO16 + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T2 + Type: STT_FUNC + Section: .text + Size: 0x08 + - Name: D2 + Type: STT_TLS + Section: .tdata + Size: 0x04 + +# o2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x10 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0x00 + Symbol: D1 + Type: R_MIPS_TLS_GOTTPREL + Addend: 0 + - Offset: 0x04 + Symbol: D0 + Type: R_MIPS_TLS_TPREL_HI16 + Addend: 0 + - Offset: 0x08 + Symbol: D0 + Type: R_MIPS_TLS_TPREL_LO16 + Addend: 0 + - Offset: 0x0C + Symbol: D2 + Type: R_MIPS_TLS_GOTTPREL + Addend: 0 + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: D0 + Type: STT_TLS + Section: .tdata + Size: 0x04 + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x10 + - Name: D1 + Type: STT_TLS + - Name: D2 + Type: STT_TLS +... diff --git a/test/elf/Mips/tls-4-micro.test b/test/elf/Mips/tls-4-micro.test new file mode 100644 index 000000000000..1b0d03fa8875 --- /dev/null +++ b/test/elf/Mips/tls-4-micro.test @@ -0,0 +1,126 @@ +# Check handling of R_MICROMIPS_TLS_LDM relocation and generation +# of corresponding dynamic relocation R_MICROMIPS_TLS_DTPMOD32. + +# RUN: yaml2obj -format=elf -docnum 1 -o %t-so1.o %s +# RUN: yaml2obj -format=elf -docnum 2 -o %t-so2.o %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so1.o %t-so2.o + +# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=REL %s +# RUN: llvm-readobj -dynamic-table %t.so | FileCheck -check-prefix=DYN %s +# RUN: llvm-readobj -dt %t.so | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=GOT %s + +# REL: Section (4) .rel.dyn { +# REL-NEXT: 0x2008 R_MIPS_TLS_DTPMOD32 - 0x0 +# REL-NEXT: } + +# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2 +# DYN: 0x70000013 MIPS_GOTSYM 0x4 + +# SYM: Name: @ (0) +# SYM: Name: T1@ (1) +# SYM: Name: T2@ (4) +# SYM: Name: T3@ (7) + +# GOT: Contents of section .got: +# GOT-NEXT: 2000 00000000 00000080 00000000 00000000 ................ +# Two LDM entries --^--------^ + +# so1.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: L01 + Type: R_MICROMIPS_TLS_LDM + - Offset: 0x04 + Symbol: L01 + Type: R_MICROMIPS_TLS_LDM + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Local: + - Name: L01 + Type: STT_TLS + Section: .tdata + Size: 0x04 + Global: + - Name: T1 + Type: STT_FUNC + Section: .text + Value: 0x00 + Size: 0x04 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T2 + Type: STT_FUNC + Section: .text + Value: 0x04 + Size: 0x04 + Other: [ STO_MIPS_MICROMIPS ] + +# so2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: L02 + Type: R_MICROMIPS_TLS_LDM + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Local: + - Name: L02 + Type: STT_TLS + Section: .tdata + Size: 0x04 + Global: + - Name: T3 + Type: STT_FUNC + Section: .text + Size: 0x04 + Other: [ STO_MIPS_MICROMIPS ] +... diff --git a/test/elf/Mips/tls-4.test b/test/elf/Mips/tls-4.test new file mode 100644 index 000000000000..fb42f0d93378 --- /dev/null +++ b/test/elf/Mips/tls-4.test @@ -0,0 +1,123 @@ +# Check handling of R_MIPS_TLS_LDM relocation and generation of corresponding +# dynamic relocation R_MIPS_TLS_DTPMOD32. + +# RUN: yaml2obj -format=elf -docnum 1 -o %t-so1.o %s +# RUN: yaml2obj -format=elf -docnum 2 -o %t-so2.o %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so1.o %t-so2.o + +# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=REL %s +# RUN: llvm-readobj -dynamic-table %t.so | FileCheck -check-prefix=DYN %s +# RUN: llvm-readobj -dt %t.so | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=GOT %s + +# REL: Section (4) .rel.dyn { +# REL-NEXT: 0x2008 R_MIPS_TLS_DTPMOD32 - 0x0 +# REL-NEXT: } + +# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2 +# DYN: 0x70000013 MIPS_GOTSYM 0x4 + +# SYM: Name: @ (0) +# SYM: Name: T1@ (1) +# SYM: Name: T2@ (4) +# SYM: Name: T3@ (7) + +# GOT: Contents of section .got: +# GOT-NEXT: 2000 00000000 00000080 00000000 00000000 ................ +# Two LDM entries --^--------^ + +# so1.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: L01 + Type: R_MIPS_TLS_LDM + - Offset: 0x04 + Symbol: L01 + Type: R_MIPS_TLS_LDM + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Local: + - Name: L01 + Type: STT_TLS + Section: .tdata + Size: 0x04 + Global: + - Name: T1 + Type: STT_FUNC + Section: .text + Value: 0x00 + Size: 0x04 + - Name: T2 + Type: STT_FUNC + Section: .text + Value: 0x04 + Size: 0x04 + +# so2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x04 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: L02 + Type: R_MIPS_TLS_LDM + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Local: + - Name: L02 + Type: STT_TLS + Section: .tdata + Size: 0x04 + Global: + - Name: T3 + Type: STT_FUNC + Section: .text + Size: 0x04 +... diff --git a/test/elf/Mips/tls-5-64.test b/test/elf/Mips/tls-5-64.test new file mode 100644 index 000000000000..784d71efc48f --- /dev/null +++ b/test/elf/Mips/tls-5-64.test @@ -0,0 +1,71 @@ +# Check that in case of an executable file linking symbol referred +# by the R_MIPS_TLS_GD relocation gets an entry in the dynamic symbol table. + +# RUN: yaml2obj -format=elf -o %t-o.o %s +# RUN: lld -flavor gnu -target mips64el -e T0 -o %t.exe %t-o.o + +# Check dynamic relocations: +# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s +# Check dynamic symbol table: +# RUN: llvm-readobj -dt %t.exe | FileCheck -check-prefix=SYM %s + +# REL: Relocations [ +# REL-NEXT: Section (5) .rel.dyn { +# REL-NEXT: 0x120002010 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE T1 0x0 +# REL-NEXT: 0x120002018 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE T1 0x0 +# REL-NEXT: } +# REL-NEXT: ] + +# SYM: Symbol { +# SYM: Name: T1@ (1) +# SYM-NEXT: Value: 0x0 +# SYM-NEXT: Size: 8 +# SYM-NEXT: Binding: Global (0x1) +# SYM-NEXT: Type: TLS (0x6) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: .tdata (0x7) +# SYM-NEXT: } + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 8 + + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 4 + Info: .text + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MIPS_TLS_GD + + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 4 + Size: 8 + +Symbols: + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 8 + - Name: T1 + Type: STT_TLS + Section: .tdata + Value: 0 + Size: 8 +... diff --git a/test/elf/Mips/tls-5-micro.test b/test/elf/Mips/tls-5-micro.test new file mode 100644 index 000000000000..89d1d98a6877 --- /dev/null +++ b/test/elf/Mips/tls-5-micro.test @@ -0,0 +1,70 @@ +# Check that in case of an executable file linking symbol referred by +# the R_MICROMIPS_TLS_GD relocation gets an entry in the dynamic symbol table. + +# RUN: yaml2obj -format=elf -o %t-o.o %s +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o + +# Check dynamic relocations: +# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s +# Check dynamic symbol table: +# RUN: llvm-readobj -dt %t.exe | FileCheck -check-prefix=SYM %s + +# REL: Relocations [ +# REL-NEXT: Section (5) .rel.dyn { +# REL-NEXT: 0x402008 R_MIPS_TLS_DTPMOD32 T1 0x0 +# REL-NEXT: 0x40200C R_MIPS_TLS_DTPREL32 T1 0x0 +# REL-NEXT: } +# REL-NEXT: ] + +# SYM: Symbol { +# SYM: Name: T1@ (1) +# SYM-NEXT: Value: 0x0 +# SYM-NEXT: Size: 4 +# SYM-NEXT: Binding: Global (0x1) +# SYM-NEXT: Type: TLS (0x6) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: .tdata (0x7) +# SYM-NEXT: } + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x04 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MICROMIPS_TLS_GD + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x04 + Other: [ STO_MIPS_MICROMIPS ] + - Name: T1 + Type: STT_TLS + Section: .tdata + Value: 0x00 + Size: 0x04 +... diff --git a/test/elf/Mips/tls-5.test b/test/elf/Mips/tls-5.test new file mode 100644 index 000000000000..378ce321b8c9 --- /dev/null +++ b/test/elf/Mips/tls-5.test @@ -0,0 +1,69 @@ +# Check that in case of an executable file linking symbol referred +# by the R_MIPS_TLS_GD relocation gets an entry in the dynamic symbol table. + +# RUN: yaml2obj -format=elf -o %t-o.o %s +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o + +# Check dynamic relocations: +# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s +# Check dynamic symbol table: +# RUN: llvm-readobj -dt %t.exe | FileCheck -check-prefix=SYM %s + +# REL: Relocations [ +# REL-NEXT: Section (5) .rel.dyn { +# REL-NEXT: 0x402008 R_MIPS_TLS_DTPMOD32 T1 0x0 +# REL-NEXT: 0x40200C R_MIPS_TLS_DTPREL32 T1 0x0 +# REL-NEXT: } +# REL-NEXT: ] + +# SYM: Symbol { +# SYM: Name: T1@ (1) +# SYM-NEXT: Value: 0x0 +# SYM-NEXT: Size: 4 +# SYM-NEXT: Binding: Global (0x1) +# SYM-NEXT: Type: TLS (0x6) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: .tdata (0x7) +# SYM-NEXT: } + +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ] +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Size: 0x04 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: T1 + Type: R_MIPS_TLS_GD + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Size: 0x04 + - Name: T1 + Type: STT_TLS + Section: .tdata + Value: 0x00 + Size: 0x04 +... diff --git a/test/elf/X86_64/ExampleTarget/triple.test b/test/elf/X86_64/ExampleTarget/triple.test new file mode 100644 index 000000000000..3aecceb4305e --- /dev/null +++ b/test/elf/X86_64/ExampleTarget/triple.test @@ -0,0 +1,32 @@ +# Check that the Example Target is actually used. + +# RUN: yaml2obj -format=elf %s -o %t.o +# RUN: lld -flavor gnu -target x86_64-example-freebsd9 %t.o -o %t.exe +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s +# +# CHECK: Type: 0xFF00 + +# object + +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E5B864000000C745FC000000005DC366666666662E0F1F840000000000554889E531C05DC3 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: _start + Type: STT_FUNC + Section: .text + Size: 0x0000000000000000 diff --git a/test/elf/X86_64/Inputs/constint.c b/test/elf/X86_64/Inputs/constint.c new file mode 100644 index 000000000000..9fc0ebcf6591 --- /dev/null +++ b/test/elf/X86_64/Inputs/constint.c @@ -0,0 +1 @@ +const int b = 20; diff --git a/test/elf/X86_64/Inputs/constint.o b/test/elf/X86_64/Inputs/constint.o Binary files differnew file mode 100644 index 000000000000..8324b73014d0 --- /dev/null +++ b/test/elf/X86_64/Inputs/constint.o diff --git a/test/elf/X86_64/Inputs/debug0.c b/test/elf/X86_64/Inputs/debug0.c new file mode 100644 index 000000000000..1ebe50087383 --- /dev/null +++ b/test/elf/X86_64/Inputs/debug0.c @@ -0,0 +1,5 @@ +int adena(); + +int main() { +return adena(); +} diff --git a/test/elf/X86_64/Inputs/debug0.x86-64 b/test/elf/X86_64/Inputs/debug0.x86-64 Binary files differnew file mode 100644 index 000000000000..914f5224b9a2 --- /dev/null +++ b/test/elf/X86_64/Inputs/debug0.x86-64 diff --git a/test/elf/X86_64/Inputs/debug1.c b/test/elf/X86_64/Inputs/debug1.c new file mode 100644 index 000000000000..281b8a361dbb --- /dev/null +++ b/test/elf/X86_64/Inputs/debug1.c @@ -0,0 +1,3 @@ +int adena() { +return 0; +} diff --git a/test/elf/X86_64/Inputs/debug1.x86-64 b/test/elf/X86_64/Inputs/debug1.x86-64 Binary files differnew file mode 100644 index 000000000000..bfc81458a034 --- /dev/null +++ b/test/elf/X86_64/Inputs/debug1.x86-64 diff --git a/test/elf/X86_64/Inputs/externtls.c b/test/elf/X86_64/Inputs/externtls.c new file mode 100644 index 000000000000..499a645a9217 --- /dev/null +++ b/test/elf/X86_64/Inputs/externtls.c @@ -0,0 +1,6 @@ +extern __thread int extern_tls; + +int main() { + extern_tls = 1; + return 0; +} diff --git a/test/elf/X86_64/Inputs/externtls.x86-64 b/test/elf/X86_64/Inputs/externtls.x86-64 Binary files differnew file mode 100644 index 000000000000..3019aa0ca27c --- /dev/null +++ b/test/elf/X86_64/Inputs/externtls.x86-64 diff --git a/test/elf/X86_64/Inputs/fn.c b/test/elf/X86_64/Inputs/fn.c new file mode 100644 index 000000000000..54939a2426b2 --- /dev/null +++ b/test/elf/X86_64/Inputs/fn.c @@ -0,0 +1,4 @@ +int fn() +{ + return 0; +} diff --git a/test/elf/X86_64/Inputs/fn.o b/test/elf/X86_64/Inputs/fn.o Binary files differnew file mode 100644 index 000000000000..4b67d459dfdb --- /dev/null +++ b/test/elf/X86_64/Inputs/fn.o diff --git a/test/elf/X86_64/Inputs/generaltls-so.o.yaml b/test/elf/X86_64/Inputs/generaltls-so.o.yaml new file mode 100644 index 000000000000..f0649e7639a6 --- /dev/null +++ b/test/elf/X86_64/Inputs/generaltls-so.o.yaml @@ -0,0 +1,68 @@ +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E566488D3D00000000666648E8000000008B005DC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000008 + Symbol: mynumber + Type: R_X86_64_TLSGD + Addend: -4 + - Offset: 0x0000000000000010 + Symbol: __tls_get_addr + Type: R_X86_64_PLT32 + Addend: -4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x0000000000000004 + Content: '21000000' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .tdata + Type: STT_SECTION + Section: .tdata + Global: + - Name: getnumber + Type: STT_FUNC + Section: .text + Size: 0x0000000000000018 + - Name: mynumber + Type: STT_TLS + Section: .tdata + Size: 0x0000000000000004 + - Name: _GLOBAL_OFFSET_TABLE_ + - Name: __tls_get_addr +... diff --git a/test/elf/X86_64/Inputs/group/1.c b/test/elf/X86_64/Inputs/group/1.c new file mode 100644 index 000000000000..f5e618bc4a85 --- /dev/null +++ b/test/elf/X86_64/Inputs/group/1.c @@ -0,0 +1,8 @@ +int _start() { + return 0; +} + +int main() { +fn(); +return 0; +} diff --git a/test/elf/X86_64/Inputs/group/1.o b/test/elf/X86_64/Inputs/group/1.o Binary files differnew file mode 100644 index 000000000000..743518eb0fa3 --- /dev/null +++ b/test/elf/X86_64/Inputs/group/1.o diff --git a/test/elf/X86_64/Inputs/group/fn.c b/test/elf/X86_64/Inputs/group/fn.c new file mode 100644 index 000000000000..e443c73a1ee0 --- /dev/null +++ b/test/elf/X86_64/Inputs/group/fn.c @@ -0,0 +1,4 @@ +int fn() { +fn1(); +return 0; +} diff --git a/test/elf/X86_64/Inputs/group/fn.o b/test/elf/X86_64/Inputs/group/fn.o Binary files differnew file mode 100644 index 000000000000..1134432449cd --- /dev/null +++ b/test/elf/X86_64/Inputs/group/fn.o diff --git a/test/elf/X86_64/Inputs/group/fn1.c b/test/elf/X86_64/Inputs/group/fn1.c new file mode 100644 index 000000000000..cca0df7fd277 --- /dev/null +++ b/test/elf/X86_64/Inputs/group/fn1.c @@ -0,0 +1,3 @@ +int fn1() { +fn2(); +} diff --git a/test/elf/X86_64/Inputs/group/fn1.o b/test/elf/X86_64/Inputs/group/fn1.o Binary files differnew file mode 100644 index 000000000000..2b02310003db --- /dev/null +++ b/test/elf/X86_64/Inputs/group/fn1.o diff --git a/test/elf/X86_64/Inputs/group/fn2.c b/test/elf/X86_64/Inputs/group/fn2.c new file mode 100644 index 000000000000..a60370ed1e6b --- /dev/null +++ b/test/elf/X86_64/Inputs/group/fn2.c @@ -0,0 +1,3 @@ +int fn2() { +return 0; +} diff --git a/test/elf/X86_64/Inputs/group/fn2.o b/test/elf/X86_64/Inputs/group/fn2.o Binary files differnew file mode 100644 index 000000000000..fabec849a775 --- /dev/null +++ b/test/elf/X86_64/Inputs/group/fn2.o diff --git a/test/elf/X86_64/Inputs/group/group.sh b/test/elf/X86_64/Inputs/group/group.sh new file mode 100755 index 000000000000..2eba1030160b --- /dev/null +++ b/test/elf/X86_64/Inputs/group/group.sh @@ -0,0 +1,38 @@ +cat > 1.c << \! +int _start() { + return 0; +} + +int main() { +fn(); +return 0; +} +! + +cat > fn.c << \! +int fn() { +fn1(); +return 0; +} +! + +cat > fn2.c << \! +int fn2() { +return 0; +} +! + +cat > fn1.c << \! +int fn1() { +fn2(); +} +! + +gcc -c 1.c fn.c fn2.c fn1.c +ar cr libfn.a fn.o fn2.o +ar cr libfn1.a fn1.o +lld -flavor gnu -target x86_64 -shared -o libfn2.so fn2.o +lld -flavor gnu -target x86_64 1.o libfn.a libfn1.a -o x +lld -flavor gnu -target x86_64 1.o --start-group libfn.a libfn1.a --end-group -o x +lld -flavor gnu -target x86_64 1.o --start-group fn.o fn2.o fn1.o --end-group -o x +lld -flavor gnu -target x86_64 1.o --start-group --whole-archive libfn.a --no-whole-archive libfn1.a --end-group -o x diff --git a/test/elf/X86_64/Inputs/group/libfn.a b/test/elf/X86_64/Inputs/group/libfn.a Binary files differnew file mode 100644 index 000000000000..c157c3babed9 --- /dev/null +++ b/test/elf/X86_64/Inputs/group/libfn.a diff --git a/test/elf/X86_64/Inputs/group/libfn.so b/test/elf/X86_64/Inputs/group/libfn.so Binary files differnew file mode 100755 index 000000000000..fcbd11fe5519 --- /dev/null +++ b/test/elf/X86_64/Inputs/group/libfn.so diff --git a/test/elf/X86_64/Inputs/group/libfn1.a b/test/elf/X86_64/Inputs/group/libfn1.a Binary files differnew file mode 100644 index 000000000000..69b9c75b5d16 --- /dev/null +++ b/test/elf/X86_64/Inputs/group/libfn1.a diff --git a/test/elf/X86_64/Inputs/group/libfn2.so b/test/elf/X86_64/Inputs/group/libfn2.so Binary files differnew file mode 100755 index 000000000000..7ce867373910 --- /dev/null +++ b/test/elf/X86_64/Inputs/group/libfn2.so diff --git a/test/elf/X86_64/Inputs/initfini-option.c b/test/elf/X86_64/Inputs/initfini-option.c new file mode 100644 index 000000000000..e9a6c08c12ac --- /dev/null +++ b/test/elf/X86_64/Inputs/initfini-option.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +void init() { + printf("%s\n", __FUNCTION__); +} + +void fini() { + printf("%s\n", __FUNCTION__); +} + +int main() { +} + diff --git a/test/elf/X86_64/Inputs/initfini-option.o b/test/elf/X86_64/Inputs/initfini-option.o Binary files differnew file mode 100644 index 000000000000..b1ba0557353c --- /dev/null +++ b/test/elf/X86_64/Inputs/initfini-option.o diff --git a/test/elf/X86_64/Inputs/initfini.c b/test/elf/X86_64/Inputs/initfini.c new file mode 100644 index 000000000000..9427a86b6c9b --- /dev/null +++ b/test/elf/X86_64/Inputs/initfini.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +void __attribute__ ((constructor)) constructor() { + printf("%s\n", __FUNCTION__); +} + +void __attribute__ ((destructor)) destructor() { + printf("%s\n", __FUNCTION__); +} + +int main() { + return 0; +} + diff --git a/test/elf/X86_64/Inputs/initfini.o b/test/elf/X86_64/Inputs/initfini.o Binary files differnew file mode 100644 index 000000000000..f0e55a90b8b6 --- /dev/null +++ b/test/elf/X86_64/Inputs/initfini.o diff --git a/test/elf/X86_64/Inputs/largebss.c b/test/elf/X86_64/Inputs/largebss.c new file mode 100644 index 000000000000..157d01755b6a --- /dev/null +++ b/test/elf/X86_64/Inputs/largebss.c @@ -0,0 +1,3 @@ +int largebss[1000] = { 0 }; +int largecommon[1000]; +__thread int largetbss[1000] = { 0 }; diff --git a/test/elf/X86_64/Inputs/largebss.o b/test/elf/X86_64/Inputs/largebss.o Binary files differnew file mode 100644 index 000000000000..377370ec2db2 --- /dev/null +++ b/test/elf/X86_64/Inputs/largebss.o diff --git a/test/elf/X86_64/Inputs/layoutpass/1.c b/test/elf/X86_64/Inputs/layoutpass/1.c new file mode 100644 index 000000000000..fec984503214 --- /dev/null +++ b/test/elf/X86_64/Inputs/layoutpass/1.c @@ -0,0 +1,8 @@ +int main() { + a(); + return 0; +} + +int b() { + return 0; +} diff --git a/test/elf/X86_64/Inputs/layoutpass/1.o b/test/elf/X86_64/Inputs/layoutpass/1.o Binary files differnew file mode 100644 index 000000000000..848a5b3321ac --- /dev/null +++ b/test/elf/X86_64/Inputs/layoutpass/1.o diff --git a/test/elf/X86_64/Inputs/layoutpass/2.c b/test/elf/X86_64/Inputs/layoutpass/2.c new file mode 100644 index 000000000000..fb9dbcc28aa6 --- /dev/null +++ b/test/elf/X86_64/Inputs/layoutpass/2.c @@ -0,0 +1,7 @@ +int a() { + return 0; +} + +int c() { + return 0; +} diff --git a/test/elf/X86_64/Inputs/layoutpass/2.o b/test/elf/X86_64/Inputs/layoutpass/2.o Binary files differnew file mode 100644 index 000000000000..4c5ef8679581 --- /dev/null +++ b/test/elf/X86_64/Inputs/layoutpass/2.o diff --git a/test/elf/X86_64/Inputs/layoutpass/3.c b/test/elf/X86_64/Inputs/layoutpass/3.c new file mode 100644 index 000000000000..054029fe5cfe --- /dev/null +++ b/test/elf/X86_64/Inputs/layoutpass/3.c @@ -0,0 +1,3 @@ +int d() { + return 0; +} diff --git a/test/elf/X86_64/Inputs/layoutpass/3.o b/test/elf/X86_64/Inputs/layoutpass/3.o Binary files differnew file mode 100644 index 000000000000..76ef76e97901 --- /dev/null +++ b/test/elf/X86_64/Inputs/layoutpass/3.o diff --git a/test/elf/X86_64/Inputs/layoutpass/lib2.a b/test/elf/X86_64/Inputs/layoutpass/lib2.a Binary files differnew file mode 100644 index 000000000000..5f076c869817 --- /dev/null +++ b/test/elf/X86_64/Inputs/layoutpass/lib2.a diff --git a/test/elf/X86_64/Inputs/libfn.a b/test/elf/X86_64/Inputs/libfn.a Binary files differnew file mode 100644 index 000000000000..380844b0838d --- /dev/null +++ b/test/elf/X86_64/Inputs/libfn.a diff --git a/test/elf/X86_64/Inputs/libfn.so b/test/elf/X86_64/Inputs/libfn.so Binary files differnew file mode 100755 index 000000000000..dc02480aa690 --- /dev/null +++ b/test/elf/X86_64/Inputs/libfn.so diff --git a/test/elf/X86_64/Inputs/main.c b/test/elf/X86_64/Inputs/main.c new file mode 100644 index 000000000000..0280c9127076 --- /dev/null +++ b/test/elf/X86_64/Inputs/main.c @@ -0,0 +1,4 @@ +int main() { + fn(); + return 0; +} diff --git a/test/elf/X86_64/Inputs/main.o b/test/elf/X86_64/Inputs/main.o Binary files differnew file mode 100644 index 000000000000..ec8929f4b51d --- /dev/null +++ b/test/elf/X86_64/Inputs/main.o diff --git a/test/elf/X86_64/Inputs/multi-ovrd.c b/test/elf/X86_64/Inputs/multi-ovrd.c new file mode 100644 index 000000000000..cf6c0b6ac361 --- /dev/null +++ b/test/elf/X86_64/Inputs/multi-ovrd.c @@ -0,0 +1,10 @@ +#include <stdio.h> +void f(void) +{ + printf("overridden f!\n"); +} + +void g(void) +{ + printf("overridden g!\n"); +} diff --git a/test/elf/X86_64/Inputs/multi-ovrd.o b/test/elf/X86_64/Inputs/multi-ovrd.o Binary files differnew file mode 100644 index 000000000000..e4c4d6037fdd --- /dev/null +++ b/test/elf/X86_64/Inputs/multi-ovrd.o diff --git a/test/elf/X86_64/Inputs/multi-weak.c b/test/elf/X86_64/Inputs/multi-weak.c new file mode 100644 index 000000000000..10b9160352d9 --- /dev/null +++ b/test/elf/X86_64/Inputs/multi-weak.c @@ -0,0 +1,20 @@ +int fn() +{ + return 0; +} + +void __attribute__((weak)) f() +{ + printf("original f..\n"); +} + +void __attribute__((weak)) g() +{ + printf("original f..\n"); +} + +int main(void) +{ + f(); + return 0; +} diff --git a/test/elf/X86_64/Inputs/multi-weak.o b/test/elf/X86_64/Inputs/multi-weak.o Binary files differnew file mode 100644 index 000000000000..d5677b699ac4 --- /dev/null +++ b/test/elf/X86_64/Inputs/multi-weak.o diff --git a/test/elf/X86_64/Inputs/multiweaksyms.o b/test/elf/X86_64/Inputs/multiweaksyms.o Binary files differnew file mode 100644 index 000000000000..5e2e54d66b0d --- /dev/null +++ b/test/elf/X86_64/Inputs/multiweaksyms.o diff --git a/test/elf/X86_64/Inputs/nmagic.c b/test/elf/X86_64/Inputs/nmagic.c new file mode 100644 index 000000000000..3ad15f0c4971 --- /dev/null +++ b/test/elf/X86_64/Inputs/nmagic.c @@ -0,0 +1,8 @@ +int a = 10; +__thread int b = 20; +__thread int c; +__thread int d; + +int main() { + return 0; +} diff --git a/test/elf/X86_64/Inputs/nmagic.o b/test/elf/X86_64/Inputs/nmagic.o Binary files differnew file mode 100644 index 000000000000..af28e0ada8b3 --- /dev/null +++ b/test/elf/X86_64/Inputs/nmagic.o diff --git a/test/elf/X86_64/Inputs/no-interp-section.c b/test/elf/X86_64/Inputs/no-interp-section.c new file mode 100644 index 000000000000..3981c038ed33 --- /dev/null +++ b/test/elf/X86_64/Inputs/no-interp-section.c @@ -0,0 +1 @@ +int c = 10; diff --git a/test/elf/X86_64/Inputs/no-interp-section.o b/test/elf/X86_64/Inputs/no-interp-section.o Binary files differnew file mode 100644 index 000000000000..063eb3244f22 --- /dev/null +++ b/test/elf/X86_64/Inputs/no-interp-section.o diff --git a/test/elf/X86_64/Inputs/note.o b/test/elf/X86_64/Inputs/note.o Binary files differnew file mode 100644 index 000000000000..d86b0cf85d19 --- /dev/null +++ b/test/elf/X86_64/Inputs/note.o diff --git a/test/elf/X86_64/Inputs/note.s b/test/elf/X86_64/Inputs/note.s new file mode 100644 index 000000000000..0a0b03da6bb7 --- /dev/null +++ b/test/elf/X86_64/Inputs/note.s @@ -0,0 +1,11 @@ + .section ".note.ident", "a" + .p2align 2 + .long 1f - 0f # name size (not including padding) + .long 3f - 2f # desc size (not including padding) + .long 0x01234567 # type +0: .asciz "NaMe" # name +1: .p2align 2 +2: .long 0x76543210 # desc + .long 0x89abcdef +3: .p2align 2 + diff --git a/test/elf/X86_64/Inputs/note_ro_rw.o b/test/elf/X86_64/Inputs/note_ro_rw.o Binary files differnew file mode 100644 index 000000000000..76f2486d2736 --- /dev/null +++ b/test/elf/X86_64/Inputs/note_ro_rw.o diff --git a/test/elf/X86_64/Inputs/note_ro_rw.s b/test/elf/X86_64/Inputs/note_ro_rw.s new file mode 100644 index 000000000000..2a0eff5dfb2b --- /dev/null +++ b/test/elf/X86_64/Inputs/note_ro_rw.s @@ -0,0 +1,21 @@ + .section ".note.ro", "a" + .p2align 2 + .long 1f - 0f # name size (not including padding) + .long 3f - 2f # desc size (not including padding) + .long 0x01234567 # type +0: .asciz "NaMe" # name +1: .p2align 2 +2: .long 0x76543210 # desc + .long 0x89abcdef +3: .p2align 2 + .section ".note.rw", "aw" + .p2align 2 + .long 1f - 0f # name size (not including padding) + .long 3f - 2f # desc size (not including padding) + .long 0x01234567 # type +0: .asciz "NaMe" # name +1: .p2align 2 +2: .long 0x76543210 # desc + .long 0x89abcdef +3: .p2align 2 + diff --git a/test/elf/X86_64/Inputs/ovrd.c b/test/elf/X86_64/Inputs/ovrd.c new file mode 100644 index 000000000000..a3d721dac2aa --- /dev/null +++ b/test/elf/X86_64/Inputs/ovrd.c @@ -0,0 +1,6 @@ +#include <stdio.h> +void f(void) +{ + printf("overridden f!\n"); +} + diff --git a/test/elf/X86_64/Inputs/ovrd.o b/test/elf/X86_64/Inputs/ovrd.o Binary files differnew file mode 100644 index 000000000000..ea7353d94ed9 --- /dev/null +++ b/test/elf/X86_64/Inputs/ovrd.o diff --git a/test/elf/X86_64/Inputs/rodata.c b/test/elf/X86_64/Inputs/rodata.c new file mode 100644 index 000000000000..01489fe550c8 --- /dev/null +++ b/test/elf/X86_64/Inputs/rodata.c @@ -0,0 +1,3 @@ +const char _nl_default_default_domain[] __attribute__ ((visibility ("hidden"))) = "messages"; +const char *_nl_current_default_domain __attribute__ ((visibility ("hidden"))) = _nl_default_default_domain; +const char _nl_default_default_dirname[] = "/usr/local"; diff --git a/test/elf/X86_64/Inputs/rodata.o b/test/elf/X86_64/Inputs/rodata.o Binary files differnew file mode 100644 index 000000000000..660606cdc9c0 --- /dev/null +++ b/test/elf/X86_64/Inputs/rodata.o diff --git a/test/elf/X86_64/Inputs/rodata.s b/test/elf/X86_64/Inputs/rodata.s new file mode 100644 index 000000000000..e1a2eb702736 --- /dev/null +++ b/test/elf/X86_64/Inputs/rodata.s @@ -0,0 +1,24 @@ + .file "x.c" + .hidden _nl_default_default_domain + .globl _nl_default_default_domain + .section .rodata._nl_default_default_domain,"ams",@progbits,1 + .type _nl_default_default_domain, @object + .size _nl_default_default_domain, 9 +_nl_default_default_domain: + .string "messages" + .hidden _nl_current_default_domain + .globl _nl_current_default_domain + .section .data._nl_current_default_domain,"aw",@progbits + .align 8 + .type _nl_current_default_domain, @object + .size _nl_current_default_domain, 8 +_nl_current_default_domain: + .quad _nl_default_default_domain + .globl _nl_default_default_dirname + .section .rodata._nl_default_default_dirname,"ams",@progbits,1 + .type _nl_default_default_dirname, @object + .size _nl_default_default_dirname, 11 +_nl_default_default_dirname: + .string "/usr/local" + .ident "GCC: (Ubuntu 4.8.1-2ubuntu1~10.04.1) 4.8.1" + .section .note.GNU-stack,"",@progbits diff --git a/test/elf/X86_64/Inputs/rwint.c b/test/elf/X86_64/Inputs/rwint.c new file mode 100644 index 000000000000..d1cf7d62c801 --- /dev/null +++ b/test/elf/X86_64/Inputs/rwint.c @@ -0,0 +1 @@ +int a = 10; diff --git a/test/elf/X86_64/Inputs/rwint.o b/test/elf/X86_64/Inputs/rwint.o Binary files differnew file mode 100644 index 000000000000..9fba51f07add --- /dev/null +++ b/test/elf/X86_64/Inputs/rwint.o diff --git a/test/elf/X86_64/Inputs/sectionmap.c b/test/elf/X86_64/Inputs/sectionmap.c new file mode 100644 index 000000000000..c4f530148949 --- /dev/null +++ b/test/elf/X86_64/Inputs/sectionmap.c @@ -0,0 +1,4 @@ +int foo __attribute__((section(".gcc_except_table.foo"))) = 4; +const int bar __attribute__((section(".data.rel.local"))) = 2; +const int baz __attribute__((section(".data.rel.ro"))) = 2; +const int bak __attribute__((section(".data.xyz"))) = 2; diff --git a/test/elf/X86_64/Inputs/sectionmap.o b/test/elf/X86_64/Inputs/sectionmap.o Binary files differnew file mode 100644 index 000000000000..599cf2cca563 --- /dev/null +++ b/test/elf/X86_64/Inputs/sectionmap.o diff --git a/test/elf/X86_64/Inputs/undefcpp.c b/test/elf/X86_64/Inputs/undefcpp.c new file mode 100644 index 000000000000..ce84c2a592b6 --- /dev/null +++ b/test/elf/X86_64/Inputs/undefcpp.c @@ -0,0 +1 @@ +int foo() { return _Z3fooPKc(); } diff --git a/test/elf/X86_64/Inputs/undefcpp.o b/test/elf/X86_64/Inputs/undefcpp.o Binary files differnew file mode 100644 index 000000000000..6b8ebf5b6ab0 --- /dev/null +++ b/test/elf/X86_64/Inputs/undefcpp.o diff --git a/test/elf/X86_64/Inputs/weak-zero-sized.o b/test/elf/X86_64/Inputs/weak-zero-sized.o Binary files differnew file mode 100644 index 000000000000..7c10c6a509ed --- /dev/null +++ b/test/elf/X86_64/Inputs/weak-zero-sized.o diff --git a/test/elf/X86_64/Inputs/weak.c b/test/elf/X86_64/Inputs/weak.c new file mode 100644 index 000000000000..ae07ffc745d8 --- /dev/null +++ b/test/elf/X86_64/Inputs/weak.c @@ -0,0 +1,14 @@ +int fn() +{ + return 0; +} + +void __attribute__((weak)) f() +{ + printf("original f..\n"); +} +int main(void) +{ + f(); + return 0; +} diff --git a/test/elf/X86_64/Inputs/weak.o b/test/elf/X86_64/Inputs/weak.o Binary files differnew file mode 100644 index 000000000000..41cc88a0c482 --- /dev/null +++ b/test/elf/X86_64/Inputs/weak.o diff --git a/test/elf/X86_64/Inputs/weak.s b/test/elf/X86_64/Inputs/weak.s new file mode 100644 index 000000000000..64ce779553b6 --- /dev/null +++ b/test/elf/X86_64/Inputs/weak.s @@ -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 diff --git a/test/elf/X86_64/Inputs/zerosizedsection.o b/test/elf/X86_64/Inputs/zerosizedsection.o Binary files differnew file mode 100644 index 000000000000..a0f2f13a307a --- /dev/null +++ b/test/elf/X86_64/Inputs/zerosizedsection.o diff --git a/test/elf/X86_64/Inputs/zerosizedsection.s b/test/elf/X86_64/Inputs/zerosizedsection.s new file mode 100644 index 000000000000..651ee3aab503 --- /dev/null +++ b/test/elf/X86_64/Inputs/zerosizedsection.s @@ -0,0 +1,3 @@ +.text +.data +.word .text diff --git a/test/elf/X86_64/alignoffset.test b/test/elf/X86_64/alignoffset.test new file mode 100644 index 000000000000..b061f8937935 --- /dev/null +++ b/test/elf/X86_64/alignoffset.test @@ -0,0 +1,119 @@ +# Checks that segments are aligned as per ELF spec. The segment virtual address +# modulo page alignment should be equal to offset modulo page alignment. + +# Build executable +# RUN: yaml2obj -format=elf -docnum 1 %s -o %t.o +# RUN: lld -flavor gnu -target x86_64 %t.o -o %t.exe -static \ +# RUN: --no-align-segments --rosegment --noinhibit-exec +# RUN: llvm-readobj -program-headers %t.exe | FileCheck %s +# +#CHECK: Offset: 0x15C +#CHECK: VirtualAddress: 0x40015C +#CHECK: PhysicalAddress: 0x40015C +# +# +#const int a = 0; +#int main() { +# foo(); +# return 0; +#} +# +#int foo() { return 0; } + +# object +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E54883EC10C745FC00000000E81C000000B9000000008945F889C84883C4105DC36666662E0F1F840000000000554889E5B8000000005DC3 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .rodata + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '00000000' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 005562756E747520636C616E672076657273696F6E20332E352E302D73766E3231373330342D317E6578703120286272616E636865732F72656C656173655F33352920286261736564206F6E204C4C564D20332E352E302900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C070890010000180000001C000000000000002400000000410E108602430D060000001800000038000000000000000B00000000410E108602430D06000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 + Addend: 0 + - Offset: 0x000000000000003C + Symbol: .text + Type: R_X86_64_PC32 + Addend: 48 +Symbols: + Local: + - Name: 1.c + Type: STT_FILE + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .rodata + Type: STT_SECTION + Section: .rodata + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: a + Type: STT_OBJECT + Section: .rodata + Size: 0x0000000000000004 + - Name: foo + Type: STT_FUNC + Section: .text + Value: 0x0000000000000030 + Size: 0x000000000000000B + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x0000000000000024 +... diff --git a/test/elf/X86_64/debug.test b/test/elf/X86_64/debug.test new file mode 100644 index 000000000000..a13d12fba382 --- /dev/null +++ b/test/elf/X86_64/debug.test @@ -0,0 +1,57 @@ +# Test that debug info is assigned typeNoAlloc and that the output sections have +# a virtual address of 0. +RUN: lld -flavor gnu -target x86_64 -e main --output-filetype=yaml \ +RUN: %p/Inputs/debug0.x86-64 %p/Inputs/debug1.x86-64 -o %t +RUN: FileCheck %s -check-prefix YAML < %t + +RUN: lld -flavor gnu -target x86_64 -e main %p/Inputs/debug0.x86-64 \ +RUN: %p/Inputs/debug1.x86-64 -o %t1 +RUN: llvm-readobj -sections %t1 | FileCheck %s -check-prefix ELF +# Verify that non SHF_ALLOC sections are relocated correctly. +RUN: llvm-objdump -s %t1 | FileCheck %s -check-prefix RELOC + +YAML: type: no-alloc + +ELF: Section { +ELF: Name: .debug_info +ELF: Type: SHT_PROGBITS (0x1) +ELF: Flags [ (0x0) +ELF: ] +ELF: Address: 0x0 +ELF: } +ELF: Section { +ELF: Name: .debug_abbrev +ELF: Type: SHT_PROGBITS (0x1) +ELF: Flags [ (0x0) +ELF: ] +ELF: Address: 0x0 +ELF: } +ELF: Section { +ELF: Name: .debug_aranges +ELF: Type: SHT_PROGBITS (0x1) +ELF: Flags [ (0x0) +ELF: ] +ELF: Address: 0x0 +ELF: } +ELF: Section { +ELF: Name: .debug_line +ELF: Type: SHT_PROGBITS (0x1) +ELF: Flags [ (0x0) +ELF: ] +ELF: Address: 0x0 +ELF: } +ELF: Section { +ELF: Name: .debug_str +ELF: Type: SHT_PROGBITS (0x1) +ELF: Flags [ (0x0) +ELF: ] +ELF: Address: 0x0 +ELF: } + +RELOC: Contents of section .debug_info: +RELOC: 0000 4e000000 04000000 00000801 3a000000 N...........:... +# ^^ Relocation: ._debug_str + 0x3a +RELOC: 0010 01780000 00000000 00dc0140 00000000 .x.........@.... +# ^^ Relocation: .debug_str + 0x78 +RELOC: 0020 00100000 00000000 00000000 00028100 ................ +# ^^ Relocation: .debug_str + 0x81 diff --git a/test/elf/X86_64/defsym.test b/test/elf/X86_64/defsym.test new file mode 100644 index 000000000000..5d2256a09ac8 --- /dev/null +++ b/test/elf/X86_64/defsym.test @@ -0,0 +1,22 @@ +RUN: lld -flavor gnu -target x86_64 --defsym=main=fn --noinhibit-exec \ +RUN: %p/Inputs/fn.o -o %t +RUN: llvm-readobj -symbols %t | FileCheck %s + +CHECK: Symbol { +CHECK: Name: main (1) +CHECK: Value: 0x4001E0 +CHECK: Size: 0 +CHECK: Binding: Global (0x1) +CHECK: Type: Function (0x2) +CHECK: Other: 0 +CHECK: Section: .text (0x5) +CHECK: } +CHECK: Symbol { +CHECK: Name: fn (6) +CHECK: Value: 0x4001E0 +CHECK: Size: 6 +CHECK: Binding: Global (0x1) +CHECK: Type: Function (0x2) +CHECK: Other: 0 +CHECK: Section: .text (0x5) +CHECK: } diff --git a/test/elf/X86_64/demangle.test b/test/elf/X86_64/demangle.test new file mode 100644 index 000000000000..1977fd7f1e3a --- /dev/null +++ b/test/elf/X86_64/demangle.test @@ -0,0 +1,12 @@ +# XFAIL: win32 +# +# Check that the linker is able to demangle strings properly. +# Once there is a way to add undefined symbols using yaml2obj, the test will be +# changed. + +RUN: lld -flavor gnu -target x86_64 %p/Inputs/undefcpp.o --noinhibit-exec 2>&1 | FileCheck -check-prefix=DEMANGLE %s +RUN: lld -flavor gnu -target x86_64 %p/Inputs/undefcpp.o --noinhibit-exec --no-demangle 2>&1 | FileCheck -check-prefix=NODEMANGLE %s +RUN: lld -flavor gnu -target x86_64 %p/Inputs/undefcpp.o --noinhibit-exec --demangle 2>&1 | FileCheck -check-prefix=DEMANGLE %s + +#DEMANGLE: undefcpp.o: foo(char const*) +#NODEMANGLE: undefcpp.o: _Z3fooPKc diff --git a/test/elf/X86_64/dontignorezerosize-sections.test b/test/elf/X86_64/dontignorezerosize-sections.test new file mode 100644 index 000000000000..101e6cb55b24 --- /dev/null +++ b/test/elf/X86_64/dontignorezerosize-sections.test @@ -0,0 +1,9 @@ +# This tests that lld is not ignoring zero sized sections +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/zerosizedsection.o \ +RUN: --noinhibit-exec --output-filetype=yaml -o %t +RUN: FileCheck %s < %t + +CHECK: references: +CHECK: - kind: R_X86_64_16 +CHECK: offset: 0 +CHECK: target: L000 diff --git a/test/elf/X86_64/dynamicvars.test b/test/elf/X86_64/dynamicvars.test new file mode 100644 index 000000000000..f5db73063650 --- /dev/null +++ b/test/elf/X86_64/dynamicvars.test @@ -0,0 +1,124 @@ +# Tests that the dynamic variables created by the linker are set to the right +# values. + +#RUN: yaml2obj --format elf -docnum 1 %s -o %t.o +#RUN: lld -flavor gnu -target x86_64 -e main %t.o -o %t1 --noinhibit-exec +#RUN: llvm-readobj -sections -symbols %t1 | FileCheck -check-prefix CHECKSYMS %s + + +#CHECKSYMS: Name: .dynamic +#CHECKSYMS: Type: SHT_DYNAMIC +#CHECKSYMS: Address: [[TARGETA:[0xa-fA-f0-9]+]] +#CHECKSYMS: Name: .got.plt +#CHECKSYMS: Type: SHT_PROGBITS +#CHECKSYMS: Address: [[TARGETB:[0xa-fA-f0-9]+]] +#CHECKSYMS: Name: _DYNAMIC +#CHECKSYMS: Value: [[TARGETA]] +#CHECKSYMS: Section: .dynamic +#CHECKSYMS: Name: _GLOBAL_OFFSET_TABLE_ +#CHECKSYMS: Value: [[TARGETB]] +#CHECKSYMS: Section: .got.plt + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E54883EC10488B0500000000C745FC00000000C7000A000000E80000000031C98945F889C84883C4105DC36690554889E531C05DC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x000000000000000B + Symbol: a + Type: R_X86_64_GOTPCREL + Addend: -4 + - Offset: 0x000000000000001D + Symbol: foo + Type: R_X86_64_PLT32 + Addend: -4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 00636C616E672076657273696F6E20332E362E302000 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C070890010000180000001C000000000000002E00000000410E108602430D060000001800000038000000000000000800000000410E108602430D06000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 + Addend: 0 + - Offset: 0x000000000000003C + Symbol: .text + Type: R_X86_64_PC32 + Addend: 48 +Symbols: + Local: + - Name: 1.c + Type: STT_FILE + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: a + Type: STT_OBJECT + Value: 0x0000000000000004 + Size: 0x0000000000000004 + - Name: foo + Type: STT_FUNC + Section: .text + Value: 0x0000000000000030 + Size: 0x0000000000000008 + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x000000000000002E + - Name: _GLOBAL_OFFSET_TABLE_ +... diff --git a/test/elf/X86_64/dynlib-nointerp-section.test b/test/elf/X86_64/dynlib-nointerp-section.test new file mode 100644 index 000000000000..dca3d925b38b --- /dev/null +++ b/test/elf/X86_64/dynlib-nointerp-section.test @@ -0,0 +1,4 @@ +RUN: lld -flavor gnu -target x86_64 %p/Inputs/no-interp-section.o -o %t -shared +RUN: llvm-objdump -section-headers %t | FileCheck %s + +CHECK-NOT: .interp diff --git a/test/elf/X86_64/dynlib-search.test b/test/elf/X86_64/dynlib-search.test new file mode 100644 index 000000000000..017208ac11ad --- /dev/null +++ b/test/elf/X86_64/dynlib-search.test @@ -0,0 +1,6 @@ +# This tests the functionality for finding the shared library libfn.so for ELF +RUN: lld -flavor gnu -target x86_64 %p/Inputs/main.o -L%p/Inputs/ -lfn -o %t \ +RUN: --noinhibit-exec -t 2> %t1 +RUN: FileCheck %s < %t1 + +CHECK: {{[\/0-9A-Za-z_]+}}libfn.so diff --git a/test/elf/X86_64/dynsym-weak.test b/test/elf/X86_64/dynsym-weak.test new file mode 100644 index 000000000000..4f05656a41f2 --- /dev/null +++ b/test/elf/X86_64/dynsym-weak.test @@ -0,0 +1,118 @@ +# Check that a symbol declared as a week in a shared library gets a dynamic +# symbol table record in an executable file if this executabe file declares the +# symbol as strong. + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t.foo.o +# RUN: lld -flavor gnu -target x86_64 -shared -o %t.so %t.foo.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t.main.o +# +# Link executable file with strong symbol. Weak symbol is in the shared lib. +# RUN: lld -flavor gnu -target x86_64 -e main -o %t1.exe %t.main.o %t.so +# RUN: llvm-readobj -dyn-symbols %t1.exe | FileCheck -check-prefix=EXE %s +# +# Link executable file. Strong and weak symbol come from different object files. +# RUN: lld -flavor gnu -target x86_64 -e main -o %t2.exe %t.main.o %t.foo.o +# RUN: llvm-readobj -dyn-symbols %t2.exe | FileCheck -check-prefix=OBJ %s +# +# Link shared library. Weak symbol is in the another shared lib. +# RUN: lld -flavor gnu -target x86_64 -shared -o %t.res.so %t.main.o %t.so +# RUN: llvm-readobj -dyn-symbols %t.res.so | FileCheck -check-prefix=SO %s + +# EXE: Symbol { +# EXE: Name: flag@ ({{[0-9]+}}) +# EXE-NEXT: Value: 0x{{[0-9A-F]+}} +# EXE-NEXT: Size: 4 +# EXE-NEXT: Binding: Global (0x1) +# EXE-NEXT: Type: Object (0x1) +# EXE-NEXT: Other: 0 +# EXE-NEXT: Section: .data (0x{{[0-9A-F]+}}) +# EXE-NEXT: } + +# OBJ-NOT: Name: flag@ ({{[0-9]+}}) + +# SO: Symbol { +# SO: Name: flag@ ({{[0-9]+}}) +# SO-NEXT: Value: 0x{{[0-9A-F]+}} +# SO-NEXT: Size: 4 +# SO-NEXT: Binding: Global (0x1) +# SO-NEXT: Type: Object (0x1) +# SO-NEXT: Other: 0 +# SO-NEXT: Section: .data (0x{{[0-9A-F]+}}) +# SO-NEXT: } + +# foo.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x08 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: flag + Type: R_X86_64_GOTPCREL + Addend: -4 + +Symbols: + Global: + - Name: foo + Type: STT_FUNC + Section: .text + Size: 0x08 + Weak: + - Name: flag + +# main.o +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x08 + Info: .text + Relocations: + - Offset: 0x00 + Symbol: foo + Type: R_X86_64_PLT32 + Addend: -4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x04 + Size: 0x04 + +Symbols: + Global: + - Name: flag + Type: STT_OBJECT + Section: .data + Size: 0x04 + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x08 + - Name: foo +... diff --git a/test/elf/X86_64/extern-tls.test b/test/elf/X86_64/extern-tls.test new file mode 100644 index 000000000000..c8e7580e5f3c --- /dev/null +++ b/test/elf/X86_64/extern-tls.test @@ -0,0 +1,16 @@ +# This tests verifies that TLS variables have correct offsets +# when variables the TLS variables are not defined in the program +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/externtls.x86-64 -static \ +RUN: --output-filetype=yaml --noinhibit-exec | FileCheck %s -check-prefix=CHECKGOT + + - name: __got_tls_extern_tls +CHECKGOT: type: got +CHECKGOT: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +CHECKGOT: alignment: 2^3 +CHECKGOT: section-choice: custom-required +CHECKGOT: section-name: .got +CHECKGOT: permissions: rw- +CHECKGOT: references: +CHECKGOT: - kind: R_X86_64_TPOFF64 +CHECKGOT: offset: 0 +CHECKGOT: target: extern_tls diff --git a/test/elf/X86_64/general-dynamic-tls.test b/test/elf/X86_64/general-dynamic-tls.test new file mode 100644 index 000000000000..c1a6f6e5d120 --- /dev/null +++ b/test/elf/X86_64/general-dynamic-tls.test @@ -0,0 +1,129 @@ +# This test exercises a simple general dynamic TLS access model in X86_64. +# +# It is composed of two parts: a program and a shared library. The shared +# library uses TLS, but the program does not. +# +# The shared library should import __tls_get_addr, since it uses the general +# dynamic TLS access mode (see www.akkadia.org/drepper/tls.pdf). Notice that +# once we support TLS strength reduction, this test should be updated, since +# this can be converted into a local dynamic TLS model. + +# Prepare inputs +#RUN: yaml2obj -format=elf %p/Inputs/generaltls-so.o.yaml -o=%t.o.so +#RUN: lld -flavor gnu -target x86_64 -shared %t.o.so -o %T/libgeneraltls.so +#RUN: yaml2obj -format=elf %s -o=%t.o + +# Link - (we supply --defsym=__tls_get_addr to avoid the need to link with +# system libraries) +#RUN: lld -flavor gnu -target x86_64 -e main %t.o -L%T -lgeneraltls -o %t1 \ +#RUN: --defsym=__tls_get_addr=0 + +# Check +#RUN: llvm-readobj -dyn-symbols %t1 | FileCheck -check-prefix CHECKPROG %s +#RUN: llvm-readobj -relocations -dyn-symbols %T/libgeneraltls.so | FileCheck \ +#RUN: -check-prefix CHECKDSO %s + +# Test case generated with the following code: +# +# DSO: (file %p/Inputs/generaltls-so.o.yaml) +# +# __thread int mynumber=33; +# +# int getnumber() { +# return mynumber; +# } +# +# Program: (this file). Note: The printf() relocation was removed to simplify +# this test and allow us to test this without libc. +# +# #include <stdio.h> +# int getnumber(); +# +# int main() { +# printf("getnumber() = %d\n", getnumber()); +# return 0; +# } +# +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E54883EC10C745FC00000000B000E80000000048BF000000000000000089C6B000E80000000031F68945F889F04883C4105DC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000012 + Symbol: getnumber + Type: R_X86_64_PC32 + Addend: -4 + - Offset: 0x0000000000000018 + Symbol: .rodata.str1.1 + Type: R_X86_64_64 + Addend: 0 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .rodata.str1.1 + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 6765746E756D6265722829203D2025640A00 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .rodata.str1.1 + Type: STT_SECTION + Section: .rodata.str1.1 + Global: + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x0000000000000036 + - Name: getnumber + +# Program should import the function defined in the shared library +#CHECKPROG: getnumber@ +# Program should not import __tls_get_addr, since it does not directly use TLS +#CHECKPROG-NOT: __tls_get_addr@ + +# Check for the presence of X86_64 TLS relocations in the shared library +#CHECKDSO: R_X86_64_DTPMOD64 +#CHECKDSO: R_X86_64_DTPOFF64 +#CHECKDSO: R_X86_64_JUMP_SLOT + +# The shared library should import __tls_get_addr, since it uses the general +# dynamic TLS access mode. +#CHECKDSO: Name: __tls_get_addr@ +#CHECKDSO-NEXT: Value: 0x0 +#CHECKDSO-NEXT: Size: 0 +#CHECKDSO-NEXT: Binding: Global +#CHECKDSO-NEXT: Type: None +#CHECKDSO-NEXT: Other: 0 +#CHECKDSO-NEXT: Section: Undefined + diff --git a/test/elf/X86_64/imagebase.test b/test/elf/X86_64/imagebase.test new file mode 100644 index 000000000000..67c3b6e1ff49 --- /dev/null +++ b/test/elf/X86_64/imagebase.test @@ -0,0 +1,94 @@ +# Checks that segments start at the image address specified. + +# Build executable +# RUN: yaml2obj -format=elf -docnum 1 %s -o %t.o +# RUN: lld -flavor gnu -target x86_64 %t.o -o %t.exe -static \ +# RUN: --no-align-segments --noinhibit-exec --image-base 0x600000 +# RUN: llvm-readobj -program-headers %t.exe | FileCheck %s +# +#CHECK: VirtualAddress: 0x600000 +#CHECK: PhysicalAddress: 0x600000 +#CHECK: VirtualAddress: 0x600178 +#CHECK: PhysicalAddress: 0x600178 + +# object +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E5B864000000C745FC000000005DC366666666662E0F1F840000000000554889E531C05DC3 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '64000000' + - Name: .rodata + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '64000000' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C070890010000180000001C000000000000001200000000410E108602430D060000001800000038000000000000000800000000410E108602430D06000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 + Addend: 0 + - Offset: 0x000000000000003C + Symbol: .text + Type: R_X86_64_PC32 + Addend: 32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: foo + Type: STT_FUNC + Section: .text + Value: 0x0000000000000020 + Size: 0x0000000000000008 + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x0000000000000012 + - Name: myval + Type: STT_OBJECT + Section: .bss + Size: 0x0000000000000004 + - Name: val + Type: STT_OBJECT + Section: .rodata + Size: 0x0000000000000004 +... diff --git a/test/elf/X86_64/initfini-order.test b/test/elf/X86_64/initfini-order.test new file mode 100644 index 000000000000..d3981eb0914e --- /dev/null +++ b/test/elf/X86_64/initfini-order.test @@ -0,0 +1,10 @@ +# This tests the functionality that lld is able to emit +# init_array/fini_array sections in the right order. + +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/initfini.o \ +RUN: --noinhibit-exec -o %t +RUN: llvm-objdump -t -section-headers %t | FileCheck %s + +CHECK: {{[0-9]+}} .eh_frame {{[0-9a-z]+}} {{[0-9a-z]+}} DATA +CHECK: {{[0-9]+}} .init_array {{[0-9a-z]+}} {{[0-9a-z]+}} DATA +CHECK: {{[0-9]+}} .fini_array {{[0-9a-z]+}} {{[0-9a-z]+}} DATA diff --git a/test/elf/X86_64/initfini.test b/test/elf/X86_64/initfini.test new file mode 100644 index 000000000000..d882352a1c38 --- /dev/null +++ b/test/elf/X86_64/initfini.test @@ -0,0 +1,23 @@ +# This tests the functionality that lld is able to read +# init_array/fini_array sections in the input ELF. This +# corresponds to the the .init_array/.fini_array sections +# in the output ELF. + +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/initfini.o \ +RUN: --noinhibit-exec --output-filetype=yaml -o %t +RUN: FileCheck %s < %t + +CHECK: - type: data +CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +CHECK: section-name: .init_array +CHECK: references: +CHECK: - kind: R_X86_64_64 +CHECK: offset: 0 +CHECK: target: constructor +CHECK: - type: data +CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +CHECK: section-name: .fini_array +CHECK: references: +CHECK: - kind: R_X86_64_64 +CHECK: offset: 0 +CHECK: target: destructor diff --git a/test/elf/X86_64/largebss.test b/test/elf/X86_64/largebss.test new file mode 100644 index 000000000000..d2dde4954139 --- /dev/null +++ b/test/elf/X86_64/largebss.test @@ -0,0 +1,20 @@ +# This tests the functionality of handling BSS symbols +# BSS symbols don't occupy file content and are associated with typeZeroFill +# Any typeZeroFill content wouldn't have space reserved in the file to store +# its content + +RUN: lld -flavor gnu -target x86_64 %p/Inputs/largebss.o --output-filetype=yaml --noinhibit-exec | FileCheck %s + +CHECK: - name: largecommon +CHECK: scope: global +CHECK: type: zero-fill +CHECK: size: 4000 +CHECK: merge: as-tentative +CHECK: - name: largebss +CHECK: scope: global +CHECK: type: zero-fill +CHECK: size: 4000 +CHECK: - name: largetbss +CHECK: scope: global +CHECK: type: thread-zero-fill +CHECK: size: 4000 diff --git a/test/elf/X86_64/layoutpass-order.test b/test/elf/X86_64/layoutpass-order.test new file mode 100644 index 000000000000..e4ebef1d52db --- /dev/null +++ b/test/elf/X86_64/layoutpass-order.test @@ -0,0 +1,14 @@ +# This test checks that we follow the command line order of layouting +# symbols in the output file + +RUN: lld -flavor gnu -target x86_64 %p/Inputs/layoutpass/1.o \ +RUN: %p/Inputs/layoutpass/lib2.a %p/Inputs/layoutpass/3.o -o %t \ +RUN: --noinhibit-exec -static + +RUN: llvm-nm -n %t | FileCheck -check-prefix=SYMBOLSORDER %s + +SYMBOLSORDER: {{[A-Fa-f0-9]+}} T main +SYMBOLSORDER: {{[A-Fa-f0-9]+}} T b +SYMBOLSORDER: {{[A-Fa-f0-9]+}} T a +SYMBOLSORDER: {{[A-Fa-f0-9]+}} T c +SYMBOLSORDER: {{[A-Fa-f0-9]+}} T d diff --git a/test/elf/X86_64/maxpagesize.test b/test/elf/X86_64/maxpagesize.test new file mode 100644 index 000000000000..649d09fcada0 --- /dev/null +++ b/test/elf/X86_64/maxpagesize.test @@ -0,0 +1,113 @@ +# Checks that segments are aligned as per ELF spec when the user specifies +# max-page-size option, and the segment alignment is set to the page size +# specified by the user. + +# Build executable +# RUN: yaml2obj -format=elf -docnum 1 %s -o %t.o +# RUN: not lld -flavor gnu -target x86_64 %t.o -o %t.exe -static \ +# RUN: --no-align-segments --noinhibit-exec -z max-page-size=0 +# RUN: not lld -flavor gnu -target x86_64 %t.o -o %t.exe -static \ +# RUN: --no-align-segments --noinhibit-exec -z max-page-size=0xFF +# RUN: not lld -flavor gnu -target x86_64 %t.o -o %t.exe -static \ +# RUN: --no-align-segments --noinhibit-exec -z max-page-size=0x1010 +# RUN: lld -flavor gnu -target x86_64 %t.o -o %t1.exe -static \ +# RUN: --no-align-segments --noinhibit-exec -z max-page-size=0x100000 +# RUN: lld -flavor gnu -target x86_64 %t.o -o %t.exe -static \ +# RUN: --no-align-segments --noinhibit-exec -z max-page-size=0x10000 +# RUN: llvm-readobj -program-headers %t.exe | FileCheck %s +# RUN: llvm-readobj -program-headers %t1.exe | FileCheck %s -check-prefix=CHECKLARGE +# +#CHECK: VirtualAddress: 0x400000 +#CHECK: PhysicalAddress: 0x400000 +#CHECK: Alignment: 65536 +#CHECK: VirtualAddress: 0x400178 +#CHECK: PhysicalAddress: 0x400178 +#CHECK: Alignment: 65536 +#CHECKLARGE: VirtualAddress: 0x400000 +#CHECKLARGE: PhysicalAddress: 0x400000 +#CHECKLARGE: Alignment: 1048576 +#CHECKLARGE: VirtualAddress: 0x400178 +#CHECKLARGE: PhysicalAddress: 0x400178 +#CHECKLARGE: Alignment: 1048576 + +# object +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E5B864000000C745FC000000005DC366666666662E0F1F840000000000554889E531C05DC3 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '64000000' + - Name: .rodata + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '64000000' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C070890010000180000001C000000000000001200000000410E108602430D060000001800000038000000000000000800000000410E108602430D06000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 + Addend: 0 + - Offset: 0x000000000000003C + Symbol: .text + Type: R_X86_64_PC32 + Addend: 32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: foo + Type: STT_FUNC + Section: .text + Value: 0x0000000000000020 + Size: 0x0000000000000008 + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x0000000000000012 + - Name: myval + Type: STT_OBJECT + Section: .bss + Size: 0x0000000000000004 + - Name: val + Type: STT_OBJECT + Section: .rodata + Size: 0x0000000000000004 +... diff --git a/test/elf/X86_64/mergesimilarstrings.test b/test/elf/X86_64/mergesimilarstrings.test new file mode 100644 index 000000000000..3836f0b50758 --- /dev/null +++ b/test/elf/X86_64/mergesimilarstrings.test @@ -0,0 +1,47 @@ +# Check that relocations to section that contains strings is properly handled +# when merging strings is enabled. +# +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target x86_64 %t.o --noinhibit-exec -o %t1.out +# RUN: llvm-readobj -sections %t1.out | FileCheck %s +# RUN: lld -flavor gnu -target x86_64 %t.o --noinhibit-exec -o %t2.out --output-filetype=yaml +# RUN: FileCheck %s -check-prefix=CHECKRELOCS < %t2.out + +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: 54889e5488d3d00000000e80000000088d3d00000000e800000000b8000000005dc3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x04 + Info: .text + Relocations: + - Offset: 0x07 + Symbol: .rodata + Type: R_X86_64_PC32 + Addend: -4 + - Name: .rodata + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x01 + Content: 48656c6c6f20576f726c6400576f726c6400 +Symbols: + Global: + - Name: .rodata + Section: .rodata + +#CHECK: Name: .rodata +#CHECK: Size: 18 +#CHECKRELOCS: references: +#CHECKRELOCS: - kind: R_X86_64_PC32 +#CHECKRELOCS: offset: 7 +#CHECKRELOCS: target: .rodata +#CHECKRELOCS: addend: -4 diff --git a/test/elf/X86_64/multi-weak-layout.test b/test/elf/X86_64/multi-weak-layout.test new file mode 100644 index 000000000000..4bbf1dfc7e90 --- /dev/null +++ b/test/elf/X86_64/multi-weak-layout.test @@ -0,0 +1,52 @@ +# 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 --output-filetype=yaml -o %t +RUN: FileCheck %s -check-prefix=WEAKSYMS < %t + +WEAKSYMS: - type: data +WEAKSYMS: alignment: 2^3 +WEAKSYMS: references: +WEAKSYMS: - kind: layout-after +WEAKSYMS: offset: 0 +WEAKSYMS: target: [[L001:[-a-zA-Z0-9_]+]] +WEAKSYMS: - name: myfn2 +WEAKSYMS: scope: global +WEAKSYMS: type: data +WEAKSYMS: merge: as-weak +WEAKSYMS: alignment: 2^3 +WEAKSYMS: references: +WEAKSYMS: - kind: layout-after +WEAKSYMS: offset: 0 +WEAKSYMS: target: [[L001]] +WEAKSYMS: - ref-name: [[L001]] +WEAKSYMS: scope: global +WEAKSYMS: type: data +WEAKSYMS: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +WEAKSYMS: alignment: 2^3 +WEAKSYMS: references: +WEAKSYMS: - kind: R_X86_64_64 +WEAKSYMS: offset: 0 +WEAKSYMS: target: test +WEAKSYMS: - kind: layout-after +WEAKSYMS: offset: 0 +WEAKSYMS: target: [[L003:[-a-zA-Z0-9_]+]] +WEAKSYMS: - name: myfn1 +WEAKSYMS: scope: global +WEAKSYMS: type: data +WEAKSYMS: merge: as-weak +WEAKSYMS: alignment: 2^3 +WEAKSYMS: references: +WEAKSYMS: - kind: layout-after +WEAKSYMS: offset: 0 +WEAKSYMS: target: [[L003]] +WEAKSYMS: - ref-name: [[L003]] +WEAKSYMS: scope: global +WEAKSYMS: type: data +WEAKSYMS: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +WEAKSYMS: alignment: 2^3 +WEAKSYMS: references: +WEAKSYMS: - kind: R_X86_64_64 +WEAKSYMS: offset: 0 +WEAKSYMS: target: test diff --git a/test/elf/X86_64/multi-weak-override.test b/test/elf/X86_64/multi-weak-override.test new file mode 100644 index 000000000000..f2d0e0c2f77b --- /dev/null +++ b/test/elf/X86_64/multi-weak-override.test @@ -0,0 +1,16 @@ +# Test for weak symbol getting overridden +RUN: lld -flavor gnu -target x86_64 %p/Inputs/multi-weak.o \ +RUN: %p/Inputs/multi-ovrd.o -o %t -e main --noinhibit-exec +RUN: llvm-nm -n %t | FileCheck -check-prefix=WEAKORDER %s +RUN: lld -flavor gnu -target x86_64 %p/Inputs/multi-weak.o \ +RUN: %p/Inputs/multi-ovrd.o --output-filetype=yaml -o %t2 --noinhibit-exec +RUN: FileCheck -check-prefix=WEAKATOMSORDER %s < %t2 + +WEAKORDER: {{[0-9a-f]+}} T f +WEAKORDER: {{[0-9a-f]+}} T g + +WEAKATOMSORDER: - ref-name: {{[A-Z0-9]+}} +WEAKATOMSORDER: - ref-name: {{[A-Z0-9]+}} +WEAKATOMSORDER: - name: f +WEAKATOMSORDER: - name: g + diff --git a/test/elf/X86_64/multi-weak-syms-order.test b/test/elf/X86_64/multi-weak-syms-order.test new file mode 100644 index 000000000000..2b414593fed4 --- /dev/null +++ b/test/elf/X86_64/multi-weak-syms-order.test @@ -0,0 +1,13 @@ +# Test for weak symbol getting overridden +RUN: lld -flavor gnu -target x86_64 %p/Inputs/multi-weak.o -o %t --noinhibit-exec +RUN: llvm-nm -n %t | FileCheck -check-prefix=WEAKORDER %s +RUN: lld -flavor gnu -target x86_64 %p/Inputs/multi-weak.o -o %t2 --output-filetype=yaml --noinhibit-exec +RUN: FileCheck -check-prefix=WEAKATOMSORDER %s < %t2 + +WEAKORDER: {{[0-9a-f]+}} T fn +WEAKORDER: {{[0-9a-f]+}} T f +WEAKORDER: {{[0-9a-f]+}} T g +WEAKORDER: {{[0-9a-f]+}} T main + +WEAKATOMSORDER: - name: f +WEAKATOMSORDER: - name: g diff --git a/test/elf/X86_64/nmagic.test b/test/elf/X86_64/nmagic.test new file mode 100644 index 000000000000..b313c1f051ba --- /dev/null +++ b/test/elf/X86_64/nmagic.test @@ -0,0 +1,91 @@ +# This tests verifies functionality of NMAGIC that we create only two segments, +# PT_LOAD, PT_TLS +# The data segment should be aligned to a page boundary +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/nmagic.o \ +RUN: --noinhibit-exec -o %t --nmagic -static +RUN: llvm-readobj -sections %t | FileCheck -check-prefix=NMAGICSECTIONS %s +RUN: llvm-readobj -program-headers %t | FileCheck -check-prefix=NMAGICPROGRAMHEADERS %s + +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Index: 0 +NMAGICSECTIONS: Name: (0) +NMAGICSECTIONS: Type: SHT_NULL (0x0) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .text +NMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .eh_frame +NMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .tdata +NMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .tbss +NMAGICSECTIONS: Type: SHT_NOBITS (0x8) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .got.plt +NMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .data +NMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .bss +NMAGICSECTIONS: Type: SHT_NOBITS (0x8) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .comment +NMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .note.GNU-stack +NMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .shstrtab +NMAGICSECTIONS: Type: SHT_STRTAB (0x3) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .symtab +NMAGICSECTIONS: Type: SHT_SYMTAB (0x2) +NMAGICSECTIONS: } +NMAGICSECTIONS: Section { +NMAGICSECTIONS: Name: .strtab +NMAGICSECTIONS: Type: SHT_STRTAB (0x3) +NMAGICSECTIONS: } + +NMAGICPROGRAMHEADERS: ProgramHeaders [ +NMAGICPROGRAMHEADERS: ProgramHeader { +NMAGICPROGRAMHEADERS: Type: PT_LOAD (0x1) +NMAGICPROGRAMHEADERS: Offset: 0x0 +NMAGICPROGRAMHEADERS: VirtualAddress: 0x400000 +NMAGICPROGRAMHEADERS: PhysicalAddress: 0x400000 +NMAGICPROGRAMHEADERS: FileSize: 4108 +NMAGICPROGRAMHEADERS: MemSize: 4108 +NMAGICPROGRAMHEADERS: Flags [ (0x7) +NMAGICPROGRAMHEADERS: PF_R (0x4) +NMAGICPROGRAMHEADERS: PF_W (0x2) +NMAGICPROGRAMHEADERS: PF_X (0x1) +NMAGICPROGRAMHEADERS: ] +NMAGICPROGRAMHEADERS: Alignment: 8 +NMAGICPROGRAMHEADERS: } +NMAGICPROGRAMHEADERS: ProgramHeader { +NMAGICPROGRAMHEADERS: Type: PT_TLS (0x7) +NMAGICPROGRAMHEADERS: Offset: 0x1000 +NMAGICPROGRAMHEADERS: VirtualAddress: 0x401000 +NMAGICPROGRAMHEADERS: PhysicalAddress: 0x401000 +NMAGICPROGRAMHEADERS: FileSize: 4 +NMAGICPROGRAMHEADERS: MemSize: 12 +NMAGICPROGRAMHEADERS: Flags [ (0x6) +NMAGICPROGRAMHEADERS: PF_R (0x4) +NMAGICPROGRAMHEADERS: PF_W (0x2) +NMAGICPROGRAMHEADERS: ] +NMAGICPROGRAMHEADERS: Alignment: 4 +NMAGICPROGRAMHEADERS: } +NMAGICPROGRAMHEADERS: ] diff --git a/test/elf/X86_64/noalignsegments.test b/test/elf/X86_64/noalignsegments.test new file mode 100644 index 000000000000..8432bda51f00 --- /dev/null +++ b/test/elf/X86_64/noalignsegments.test @@ -0,0 +1,95 @@ +# Checks that segments are aligned as per ELF spec than aligning each +# segment fileoffset / virtual address to a page. + +# Build executable +# RUN: yaml2obj -format=elf -docnum 1 %s -o %t.o +# RUN: lld -flavor gnu -target x86_64 %t.o -o %t.exe -static \ +# RUN: --no-align-segments --noinhibit-exec +# RUN: llvm-readobj -program-headers %t.exe | FileCheck %s +# +#CHECK: VirtualAddress: 0x400000 +#CHECK: PhysicalAddress: 0x400000 +#CHECK: VirtualAddress: 0x400178 +#CHECK: PhysicalAddress: 0x400178 + +# object +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E5B864000000C745FC000000005DC366666666662E0F1F840000000000554889E531C05DC3 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '64000000' + - Name: .rodata + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '64000000' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C070890010000180000001C000000000000001200000000410E108602430D060000001800000038000000000000000800000000410E108602430D06000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 + Addend: 0 + - Offset: 0x000000000000003C + Symbol: .text + Type: R_X86_64_PC32 + Addend: 32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: foo + Type: STT_FUNC + Section: .text + Value: 0x0000000000000020 + Size: 0x0000000000000008 + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x0000000000000012 + - Name: myval + Type: STT_OBJECT + Section: .bss + Size: 0x0000000000000004 + - Name: val + Type: STT_OBJECT + Section: .rodata + Size: 0x0000000000000004 +... diff --git a/test/elf/X86_64/note-sections-ro_plus_rw.test b/test/elf/X86_64/note-sections-ro_plus_rw.test new file mode 100644 index 000000000000..ddeeaa41a758 --- /dev/null +++ b/test/elf/X86_64/note-sections-ro_plus_rw.test @@ -0,0 +1,42 @@ +# This tests the functionality that lld is able to recreate the note sections +# if they appear in the input, it looks like we need to differentiate RO note +# sections from RW note sections, and each creating a segment of its own + +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/note_ro_rw.o \ +RUN: --noinhibit-exec -o %t -static +RUN: llvm-readobj -sections %t | FileCheck -check-prefix=NOTESECTIONS %s +RUN: llvm-readobj -program-headers %t | FileCheck -check-prefix=NOTESEGMENT %s + +NOTESECTIONS: Section { +NOTESECTIONS: Name: .note.ro (1) +NOTESECTIONS: Type: SHT_NOTE (0x7) +NOTESECTIONS: Flags [ (0x2) +NOTESECTIONS: SHF_ALLOC (0x2) +NOTESECTIONS: ] +NOTESECTIONS: AddressAlignment: 4 +NOTESECTIONS: } +NOTESECTIONS: Section { +NOTESECTIONS: Name: .note.rw (31) +NOTESECTIONS: Type: SHT_NOTE (0x7) +NOTESECTIONS: Flags [ (0x3) +NOTESECTIONS: SHF_ALLOC (0x2) +NOTESECTIONS: SHF_WRITE (0x1) +NOTESECTIONS: ] +NOTESECTIONS: Size: 28 +NOTESECTIONS: AddressAlignment: 4 +NOTESECTIONS: } +NOTESEGMENT: ProgramHeader { +NOTESEGMENT: Type: PT_NOTE (0x4) +NOTESEGMENT: Flags [ (0x4) +NOTESEGMENT: PF_R (0x4) +NOTESEGMENT: ] +NOTESEGMENT: Alignment: 4 +NOTESEGMENT: } +NOTESEGMENT: ProgramHeader { +NOTESEGMENT: Type: PT_NOTE (0x4) +NOTESEGMENT: Flags [ (0x6) +NOTESEGMENT: PF_R (0x4) +NOTESEGMENT: PF_W (0x2) +NOTESEGMENT: ] +NOTESEGMENT: Alignment: 4 +NOTESEGMENT: } diff --git a/test/elf/X86_64/note-sections.test b/test/elf/X86_64/note-sections.test new file mode 100644 index 000000000000..a49f95cf4a27 --- /dev/null +++ b/test/elf/X86_64/note-sections.test @@ -0,0 +1,23 @@ +# This tests the functionality that lld is able to recreate the note sections +# if they appear in the input + +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/note.o \ +RUN: --noinhibit-exec -o %t -static +RUN: llvm-readobj -sections %t | FileCheck -check-prefix=NOTESECTIONS %s +RUN: llvm-readobj -program-headers %t | FileCheck -check-prefix=NOTESEGMENT %s + + +NOTESECTIONS: Section { +NOTESECTIONS: Index: 1 +NOTESECTIONS: Name: .note.ident (1) +NOTESECTIONS: Type: SHT_NOTE (0x7) +NOTESECTIONS: Size: 28 +NOTESECTIONS: AddressAlignment: 4 +NOTESECTIONS: } + +NOTESEGMENT: ProgramHeader { +NOTESEGMENT: Type: PT_NOTE (0x4) +NOTESEGMENT: FileSize: 28 +NOTESEGMENT: MemSize: 28 +NOTESEGMENT: Alignment: 4 +NOTESEGMENT: } diff --git a/test/elf/X86_64/omagic.test b/test/elf/X86_64/omagic.test new file mode 100644 index 000000000000..437d2e2a9f98 --- /dev/null +++ b/test/elf/X86_64/omagic.test @@ -0,0 +1,237 @@ +# This tests verifies functionality of omagic that we create only two segments, +# PT_LOAD, PT_TLS +# The data segment should not be aligned to a page boundary +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/nmagic.o \ +RUN: --noinhibit-exec -o %t --omagic -static +RUN: llvm-readobj -sections %t | FileCheck -check-prefix=OMAGICSECTIONS %s +RUN: llvm-readobj -program-headers %t | FileCheck -check-prefix=OMAGICPROGRAMHEADERS %s + +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: (0) +OMAGICSECTIONS: Type: SHT_NULL (0x0) +OMAGICSECTIONS: Flags [ (0x0) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x0 +OMAGICSECTIONS: Offset: 0x0 +OMAGICSECTIONS: Size: 0 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 0 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .text +OMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +OMAGICSECTIONS: Flags [ (0x6) +OMAGICSECTIONS: SHF_ALLOC (0x2) +OMAGICSECTIONS: SHF_EXECINSTR (0x4) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x4000E8 +OMAGICSECTIONS: Offset: 0xE8 +OMAGICSECTIONS: Size: 11 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 4 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .eh_frame +OMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +OMAGICSECTIONS: Flags [ (0x2) +OMAGICSECTIONS: SHF_ALLOC (0x2) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x4000F8 +OMAGICSECTIONS: Offset: 0xF8 +OMAGICSECTIONS: Size: 56 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 8 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .eh_frame_hdr +OMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +OMAGICSECTIONS: Flags [ (0x2) +OMAGICSECTIONS: SHF_ALLOC (0x2) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x400130 +OMAGICSECTIONS: Offset: 0x130 +OMAGICSECTIONS: Size: 8 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 8 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .tdata +OMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +OMAGICSECTIONS: Flags [ (0x403) +OMAGICSECTIONS: SHF_ALLOC (0x2) +OMAGICSECTIONS: SHF_TLS (0x400) +OMAGICSECTIONS: SHF_WRITE (0x1) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x400138 +OMAGICSECTIONS: Offset: 0x138 +OMAGICSECTIONS: Size: 4 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 4 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .tbss +OMAGICSECTIONS: Type: SHT_NOBITS (0x8) +OMAGICSECTIONS: Flags [ (0x403) +OMAGICSECTIONS: SHF_ALLOC (0x2) +OMAGICSECTIONS: SHF_TLS (0x400) +OMAGICSECTIONS: SHF_WRITE (0x1) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x40013C +OMAGICSECTIONS: Offset: 0x13C +OMAGICSECTIONS: Size: 8 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 4 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .got.plt +OMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +OMAGICSECTIONS: Flags [ (0x3) +OMAGICSECTIONS: SHF_ALLOC (0x2) +OMAGICSECTIONS: SHF_WRITE (0x1) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x400140 +OMAGICSECTIONS: Offset: 0x140 +OMAGICSECTIONS: Size: 0 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 8 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .data +OMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +OMAGICSECTIONS: Flags [ (0x3) +OMAGICSECTIONS: SHF_ALLOC (0x2) +OMAGICSECTIONS: SHF_WRITE (0x1) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x400140 +OMAGICSECTIONS: Offset: 0x140 +OMAGICSECTIONS: Size: 4 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 4 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .bss +OMAGICSECTIONS: Type: SHT_NOBITS (0x8) +OMAGICSECTIONS: Flags [ (0x3) +OMAGICSECTIONS: SHF_ALLOC (0x2) +OMAGICSECTIONS: SHF_WRITE (0x1) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x400144 +OMAGICSECTIONS: Offset: 0x144 +OMAGICSECTIONS: Size: 0 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 4 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .comment +OMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +OMAGICSECTIONS: Flags [ (0x0) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x0 +OMAGICSECTIONS: Offset: 0x144 +OMAGICSECTIONS: Size: 43 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 1 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .note.GNU-stack +OMAGICSECTIONS: Type: SHT_PROGBITS (0x1) +OMAGICSECTIONS: Flags [ (0x0) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x0 +OMAGICSECTIONS: Offset: 0x16F +OMAGICSECTIONS: Size: 0 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 1 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .shstrtab +OMAGICSECTIONS: Type: SHT_STRTAB (0x3) +OMAGICSECTIONS: Flags [ (0x0) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x0 +OMAGICSECTIONS: Offset: 0x16F +OMAGICSECTIONS: Size: 115 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 1 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .symtab +OMAGICSECTIONS: Type: SHT_SYMTAB (0x2) +OMAGICSECTIONS: Flags [ (0x0) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x0 +OMAGICSECTIONS: Offset: 0x1E8 +OMAGICSECTIONS: Size: 504 +OMAGICSECTIONS: Link: 13 +OMAGICSECTIONS: Info: 2 +OMAGICSECTIONS: AddressAlignment: 8 +OMAGICSECTIONS: EntrySize: 24 +OMAGICSECTIONS: } +OMAGICSECTIONS: Section { +OMAGICSECTIONS: Name: .strtab +OMAGICSECTIONS: Type: SHT_STRTAB (0x3) +OMAGICSECTIONS: Flags [ (0x0) +OMAGICSECTIONS: ] +OMAGICSECTIONS: Address: 0x0 +OMAGICSECTIONS: Offset: 0x3E0 +OMAGICSECTIONS: Size: 231 +OMAGICSECTIONS: Link: 0 +OMAGICSECTIONS: Info: 0 +OMAGICSECTIONS: AddressAlignment: 1 +OMAGICSECTIONS: EntrySize: 0 +OMAGICSECTIONS: } +OMAGICSECTIONS: ] + +OMAGICPROGRAMHEADERS: ProgramHeaders [ +OMAGICPROGRAMHEADERS: ProgramHeader { +OMAGICPROGRAMHEADERS: Type: PT_LOAD (0x1) +OMAGICPROGRAMHEADERS: Offset: 0x0 +OMAGICPROGRAMHEADERS: VirtualAddress: 0x400000 +OMAGICPROGRAMHEADERS: PhysicalAddress: 0x400000 +OMAGICPROGRAMHEADERS: FileSize: 324 +OMAGICPROGRAMHEADERS: MemSize: 324 +OMAGICPROGRAMHEADERS: Flags [ (0x7) +OMAGICPROGRAMHEADERS: PF_R (0x4) +OMAGICPROGRAMHEADERS: PF_W (0x2) +OMAGICPROGRAMHEADERS: PF_X (0x1) +OMAGICPROGRAMHEADERS: ] +OMAGICPROGRAMHEADERS: Alignment: 8 +OMAGICPROGRAMHEADERS: } +OMAGICPROGRAMHEADERS: ProgramHeader { +OMAGICPROGRAMHEADERS: Type: PT_TLS (0x7) +OMAGICPROGRAMHEADERS: Offset: 0x138 +OMAGICPROGRAMHEADERS: VirtualAddress: 0x400138 +OMAGICPROGRAMHEADERS: PhysicalAddress: 0x400138 +OMAGICPROGRAMHEADERS: FileSize: 4 +OMAGICPROGRAMHEADERS: MemSize: 12 +OMAGICPROGRAMHEADERS: Flags [ (0x6) +OMAGICPROGRAMHEADERS: PF_R (0x4) +OMAGICPROGRAMHEADERS: PF_W (0x2) +OMAGICPROGRAMHEADERS: ] +OMAGICPROGRAMHEADERS: Alignment: 4 +OMAGICPROGRAMHEADERS: } +OMAGICPROGRAMHEADERS: ] diff --git a/test/elf/X86_64/outputsegments.test b/test/elf/X86_64/outputsegments.test new file mode 100644 index 000000000000..ab6ba8deb47d --- /dev/null +++ b/test/elf/X86_64/outputsegments.test @@ -0,0 +1,189 @@ +# Tests that lld does not create separate segment if the input sections are part +# of the same output section + +# Build executable +# RUN: yaml2obj -format=elf -docnum 1 %s -o %t.o +# RUN: lld -flavor gnu -target x86_64 %t.o -o %t1.exe -static \ +# RUN: --no-align-segments --noinhibit-exec +# RUN: lld -flavor gnu -target x86_64 %t.o -o %t2.exe -static \ +# RUN: --noinhibit-exec +# RUN: llvm-readobj -program-headers %t1.exe | FileCheck %s -check-prefix=SEGMENTS +# RUN: llvm-readobj -program-headers %t2.exe | FileCheck %s -check-prefix=SEGMENTS +# +#SEGMENTS: VirtualAddress: 0x400000 +#SEGMENTS: PhysicalAddress: 0x400000 +#SEGMENTS: FileSize: 288 +#SEGMENTS: MemSize: 288 +#SEGMENTS: VirtualAddress: 0x404000 +#SEGMENTS: PhysicalAddress: 0x404000 +#SEGMENTS: FileSize: 16608 +#SEGMENTS: MemSize: 16608 +#SEGMENTS: Alignment: 16384 +# +# object +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .text.foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000002000 + Content: 554889E54883EC1048BF0000000000000000B000E800000000B9000000008945FC89C84883C4105DC3 + - Name: .rela.text.foo + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text.foo + Relocations: + - Offset: 0x000000000000000A + Symbol: .rodata.str1.1 + Type: R_X86_64_64 + Addend: 0 + - Offset: 0x0000000000000015 + Symbol: printf + Type: R_X86_64_PC32 + Addend: -4 + - Name: .text.bar + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000004000 + Content: 554889E54883EC1048BF0000000000000000B000E800000000B9000000008945FC89C84883C4105DC3 + - Name: .rela.text.bar + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text.bar + Relocations: + - Offset: 0x000000000000000A + Symbol: .rodata.str1.1 + Type: R_X86_64_64 + Addend: 7 + - Offset: 0x0000000000000015 + Symbol: printf + Type: R_X86_64_PC32 + Addend: -4 + - Name: .text.main + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E54883EC10C745FC00000000E8000000008945F8E8000000008B4DF801C189C84883C4105DC3 + - Name: .rela.text.main + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text.main + Relocations: + - Offset: 0x0000000000000010 + Symbol: foo + Type: R_X86_64_PC32 + Addend: -4 + - Offset: 0x0000000000000018 + Symbol: bar + Type: R_X86_64_PC32 + Addend: -4 + - Name: .rodata.str1.1 + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 48656C6C6F0A00576F726C640A00 + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 005562756E747520636C616E672076657273696F6E20332E352E302D73766E3231373330342D317E6578703120286272616E636865732F72656C656173655F33352920286261736564206F6E204C4C564D20332E352E302900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C070890010000180000001C000000000000002900000000410E108602430D060000001800000038000000000000002900000000410E108602430D060000001C00000054000000000000002900000000410E108602430D0600000000000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text.foo + Type: R_X86_64_PC32 + Addend: 0 + - Offset: 0x000000000000003C + Symbol: .text.bar + Type: R_X86_64_PC32 + Addend: 0 + - Offset: 0x0000000000000058 + Symbol: .text.main + Type: R_X86_64_PC32 + Addend: 0 +Symbols: + Local: + - Name: 1.c + Type: STT_FILE + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .text.foo + Type: STT_SECTION + Section: .text.foo + - Name: .text.bar + Type: STT_SECTION + Section: .text.bar + - Name: .text.main + Type: STT_SECTION + Section: .text.main + - Name: .rodata.str1.1 + Type: STT_SECTION + Section: .rodata.str1.1 + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: bar + Type: STT_FUNC + Section: .text.bar + Size: 0x0000000000000029 + - Name: foo + Type: STT_FUNC + Section: .text.foo + Size: 0x0000000000000029 + - Name: main + Type: STT_FUNC + Section: .text.main + Size: 0x0000000000000029 + - Name: printf +... diff --git a/test/elf/X86_64/reloc_r_x86_64_16.test b/test/elf/X86_64/reloc_r_x86_64_16.test new file mode 100644 index 000000000000..7cca839eb623 --- /dev/null +++ b/test/elf/X86_64/reloc_r_x86_64_16.test @@ -0,0 +1,60 @@ +# Tests that lld can handle relocations of type R_X86_64_16 +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t1.o +#RUN: lld -flavor gnu -target x86_64 %t1.o --noinhibit-exec -o %t2.out -static +#RUN: llvm-objdump -s %t2.out | FileCheck %s +#CHECK: Contents of section .data: +#CHECK: 401000 0210 +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: '0000' + - Name: .rela.data + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .data + Relocations: + - Offset: 0x0000000000000000 + Symbol: foo + Type: R_X86_64_16 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: bar + Type: STT_OBJECT + Section: .data + Size: 0x0000000000000008 + - Name: foo + Type: STT_OBJECT + Section: .data + Value: 0x0000000000000002 + Size: 0x0000000000000002 +... diff --git a/test/elf/X86_64/reloc_r_x86_64_pc16.test b/test/elf/X86_64/reloc_r_x86_64_pc16.test new file mode 100644 index 000000000000..6e43e5fade61 --- /dev/null +++ b/test/elf/X86_64/reloc_r_x86_64_pc16.test @@ -0,0 +1,61 @@ +# Tests that lld can handle relocations of type R_X86_64_PC16 +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t1.o +#RUN: lld -flavor gnu -target x86_64 %t1.o --noinhibit-exec -o %t2.out -static +#RUN: llvm-objdump -s %t2.out | FileCheck %s +#CHECK: Contents of section .data: +#CHECK: 401000 0700 +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: '0000' + - Name: .rela.data + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .data + Relocations: + - Offset: 0x0000000000000000 + Symbol: foo + Type: R_X86_64_PC16 + Addend: 5 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: bar + Type: STT_OBJECT + Section: .data + Size: 0x0000000000000008 + - Name: foo + Type: STT_OBJECT + Section: .data + Value: 0x0000000000000002 + Size: 0x0000000000000002 +... diff --git a/test/elf/X86_64/reloc_r_x86_64_pc64.test b/test/elf/X86_64/reloc_r_x86_64_pc64.test new file mode 100644 index 000000000000..75744390be91 --- /dev/null +++ b/test/elf/X86_64/reloc_r_x86_64_pc64.test @@ -0,0 +1,61 @@ +# Tests that lld can handle relocations of type R_X86_64_PC64 +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t1.o +#RUN: lld -flavor gnu -target x86_64 %t1.o --noinhibit-exec -o %t2.out -static +#RUN: llvm-objdump -s %t2.out | FileCheck %s +#CHECK: Contents of section .data: +#CHECK: 401000 0a00 +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: '0000' + - Name: .rela.data + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .data + Relocations: + - Offset: 0x0000000000000000 + Symbol: foo + Type: R_X86_64_PC64 + Addend: 8 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: bar + Type: STT_OBJECT + Section: .data + Size: 0x0000000000000008 + - Name: foo + Type: STT_OBJECT + Section: .data + Value: 0x0000000000000002 + Size: 0x0000000000000002 +... diff --git a/test/elf/X86_64/rodata.test b/test/elf/X86_64/rodata.test new file mode 100644 index 000000000000..61af99f65cfc --- /dev/null +++ b/test/elf/X86_64/rodata.test @@ -0,0 +1,9 @@ +# This tests that the ordinals for all merge atoms and defined atoms have been +# set properly + +RUN: lld -flavor gnu -target x86_64 %p/Inputs/rodata.o --noinhibit-exec \ +RUN: --merge-strings -static -o %t1 +RUN: llvm-nm -n %t1 | FileCheck %s + +CHECK: {{[0-9a-f]+}} R _nl_default_default_domain +CHECK: {{[0-9a-f]+}} R _nl_default_default_dirname diff --git a/test/elf/X86_64/sectionchoice.test b/test/elf/X86_64/sectionchoice.test new file mode 100644 index 000000000000..4034d8b1111a --- /dev/null +++ b/test/elf/X86_64/sectionchoice.test @@ -0,0 +1,7 @@ +# This tests that we are able to properly set the sectionChoice for DefinedAtoms +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/zerosizedsection.o \ +RUN: --noinhibit-exec -o %t --output-filetype=yaml +RUN: FileCheck %s < %t + +CHECK-NOT: section-choice: sectionCustomRequired + diff --git a/test/elf/X86_64/sectionmap.test b/test/elf/X86_64/sectionmap.test new file mode 100644 index 000000000000..a38f23e32b95 --- /dev/null +++ b/test/elf/X86_64/sectionmap.test @@ -0,0 +1,22 @@ +# This tests that we are able to merge the section .gcc_except_table, +# .data.rel.local, .data.rel.ro, any other sections that belong to .data +# into appropriate output sections +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/sectionmap.o \ +RUN: --noinhibit-exec -o %t +RUN: llvm-readobj -sections %t | FileCheck %s -check-prefix=VERIFYSECTIONHEADERS + +VERIFYSECTIONHEADERS: Section { +VERIFYSECTIONHEADERS: Name: .data +VERIFYSECTIONHEADERS: } +VERIFYSECTIONHEADERS: Section { +VERIFYSECTIONHEADERS: Name: .gcc_except_table +VERIFYSECTIONHEADERS: } +VERIFYSECTIONHEADERS: Section { +VERIFYSECTIONHEADERS: Name: .data.rel.local +VERIFYSECTIONHEADERS: } +VERIFYSECTIONHEADERS: Section { +VERIFYSECTIONHEADERS: Name: .data.rel.ro +VERIFYSECTIONHEADERS: } +VERIFYSECTIONHEADERS: Section { +VERIFYSECTIONHEADERS: Name: .bss +VERIFYSECTIONHEADERS: } diff --git a/test/elf/X86_64/startGroupEndGroup.test b/test/elf/X86_64/startGroupEndGroup.test new file mode 100644 index 000000000000..ce1897683b34 --- /dev/null +++ b/test/elf/X86_64/startGroupEndGroup.test @@ -0,0 +1,48 @@ +# This tests functionality of --start-group, --end-group + +# This link should fail with unresolve symbol +RUN: not lld -flavor gnu -target x86_64 %p/Inputs/group/1.o \ +RUN: %p/Inputs/group/libfn.a %p/Inputs/group/libfn1.a -o x 2> %t.err + +# Test group +RUN: lld -flavor gnu -target x86_64 %p/Inputs/group/1.o --start-group \ +RUN: %p/Inputs/group/libfn.a %p/Inputs/group/libfn1.a --end-group -o %t1 + +# Mix object files in group +RUN: lld -flavor gnu -target x86_64 %p/Inputs/group/1.o --start-group \ +RUN: %p/Inputs/group/fn.o %p/Inputs/group/fn2.o \ +RUN: %p/Inputs/group/fn1.o --end-group -o %t2 + +# Mix Whole archive input, the group should not iterate the file libfn.a +RUN: lld -flavor gnu -target x86_64 %p/Inputs/group/1.o --start-group \ +RUN: --whole-archive %p/Inputs/group/libfn.a --no-whole-archive \ +RUN: %p/Inputs/group/libfn1.a --end-group -o %t3 + +# Defined symbols in a shared library. +RUN: lld -flavor gnu -target x86_64 %p/Inputs/group/1.o --start-group \ +RUN: %p/Inputs/group/libfn2.so %p/Inputs/group/fn1.o %p/Inputs/group/fn.o \ +RUN: --end-group -o %t4 + +# Test alias options too, as they are more widely used +# Test group +RUN: lld -flavor gnu -target x86_64 %p/Inputs/group/1.o '-(' \ +RUN: %p/Inputs/group/libfn.a %p/Inputs/group/libfn1.a '-)' -o %t1.alias + +# Mix object files in group +RUN: lld -flavor gnu -target x86_64 %p/Inputs/group/1.o '-(' \ +RUN: %p/Inputs/group/fn.o %p/Inputs/group/fn2.o \ +RUN: %p/Inputs/group/fn1.o '-)' -o %t2.alias + +# Mix Whole archive input, the group should not iterate the file libfn.a +RUN: lld -flavor gnu -target x86_64 %p/Inputs/group/1.o '-(' \ +RUN: --whole-archive %p/Inputs/group/libfn.a --no-whole-archive \ +RUN: %p/Inputs/group/libfn1.a '-)' -o %t3.alias + +RUN: llvm-nm %t1 | FileCheck -check-prefix=RESOLVEDEXTERNAL %s +RUN: llvm-nm %t2 | FileCheck -check-prefix=RESOLVEDEXTERNAL %s +RUN: llvm-nm %t3 | FileCheck -check-prefix=RESOLVEDEXTERNAL %s +RUN: llvm-nm %t1.alias | FileCheck -check-prefix=RESOLVEDEXTERNAL %s +RUN: llvm-nm %t2.alias | FileCheck -check-prefix=RESOLVEDEXTERNAL %s +RUN: llvm-nm %t3.alias | FileCheck -check-prefix=RESOLVEDEXTERNAL %s + +RESOLVEDEXTERNAL: {{[0-9a-z]+}} T fn2 diff --git a/test/elf/X86_64/startGroupEndGroupWithDynlib.test b/test/elf/X86_64/startGroupEndGroupWithDynlib.test new file mode 100644 index 000000000000..3e40997db384 --- /dev/null +++ b/test/elf/X86_64/startGroupEndGroupWithDynlib.test @@ -0,0 +1,10 @@ +# This tests functionality of --start-group, --end-group with a dynamic library + +# Mix dynamic libraries/object files in group +RUN: lld -flavor gnu -target x86_64 %p/Inputs/group/1.o --start-group \ +RUN: %p/Inputs/group/libfn.so %p/Inputs/group/fn2.o \ +RUN: %p/Inputs/group/fn1.o --end-group -o %t1 + +RUN: llvm-nm %t1 | FileCheck -check-prefix=RESOLVEDEXTERNAL %s + +RESOLVEDEXTERNAL: {{[0-9a-z]+}} T fn2 diff --git a/test/elf/X86_64/staticlib-search.test b/test/elf/X86_64/staticlib-search.test new file mode 100644 index 000000000000..9c512571932d --- /dev/null +++ b/test/elf/X86_64/staticlib-search.test @@ -0,0 +1,6 @@ +# This tests the functionality for finding the static library libfn.a for ELF +RUN: lld -flavor gnu -target x86_64 %p/Inputs/main.o -L%p/Inputs/ -lfn -o %t \ +RUN: --noinhibit-exec -static -t 2> %t1 +RUN: FileCheck %s < %t1 + +CHECK: {{[\/0-9A-Za-z_]+}}libfn.a diff --git a/test/elf/X86_64/undef.test b/test/elf/X86_64/undef.test new file mode 100644 index 000000000000..8f0039a14693 --- /dev/null +++ b/test/elf/X86_64/undef.test @@ -0,0 +1,18 @@ +# This tests the functionality that an undefined symbol thats defined in the +# commmand line pulls in the required object file from the archive library +# which is usually the usecase for it +RUN: lld -flavor gnu -target x86_64 -u fn %p/Inputs/libfn.a -o %t --noinhibit-exec +RUN: llvm-readobj -symbols %t | FileCheck -check-prefix=SYMFROMARCHIVE %s +RUN: lld -flavor gnu -target x86_64 %p/Inputs/libfn.a -o %t --noinhibit-exec +RUN: llvm-readobj -symbols %t | FileCheck %s + +SYMFROMARCHIVE: Symbol { +SYMFROMARCHIVE: Name: fn ({{[0-9]+}} +SYMFROMARCHIVE: Size: 11 +SYMFROMARCHIVE: Binding: Global (0x1) +SYMFROMARCHIVE: Type: Function (0x2) +SYMFROMARCHIVE: Other: 0 +SYMFROMARCHIVE: Section: .text +SYMFROMARCHIVE: } + +CHECK-NOT: Name: fn diff --git a/test/elf/X86_64/underscore-end.test b/test/elf/X86_64/underscore-end.test new file mode 100644 index 000000000000..337aa197f812 --- /dev/null +++ b/test/elf/X86_64/underscore-end.test @@ -0,0 +1,81 @@ +# This tests verifies that the value of _end symbol is point to the right value +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/nmagic.o \ +RUN: --noinhibit-exec -o %t --nmagic +RUN: llvm-readobj -symbols %t | FileCheck -check-prefix=NMAGICABSSYMBOLS %s +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/nmagic.o \ +RUN: --noinhibit-exec -o %t --omagic +RUN: llvm-readobj -symbols %t | FileCheck -check-prefix=OMAGICABSSYMBOLS %s + +NMAGICABSSYMBOLS: Symbol { +NMAGICABSSYMBOLS: Name: __bss_start ({{[0-9]+}} +NMAGICABSSYMBOLS: Value: 0x40100C +NMAGICABSSYMBOLS: Size: 0 +NMAGICABSSYMBOLS: Binding: Global (0x1) +NMAGICABSSYMBOLS: Type: Object (0x1) +NMAGICABSSYMBOLS: Other: 0 +NMAGICABSSYMBOLS: Section: Absolute (0xFFF1) +NMAGICABSSYMBOLS: } +NMAGICABSSYMBOLS: Symbol { +NMAGICABSSYMBOLS: Name: __bss_end ({{[0-9]+}} +NMAGICABSSYMBOLS: Value: 0x40100C +NMAGICABSSYMBOLS: Size: 0 +NMAGICABSSYMBOLS: Binding: Global (0x1) +NMAGICABSSYMBOLS: Type: Object (0x1) +NMAGICABSSYMBOLS: Other: 0 +NMAGICABSSYMBOLS: Section: Absolute (0xFFF1) +NMAGICABSSYMBOLS: } +NMAGICABSSYMBOLS: Symbol { +NMAGICABSSYMBOLS: Name: _end ({{[0-9]+}} +NMAGICABSSYMBOLS: Value: 0x40100C +NMAGICABSSYMBOLS: Size: 0 +NMAGICABSSYMBOLS: Binding: Global (0x1) +NMAGICABSSYMBOLS: Type: Object (0x1) +NMAGICABSSYMBOLS: Other: 0 +NMAGICABSSYMBOLS: Section: Absolute (0xFFF1) +NMAGICABSSYMBOLS: } +NMAGICABSSYMBOLS: Symbol { +NMAGICABSSYMBOLS: Name: end ({{[0-9]+}} +NMAGICABSSYMBOLS: Value: 0x40100C +NMAGICABSSYMBOLS: Size: 0 +NMAGICABSSYMBOLS: Binding: Global (0x1) +NMAGICABSSYMBOLS: Type: Object (0x1) +NMAGICABSSYMBOLS: Other: 0 +NMAGICABSSYMBOLS: Section: Absolute (0xFFF1) +NMAGICABSSYMBOLS: } + +OMAGICABSSYMBOLS: Symbol { +OMAGICABSSYMBOLS: Name: __bss_start ({{[0-9]+}}) +OMAGICABSSYMBOLS: Value: 0x400144 +OMAGICABSSYMBOLS: Size: 0 +OMAGICABSSYMBOLS: Binding: Global (0x1) +OMAGICABSSYMBOLS: Type: Object (0x1) +OMAGICABSSYMBOLS: Other: 0 +OMAGICABSSYMBOLS: Section: Absolute (0xFFF1) +OMAGICABSSYMBOLS: } +OMAGICABSSYMBOLS: Symbol { +OMAGICABSSYMBOLS: Name: __bss_end ({{[0-9]+}} +OMAGICABSSYMBOLS: Value: 0x400144 +OMAGICABSSYMBOLS: Size: 0 +OMAGICABSSYMBOLS: Binding: Global (0x1) +OMAGICABSSYMBOLS: Type: Object (0x1) +OMAGICABSSYMBOLS: Other: 0 +OMAGICABSSYMBOLS: Section: Absolute (0xFFF1) +OMAGICABSSYMBOLS: } +OMAGICABSSYMBOLS: Symbol { +OMAGICABSSYMBOLS: Name: _end ({{[0-9]+}} +OMAGICABSSYMBOLS: Value: 0x400144 +OMAGICABSSYMBOLS: Size: 0 +OMAGICABSSYMBOLS: Binding: Global (0x1) +OMAGICABSSYMBOLS: Type: Object (0x1) +OMAGICABSSYMBOLS: Other: 0 +OMAGICABSSYMBOLS: Section: Absolute (0xFFF1) +OMAGICABSSYMBOLS: } +OMAGICABSSYMBOLS: Symbol { +OMAGICABSSYMBOLS: Name: end ({{[0-9]+}} +OMAGICABSSYMBOLS: Value: 0x400144 +OMAGICABSSYMBOLS: Size: 0 +OMAGICABSSYMBOLS: Binding: Global (0x1) +OMAGICABSSYMBOLS: Type: Object (0x1) +OMAGICABSSYMBOLS: Other: 0 +OMAGICABSSYMBOLS: Section: Absolute (0xFFF1) +OMAGICABSSYMBOLS: } diff --git a/test/elf/X86_64/weak-override.test b/test/elf/X86_64/weak-override.test new file mode 100644 index 000000000000..b68b449a6649 --- /dev/null +++ b/test/elf/X86_64/weak-override.test @@ -0,0 +1,45 @@ +# Test for weak symbol getting overridden +RUN: lld -flavor gnu -target x86_64 %p/Inputs/weak.o %p/Inputs/ovrd.o \ +RUN: -o %t --noinhibit-exec +RUN: llvm-nm %t | FileCheck -check-prefix=WEAKORDER %s +RUN: lld -flavor gnu -target x86_64 %p/Inputs/weak.o \ +RUN: %p/Inputs/ovrd.o -o %t2 --output-filetype=yaml --noinhibit-exec +RUN: FileCheck -check-prefix=WEAKATOMSORDER %s < %t2 + +WEAKORDER: {{[0-9a-c]+}} T f + +WEAKATOMSORDER: references: +WEAKATOMSORDER: - kind: layout-after +WEAKATOMSORDER: offset: 0 +WEAKATOMSORDER: target: fn +WEAKATOMSORDER: - name: fn +WEAKATOMSORDER: references: +WEAKATOMSORDER: - kind: layout-after +WEAKATOMSORDER: offset: 0 +WEAKATOMSORDER: target: [[CONSTSTRA:[-a-zA-Z0-9_]+]] +WEAKATOMSORDER: - ref-name: [[CONSTSTRA]] +WEAKATOMSORDER: scope: global +WEAKATOMSORDER: content: [ 55, 48, 89, E5, BF, 00, 00, 00, 00, E8, 00, 00, +WEAKATOMSORDER: 00, 00, 5D, C3 ] +WEAKATOMSORDER: references: +WEAKATOMSORDER: - kind: layout-after +WEAKATOMSORDER: offset: 0 +WEAKATOMSORDER: target: main +WEAKATOMSORDER: - name: main +WEAKATOMSORDER: scope: global +WEAKATOMSORDER: content: [ 55, 48, 89, E5, B8, 00, 00, 00, 00, E8, 00, 00, +WEAKATOMSORDER: 00, 00, B8, 00, 00, 00, 00, 5D, C3 ] +WEAKATOMSORDER: references: +WEAKATOMSORDER: - kind: R_X86_64_PC32 +WEAKATOMSORDER: offset: 10 +WEAKATOMSORDER: target: f +WEAKATOMSORDER: addend: -4 +WEAKATOMSORDER: - ref-name: {{[0-9A-Z]+}} +WEAKATOMSORDER: references: +WEAKATOMSORDER: - kind: layout-after +WEAKATOMSORDER: offset: 0 +WEAKATOMSORDER: target: f +WEAKATOMSORDER: - name: f +WEAKATOMSORDER: scope: global +WEAKATOMSORDER: content: [ 55, 48, 89, E5, BF, 00, 00, 00, 00, E8, 00, 00, +WEAKATOMSORDER: 00, 00, 5D, C3 ] diff --git a/test/elf/X86_64/weak-zero-sized.test b/test/elf/X86_64/weak-zero-sized.test new file mode 100644 index 000000000000..76e051064b9d --- /dev/null +++ b/test/elf/X86_64/weak-zero-sized.test @@ -0,0 +1,26 @@ +# Test for zero sized weak atoms, there is only a single weak atom +RUN: lld -flavor gnu -target x86_64 %p/Inputs/weak-zero-sized.o -o %t \ +RUN: --noinhibit-exec +RUN: llvm-nm %t | FileCheck -check-prefix=WEAKORDER %s +RUN: lld -flavor gnu -target x86_64 %p/Inputs/weak-zero-sized.o \ +RUN: --output-filetype=yaml -o %t2 --noinhibit-exec +RUN: FileCheck -check-prefix=WEAKATOMSORDER %s < %t2 + +WEAKORDER: 004001a4 T _start + +WEAKATOMSORDER: alignment: 2^2 +WEAKATOMSORDER: - kind: layout-after +WEAKATOMSORDER: offset: 0 +WEAKATOMSORDER: target: [[TARGETC:[-a-zA-Z0-9_]+]] +WEAKATOMSORDER: - name: [[TARGETA:[-a-zA-Z0-9_]+]] +WEAKATOMSORDER: scope: global +WEAKATOMSORDER: merge: as-weak +WEAKATOMSORDER: alignment: 2^2 +WEAKATOMSORDER: references: +WEAKATOMSORDER: - kind: layout-after +WEAKATOMSORDER: offset: 0 +WEAKATOMSORDER: target: [[TARGETC]] +WEAKATOMSORDER: - ref-name: [[TARGETC]] +WEAKATOMSORDER: scope: global +WEAKATOMSORDER: content: [ C3 ] +WEAKATOMSORDER: alignment: 2^2 diff --git a/test/elf/X86_64/weaksym.test b/test/elf/X86_64/weaksym.test new file mode 100644 index 000000000000..d44ca8a36968 --- /dev/null +++ b/test/elf/X86_64/weaksym.test @@ -0,0 +1,78 @@ +# Tests that an executable with a weak undefine will put this symbol in the +# dynamic symbol table if the executable has a dynamic relocation against this +# symbol. + +#RUN: yaml2obj --format elf %s -o %t.o +#RUN: lld -flavor gnu -target x86_64 -e main %t.o -o %t1 +#RUN: llvm-readobj -dt %t1 | FileCheck -check-prefix CHECKSYMS %s + +#CHECKSYMS: Name: x@ +#CHECKSYMS-NEXT: Value: 0x0 +#CHECKSYMS-NEXT: Size: 0 +#CHECKSYMS-NEXT: Binding: Weak (0x2) +#CHECKSYMS-NEXT: Type: None (0x0) +#CHECKSYMS-NEXT: Other: 0 +#CHECKSYMS-NEXT: Section: Undefined (0x0) + +# The object file above corresponds to the following C program compiled with +# -fPIC: +# extern int *x __attribute__((weak)); +# +# int main() { +# if (x) +# return 1; +# return 0; +# } + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E5488B0500000000C745FC00000000488138000000000F840C000000C745FC01000000E907000000C745FC000000008B45FC5DC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000007 + Symbol: x + Type: R_X86_64_GOTPCREL + Addend: -4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x0000000000000037 + - Name: _GLOBAL_OFFSET_TABLE_ + Weak: + - Name: x diff --git a/test/elf/X86_64/yamlinput.test b/test/elf/X86_64/yamlinput.test new file mode 100644 index 000000000000..6e529b41b7a6 --- /dev/null +++ b/test/elf/X86_64/yamlinput.test @@ -0,0 +1,166 @@ +# This tests the functionality that lld is able to read +# an input YAML from a previous link + +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/initfini.o \ +RUN: --noinhibit-exec --output-filetype=yaml -o %t.objtxt +RUN: lld -flavor gnu -target x86_64-linux %t.objtxt \ +RUN: --noinhibit-exec -o %t1 +RUN: llvm-readobj -sections %t1 | FileCheck %s -check-prefix=SECTIONS + +SECTIONS: Section { +SECTIONS: Index: 0 +SECTIONS: Name: (0) +SECTIONS: Type: SHT_NULL (0x0) +SECTIONS: Flags [ (0x0) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 1 +SECTIONS: Name: .interp +SECTIONS: Type: SHT_PROGBITS (0x1) +SECTIONS: Flags [ (0x2) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 2 +SECTIONS: Name: .hash +SECTIONS: Type: SHT_HASH (0x5) +SECTIONS: Flags [ (0x2) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 3 +SECTIONS: Name: .dynsym +SECTIONS: Type: SHT_DYNSYM (0xB) +SECTIONS: Flags [ (0x2) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 4 +SECTIONS: Name: .dynstr +SECTIONS: Type: SHT_STRTAB (0x3) +SECTIONS: Flags [ (0x2) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 5 +SECTIONS: Name: .text +SECTIONS: Type: SHT_PROGBITS (0x1) +SECTIONS: Flags [ (0x6) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: SHF_EXECINSTR (0x4) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 6 +SECTIONS: Name: .rodata +SECTIONS: Type: SHT_PROGBITS (0x1) +SECTIONS: Flags [ (0x2) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 7 +SECTIONS: Name: .eh_frame +SECTIONS: Type: SHT_PROGBITS (0x1) +SECTIONS: Flags [ (0x2) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 8 +SECTIONS: Name: .eh_frame_hdr +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 9 +SECTIONS: Name: .init_array +SECTIONS: Type: SHT_PROGBITS (0x1) +SECTIONS: Flags [ (0x3) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: SHF_WRITE (0x1) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 10 +SECTIONS: Name: .fini_array +SECTIONS: Type: SHT_PROGBITS (0x1) +SECTIONS: Flags [ (0x3) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: SHF_WRITE (0x1) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 11 +SECTIONS: Name: .dynamic +SECTIONS: Type: SHT_DYNAMIC (0x6) +SECTIONS: Flags [ (0x3) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: SHF_WRITE (0x1) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 12 +SECTIONS: Name: .got.plt +SECTIONS: Type: SHT_PROGBITS (0x1) +SECTIONS: Flags [ (0x3) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: SHF_WRITE (0x1) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 13 +SECTIONS: Name: .data +SECTIONS: Type: SHT_PROGBITS (0x1) +SECTIONS: Flags [ (0x3) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: SHF_WRITE (0x1) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 14 +SECTIONS: Name: .bss +SECTIONS: Type: SHT_NOBITS (0x8) +SECTIONS: Flags [ (0x3) +SECTIONS: SHF_ALLOC (0x2) +SECTIONS: SHF_WRITE (0x1) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 15 +SECTIONS: Name: .comment +SECTIONS: Type: SHT_PROGBITS (0x1) +SECTIONS: Flags [ (0x0) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 16 +SECTIONS: Name: .note.GNU-stack +SECTIONS: Type: SHT_PROGBITS (0x1) +SECTIONS: Flags [ (0x0) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 17 +SECTIONS: Name: .shstrtab +SECTIONS: Type: SHT_STRTAB (0x3) +SECTIONS: Flags [ (0x0) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 18 +SECTIONS: Name: .symtab +SECTIONS: Type: SHT_SYMTAB (0x2) +SECTIONS: Flags [ (0x0) +SECTIONS: ] +SECTIONS: } +SECTIONS: Section { +SECTIONS: Index: 19 +SECTIONS: Name: .strtab +SECTIONS: Type: SHT_STRTAB (0x3) +SECTIONS: Flags [ (0x0) +SECTIONS: ] +SECTIONS: } diff --git a/test/elf/abs-dup.objtxt b/test/elf/abs-dup.objtxt new file mode 100644 index 000000000000..7340a29b0f00 --- /dev/null +++ b/test/elf/abs-dup.objtxt @@ -0,0 +1,19 @@ +# Tests handling an absolute symbol with no name +# RUN: lld -flavor gnu -target x86_64 -r %s \ +# RUN: --output-filetype=yaml | FileCheck %s + +absolute-atoms: + - name: abs + scope: static + value: 0x10 + - name: '' + scope: static + value: 0x15 + +# CHECK: absolute-atoms: +# CHECK: - name: abs +# CHECK: scope: static +# CHECK: value: 0x0000000000000010 +# CHECK: - name: '' +# CHECK: scope: static +# CHECK: value: 0x0000000000000015 diff --git a/test/elf/abs.test b/test/elf/abs.test new file mode 100644 index 000000000000..bad74f10d194 --- /dev/null +++ b/test/elf/abs.test @@ -0,0 +1,19 @@ +# +# Source File: +# .local absGlobalSymbol +# .set absLocalSymbol,0xC0000 +# .type absLocalSymbol, @object +# .globl absGlobalSymbol +# .set absGlobalSymbol,0xD0000 +# .type absGlobalSymbol, @object + +# built using: "gcc -m32" +# +RUN: lld -flavor gnu -target i386 --output-filetype=yaml -r %p/Inputs/abs-test.i386 | FileCheck -check-prefix=YAML %s + +YAML: absolute-atoms: +YAML: - name: absLocalSymbol +YAML: value: {{0x[0]+C0000}} +YAML: - name: absGlobalSymbol +YAML: scope: global +YAML: value: {{0x[0]+D0000}} diff --git a/test/elf/allowduplicates.objtxt b/test/elf/allowduplicates.objtxt new file mode 100644 index 000000000000..dbad3bd312ed --- /dev/null +++ b/test/elf/allowduplicates.objtxt @@ -0,0 +1,51 @@ +# RUN: lld -flavor gnu -target x86_64 --allow-multiple-definition %s \ +# RUN: --output-filetype=yaml --noinhibit-exec | FileCheck %s +# +# RUN: not lld -flavor gnu -target x86_64 %s --output-filetype=yaml \ +# RUN: --noinhibit-exec 2>&1 | FileCheck -check-prefix=ERROR %s +# +# RUN: lld -flavor gnu -target x86_64 -z muldefs %s \ +# RUN: --noinhibit-exec --output-filetype=yaml | FileCheck %s + +--- +defined-atoms: + - name: .text + alignment: 2^4 + section-choice: custom-required + section-name: .text + - name: main + scope: global + content: [ B8, 00, 00, 00, 00, C7, 44, 24, FC, 00, 00, 00, + 00, C3 ] + alignment: 2^4 + section-choice: custom-required + section-name: .text +--- +defined-atoms: + - name: .text + alignment: 2^4 + section-choice: custom-required + section-name: .text + - name: main + scope: global + content: [ B8, 00, 00, 00, 00, C7, 44, 24, FC, 00, 00, 00, + 00, C3 ] + alignment: 2^4 + section-choice: custom-required + section-name: .text +--- + +# CHECK: defined-atoms: +# CHECK: - name: .text +# CHECK: alignment: 2^4 +# CHECK: section-choice: custom-required +# CHECK: section-name: .text +# CHECK: - name: main +# CHECK: scope: global +# CHECK: content: [ B8, 00, 00, 00, 00, C7, 44, 24, FC, 00, 00, 00, +# CHECK: 00, C3 ] +# CHECK: alignment: 2^4 +# CHECK: section-choice: custom-required +# CHECK: section-name: .text + +# ERROR: duplicate symbol error diff --git a/test/elf/archive-elf-forceload.test b/test/elf/archive-elf-forceload.test new file mode 100644 index 000000000000..a0d115094815 --- /dev/null +++ b/test/elf/archive-elf-forceload.test @@ -0,0 +1,43 @@ +# Tests the functionality of archive libraries reading +# and resolution +# Note: The binary files would not be required once we have support to generate +# binary archives from textual(yaml) input +# +# Tests generated using the source files below +# main file +# int main() +# { +# fn(); +# return 0; +# } +# +# archive file +# int fn() +# { +# return 0; +# } +# +# int fn1() +# { +# return 0; +# } +# gcc -c main.c fn.c fn1.c + +RUN: lld -flavor gnu -target x86_64-linux -e main %p/Inputs/mainobj.x86_64 \ +RUN: --whole-archive %p/Inputs/libfnarchive.a --no-whole-archive --output-filetype=yaml \ +RUN: | FileCheck -check-prefix FORCELOAD %s + +FORCELOAD: defined-atoms: +FORCELOAD: - name: fn1 +FORCELOAD: scope: global +FORCELOAD: content: [ 55, 48, 89, E5, B8, 00, 00, 00, 00, 5D, C3 ] +FORCELOAD: - name: fn +FORCELOAD: scope: global +FORCELOAD: content: [ 55, 48, 89, E5, B8, 00, 00, 00, 00, 5D, C3 ] +FORCELOAD: absolute-atoms: +FORCELOAD: - name: main.c +FORCELOAD: value: 0x0 +FORCELOAD: - name: fn1.c +FORCELOAD: value: 0x0 +FORCELOAD: - name: fn.c +FORCELOAD: value: 0x0 diff --git a/test/elf/archive-elf.test b/test/elf/archive-elf.test new file mode 100644 index 000000000000..ba6774644cbd --- /dev/null +++ b/test/elf/archive-elf.test @@ -0,0 +1,38 @@ +# Tests the functionality of archive libraries reading +# and resolution +# Note: The binary files would not be required once we have support to generate +# binary archives from textual(yaml) input +# +# Tests generated using the source files below +# main file +# int main() +# { +# fn(); +# return 0; +# } +# +# archive file +# int fn() +# { +# return 0; +# } +# +# int fn1() +# { +# return 0; +# } +# gcc -c main.c fn.c fn1.c + +RUN: lld -flavor gnu -target x86_64-linux --output-filetype=yaml -r \ +RUN: %p/Inputs/mainobj.x86_64 %p/Inputs/libfnarchive.a | \ +RUN: FileCheck -check-prefix NOFORCELOAD %s + +NOFORCELOAD: defined-atoms: +NOFORCELOAD: - name: fn +NOFORCELOAD: scope: global +NOFORCELOAD: content: [ 55, 48, 89, E5, B8, 00, 00, 00, 00, 5D, C3 ] +NOFORCELOAD: absolute-atoms: +NOFORCELOAD: - name: main.c +NOFORCELOAD: value: 0x0 +NOFORCELOAD: - name: fn.c +NOFORCELOAD: value: 0x0 diff --git a/test/elf/as-needed.test b/test/elf/as-needed.test new file mode 100644 index 000000000000..4477f0fe0ca6 --- /dev/null +++ b/test/elf/as-needed.test @@ -0,0 +1,15 @@ +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared.x86-64 \ +RUN: --as-needed %p/Inputs/shared.so-x86-64 %p/Inputs/libifunc.x86-64.so \ +RUN: -o %t1 -e main --allow-shlib-undefined +RUN: llvm-readobj -dynamic-table %t1 | FileCheck %s -check-prefix AS_NEEDED + +AS_NEEDED: NEEDED SharedLibrary (shared.so-x86-64) +AS_NEEDED-NOT: NEEDED SharedLibrary (libifunc.x86-64.so) + +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared.x86-64 \ +RUN: %p/Inputs/shared.so-x86-64 %p/Inputs/libifunc.x86-64.so \ +RUN: -o %t2 -e main --allow-shlib-undefined +RUN: llvm-readobj -dynamic-table %t2 | FileCheck %s -check-prefix NO_AS_NEEDED + +NO_AS_NEEDED: NEEDED SharedLibrary (shared.so-x86-64) +NO_AS_NEEDED: NEEDED SharedLibrary (libifunc.x86-64.so) diff --git a/test/elf/branch.test b/test/elf/branch.test new file mode 100644 index 000000000000..5e0b4a5aabf1 --- /dev/null +++ b/test/elf/branch.test @@ -0,0 +1,34 @@ +RUN: lld -flavor gnu -target hexagon -static --output-filetype=yaml \ +RUN: %p/Inputs/branch-test.hexagon %p/Inputs/target-test.hexagon --noinhibit-exec | FileCheck %s -check-prefix hexagon-yaml +RUN: lld -flavor gnu -target hexagon -e target -o %t1 \ +RUN: %p/Inputs/branch-test.hexagon %p/Inputs/target-test.hexagon --noinhibit-exec +RUN: llvm-readobj -h %t1 | FileCheck -check-prefix=hexagon-readobj %s + +hexagon-yaml: - name: back +hexagon-yaml: scope: global +hexagon-yaml: content: [ 00, C0, 00, 7F, 00, C0, 00, 5A, 00, 00, 00, 00, +hexagon-yaml: 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ] +hexagon-yaml: references: +hexagon-yaml: - kind: +hexagon-yaml: offset: 4 +hexagon-yaml: target: target + +hexagon-yaml: - name: target +hexagon-yaml: scope: global +hexagon-yaml: content: [ 00, C0, 00, 5A ] +hexagon-yaml: references: +hexagon-yaml: - kind: +hexagon-yaml: offset: 0 +hexagon-yaml: target: back + + +hexagon-readobj: ElfHeader { +hexagon-readobj: Ident { +hexagon-readobj: Class: 32-bit (0x1) +hexagon-readobj: DataEncoding: LittleEndian (0x1) +hexagon-readobj: FileVersion: 1 +hexagon-readobj: OS/ABI: SystemV (0x0) +hexagon-readobj: ABIVersion: 0 +hexagon-readobj: } +hexagon-readobj: Type: Executable (0x2) +hexagon-readobj: Machine: EM_HEXAGON (0xA4) diff --git a/test/elf/check.test b/test/elf/check.test new file mode 100644 index 000000000000..336b7fc1335c --- /dev/null +++ b/test/elf/check.test @@ -0,0 +1,39 @@ +# This tests the basic functionality of ordering data and functions as they +# appear in the inputs +RUN: lld -flavor gnu -target i386 -e global_func --noinhibit-exec --output-filetype=yaml \ +RUN: %p/Inputs/object-test.elf-i386 -o %t +RUN: FileCheck %s -check-prefix ELF-i386 < %t +RUN: lld -flavor gnu -target hexagon -e global_func --noinhibit-exec --output-filetype=yaml \ +RUN: %p/Inputs/object-test.elf-hexagon -o %t1 +RUN: FileCheck %s -check-prefix ELF-hexagon < %t1 + +ELF-i386: defined-atoms: +ELF-i386: - name: global_func +ELF-i386: - name: static_func +ELF-i386: - name: weak_func +ELF-i386: - name: hidden_func +ELF-i386: - name: no_dead_strip +ELF-i386: - name: no_special_section_func +ELF-i386: - name: global_variable +ELF-i386: - name: uninitialized_static_variable +ELF-i386: - name: special_section_func +ELF-i386: undefined-atoms: +ELF-i386: - name: puts +ELF-i386: absolute-atoms: +ELF-i386: - name: sample.c + +ELF-hexagon: - name: global_func +ELF-hexagon: - name: static_func +ELF-hexagon: - name: weak_func +ELF-hexagon: - name: hidden_func +ELF-hexagon: - name: no_dead_strip +ELF-hexagon: - name: no_special_section_func +ELF-hexagon: - name: global_variable +ELF-hexagon: - name: uninitialized_static_variable +ELF-hexagon: - name: special_section_func +ELF-hexagon: undefined-atoms: +ELF-hexagon: - name: puts +ELF-hexagon: absolute-atoms: +ELF-hexagon: - name: sample.c +ELF-hexagon: scope: static +ELF-hexagon: value: 0x0000000000000000 diff --git a/test/elf/checkrodata.test b/test/elf/checkrodata.test new file mode 100644 index 000000000000..fc75657b4afb --- /dev/null +++ b/test/elf/checkrodata.test @@ -0,0 +1,9 @@ + +RUN: lld -flavor gnu -target i386 -o %t1 %p/Inputs/rodata-test.i386 --noinhibit-exec +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 0000000000000114 DATA + +hexagon: .rodata 00000004 0000000000000114 DATA diff --git a/test/elf/common.test b/test/elf/common.test new file mode 100644 index 000000000000..46fcfe39d486 --- /dev/null +++ b/test/elf/common.test @@ -0,0 +1,10 @@ +RUN: lld -flavor gnu -target x86_64-linux -o %t %p/Inputs/relocs.x86-64 \ +RUN: -e _start -static +RUN: llvm-readobj -t %t | FileCheck %s + +CHECK: Symbol { +CHECK: Name: i +CHECK-NEXT: Value: +CHECK-NEXT: Size: +CHECK-NEXT: Binding: +CHECK-NEXT: Type: Object diff --git a/test/elf/consecutive-weak-sym-defs.test b/test/elf/consecutive-weak-sym-defs.test new file mode 100644 index 000000000000..095fabb17ab8 --- /dev/null +++ b/test/elf/consecutive-weak-sym-defs.test @@ -0,0 +1,81 @@ +#Tests that multiple consecutive weak symbol definitions do not confuse the +#ELF reader. For example: +# +# my_weak_func1: +# my_weak_func2: +# my_weak_func3: +# code +# +#If my_weak_func2 is merged to other definition, this should not disturb the +#definition my_weak_func1 to "code". +# +# +#RUN: yaml2obj -format=elf %p/Inputs/consecutive-weak-defs.o.yaml -o=%t1.o +#RUN: yaml2obj -format=elf %p/Inputs/main-with-global-def.o.yaml -o=%t2.o +#RUN: lld -flavor gnu -target x86_64 %t1.o %t2.o -e=main -o %t1 +#RUN: obj2yaml %t1 | FileCheck -check-prefix CHECKLAYOUT %s +# +# Check that the layout has not been changed: +# +#CHECKLAYOUT: Name: .text +#CHECKLAYOUT-NEXT: Type: +#CHECKLAYOUT-NEXT: Flags: +#CHECKLAYOUT-NEXT: Address: +#CHECKLAYOUT-NEXT: AddressAlign: +#CHECKLAYOUT-NEXT: Content: 554889E5E8020000005DC3554889E5B8640000005DC3 +# ^~~> my_func ^~~> my_weak_func +# +# +# +#Our two input files were produced by the following code: +# +#Inputs/consecutive-weak-defs.o.yaml (this one is in assembly to allow us to +# easily define multiple labels) +# +# .text +# .globl my_func +# .type my_func,@function +# my_func: +# pushq %rbp +# movq %rsp, %rbp +# callq my_weak_func +# popq %rbp +# retq +# .Ltmp0: +# .size my_func, .Ltmp0-my_func +# +# .text +# .weak my_weak_func +# .type my_weak_func,@function +# .weak my_weak_func2 +# .type my_weak_func2,@function +# .weak my_weak_func3 +# .type my_weak_func3,@function +# my_weak_func: +# my_weak_func2: +# my_weak_func3: +# pushq %rbp +# movq %rsp, %rbp +# movl $100, %eax +# popq %rbp +# retq +# .Ltmp1: +# .size my_weak_func, .Ltmp1-my_weak_func +# .size my_weak_func2, .Ltmp1-my_weak_func2 +# .size my_weak_func3, .Ltmp1-my_weak_func3 +# +#Inputs/main-with-global-def.o.yaml: +# +# int my_func(); +# +# int my_weak_func2() { +# return 200; +# } +# +# int main() { +# return my_func(); +# } +# +#------------------------------------------------------------------------------- +# The net effect is that this program should return 100. + diff --git a/test/elf/defsym.objtxt b/test/elf/defsym.objtxt new file mode 100644 index 000000000000..e9c3922d5994 --- /dev/null +++ b/test/elf/defsym.objtxt @@ -0,0 +1,28 @@ +# RUN: lld -flavor gnu -target x86_64 --defsym=foo=0x1234 -r %s \ +# RUN: --output-filetype=yaml | FileCheck -check-prefix=ABS %s + +# RUN: lld -flavor gnu -target x86_64 --defsym=foo=main -r %s \ +# RUN: --output-filetype=yaml | FileCheck -check-prefix=ALIAS %s + +defined-atoms: + - name: main + scope: global + content: [ B8, 00, 00, 00, 00, C7, 44, 24, FC, 00, 00, 00, 00, C3 ] + alignment: 2^4 + section-choice: custom-required + section-name: .text + +# ABS: absolute-atoms: +# ABS: - name: foo +# ABS: scope: global +# ABS: value: 0x0000000000001234 + +# ALIAS: defined-atoms: +# ALIAS: - name: foo +# ALIAS: scope: global +# ALIAS: section-choice: custom-required +# ALIAS: section-name: .text +# ALIAS: references: +# ALIAS: - kind: layout-after +# ALIAS: offset: 0 +# ALIAS: target: main diff --git a/test/elf/dynamic-segorder.test b/test/elf/dynamic-segorder.test new file mode 100644 index 000000000000..1fdccec9921b --- /dev/null +++ b/test/elf/dynamic-segorder.test @@ -0,0 +1,17 @@ +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 \ +RUN: %p/Inputs/shared.so-x86-64 -o %t -e main --allow-shlib-undefined \ +RUN: --defsym=__tls_get_addr=0 +RUN: llvm-objdump -p %t | FileCheck %s + +CHECK: PHDR +CHECK: flags r-x +CHECK: INTERP +CHECK: flags r-- +CHECK: LOAD +CHECK: flags r-x +CHECK: LOAD +CHECK: flags rw- +CHECK: DYNAMIC +CHECK: flags rw- +CHECK: TLS +CHECK: flags rw- diff --git a/test/elf/dynamic-undef.test b/test/elf/dynamic-undef.test new file mode 100644 index 000000000000..7506b21b3ca7 --- /dev/null +++ b/test/elf/dynamic-undef.test @@ -0,0 +1,34 @@ +# +# This test creates a executable and tests the options that are used to +# to create an executable and a shared library +# +# This test will fail because there are unresolved symbols from the shared +# library and we are not passing --allow-shlib-undefined +RUN: not lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 \ +RUN: %p/Inputs/shared.so-x86-64 -o %t -e main 2> %t1 +RUN: FileCheck -check-prefix=EXEC %s < %t1 +# This test will pass because of --allow-shlib-undefined +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 \ +RUN: %p/Inputs/shared.so-x86-64 -o %t -e main --allow-shlib-undefined \ +RUN: --defsym=__tls_get_addr=0 +# Building shared libraries should not fail when there is a undefined symbol. +# Test creation of shared library, this should pass because we are using +# shared option and by default, dynamic library wouldn't create undefined atoms +# from the input shared library +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 \ +RUN: %p/Inputs/shared.so-x86-64 -o %t.usenoundefines -e main -shared +RUN: llvm-readobj -symbols %t.usenoundefines | FileCheck %s -check-prefix=SHLIB-NOUNDEF +# Test creation of shared library, this should fail because we are using +# shared option setting the options to use the shared library undefines to +# create undefined atoms from the input shared library +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 \ +RUN: %p/Inputs/shared.so-x86-64 -o %t.useundefines -e main -shared \ +RUN: --use-shlib-undefines --no-allow-shlib-undefined 2> %t2 +RUN: llvm-readobj -symbols %t.useundefines | FileCheck -check-prefix=SHLIB-UNDEF-SYMBOLS %s + +EXEC: Undefined symbol: {{.+[\\/]}}shared.so-x86-64: puts +SHLIB: Undefined symbol: {{.+[\\/]}}shared.so-x86-64: puts +EXEC-NOT: Undefined symbol: {{.+[\\/]}}shared.so-x86-64: weakfoo +SHLIB-NOT: Undefined symbol: {{.+[\\/]}}shared.so-x86-64: weakfoo +SHLIB-NOUNDEF-NOT: Name: puts +SHLIB-UNDEF-SYMBOLS: Name: puts diff --git a/test/elf/dynamic.test b/test/elf/dynamic.test new file mode 100644 index 000000000000..59269612cf8e --- /dev/null +++ b/test/elf/dynamic.test @@ -0,0 +1,80 @@ +# Checks functionality of dynamic executables +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared.x86-64 \ +RUN: %p/Inputs/shared.so-x86-64 -o %t -e main --allow-shlib-undefined \ +RUN: -rpath /l1:/l2 -rpath /l3 +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared.x86-64 \ +RUN: %p/Inputs/shared.so-x86-64 --output-filetype=yaml -o %t2 --allow-shlib-undefined \ +RUN: --noinhibit-exec +RUN: llvm-objdump -p %t >> %t2 +RUN: llvm-readobj -s -dyn-symbols -dynamic-table %t >> %t2 +RUN: FileCheck %s < %t2 + +CHECK: name: main +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: shared-library-atoms: +CHECK: name: foo +CHECK: load-name: shared.so-x86-64 + +CHECK: PHDR off 0x{{0+}}40 +CHECK: INTERP +CHECK: flags r-- + +CHECK: Section { +CHECK: Name: .hash +CHECK-NEXT: Type: SHT_HASH +CHECK-NEXT: Flags [ +CHECK-NEXT: SHF_ALLOC +CHECK-NEXT: ] +CHECK-NEXT: Address: +CHECK-NEXT: Offset: +CHECK-NEXT: Size: 32 +CHECK-NEXT: Link: +CHECK-NEXT: Info: +CHECK-NEXT: AddressAlignment: 8 +CHECK-NEXT: EntrySize: +CHECK-NEXT: } + +CHECK: DynamicSymbols [ +CHECK: Symbol { +CHECK: Name: foo +CHECK-NEXT: Value: 0 +CHECK-NEXT: Size: +CHECK-NEXT: Binding: Global +CHECK-NEXT: Type: Function +CHECK: } +CHECK: Symbol { +CHECK: Name: i +CHECK-NEXT: Value: 0 +CHECK-NEXT: Size: +CHECK-NEXT: Binding: Global +CHECK-NEXT: Type: Object +CHECK: } + +CHECK: DynamicSection [ (15 entries) +CHECK: Tag Type Name/Value +CHECK: 0x0000000000000004 HASH +CHECK: 0x0000000000000005 STRTAB +CHECK: 0x0000000000000006 SYMTAB +CHECK: 0x000000000000000A STRSZ +CHECK: 0x000000000000000B SYMENT 24 +CHECK: 0x0000000000000007 RELA +CHECK: 0x0000000000000008 RELASZ 24 +CHECK: 0x0000000000000009 RELAENT 24 +CHECK: 0x0000000000000002 PLTRELSZ 24 +CHECK: 0x0000000000000003 PLTGOT +CHECK: 0x0000000000000014 PLTREL RELA +CHECK: 0x0000000000000017 JMPREL +CHECK: 0x0000000000000001 NEEDED SharedLibrary (shared.so-x86-64) +CHECK: 0x000000000000000F RPATH /l1:/l2:/l3 +CHECK: 0x0000000000000000 NULL 0x0 +CHECK: ] diff --git a/test/elf/eh_frame_hdr.test b/test/elf/eh_frame_hdr.test new file mode 100644 index 000000000000..31429857ec69 --- /dev/null +++ b/test/elf/eh_frame_hdr.test @@ -0,0 +1,30 @@ +#RUN: yaml2obj -format=elf %s > %t +#RUN: lld -flavor gnu -target x86_64-linux %t --noinhibit-exec \ +#RUN: -o %t1 +#RUN: llvm-objdump -s %t1 | FileCheck %s + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + +Sections: +- Name: .eh_frame + Type: SHT_PROGBITS + Content: "00" + AddressAlign: 8 + Flags: [SHF_ALLOC] + +Symbols: + Local: + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + +# CHECK: Contents of section .eh_frame: +# CHECK-NEXT: 4001e0 00 +# CHECK-NEXT: Contents of section .eh_frame_hdr: +# CHECK-NEXT: 4001e8 011bffff f4ffffff +# ^ 0x4001e0 - 0x4001e8 - 4 = 0xfffffff4 diff --git a/test/elf/entry.objtxt b/test/elf/entry.objtxt new file mode 100644 index 000000000000..7e0c1623565a --- /dev/null +++ b/test/elf/entry.objtxt @@ -0,0 +1,58 @@ +# Tests entry point handling +# +# Test generated using the source file below: +# +# int main() +# { +# return 0; +# } +# + +# RUN: lld -flavor gnu -target x86_64 %s -e _entrypoint --noinhibit-exec -o %t1 +# RUN: llvm-nm -n %t1 | FileCheck %s +# +# CHECK: 004001e0 T main +# CHECK: 00401000 D _DYNAMIC +# CHECK: 00401060 A _end +# CHECK: 00401060 A end +# CHECK: U _entrypoint + +defined-atoms: + - name: .text + alignment: 2^4 + section-choice: custom-required + section-name: .text + - name: main + scope: global + content: [ B8, 00, 00, 00, 00, C7, 44, 24, FC, 00, 00, 00, + 00, C3 ] + alignment: 2^4 + section-choice: custom-required + section-name: .text + - name: .data + type: data + alignment: 2^2 + section-choice: custom-required + section-name: .data + - name: .bss + type: zero-fill + alignment: 2^2 + section-choice: custom-required + section-name: .bss + - name: .note.GNU-stack + section-choice: custom-required + section-name: .note.GNU-stack + permissions: r-- + - name: .eh_frame + content: [ 14, 00, 00, 00, 00, 00, 00, 00, 01, 7A, 52, 00, + 01, 78, 10, 01, 1B, 0C, 07, 08, 90, 01, 00, 00, + 14, 00, 00, 00, 1C, 00, 00, 00, 00, 00, 00, 00, + 0E, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ] + alignment: 2^3 + section-choice: custom-required + section-name: .eh_frame + permissions: r-- + references: + - kind: R_X86_64_PC32 + offset: 32 + target: .text diff --git a/test/elf/export-dynamic.test b/test/elf/export-dynamic.test new file mode 100644 index 000000000000..37876a47c840 --- /dev/null +++ b/test/elf/export-dynamic.test @@ -0,0 +1,99 @@ +# Tests the --export-dynamic (-E) flag. When creating a dynamic executable and +# receiving this flag, the linker should export all globally visible symbols in +# its dynamic symbol table. + +#RUN: yaml2obj -format=elf %s -o=%t.o +#RUN: lld -flavor gnu -target x86_64 -E %t.o -e=main -o %t1 +#RUN: llvm-readobj -dt %t1 | FileCheck -check-prefix CHECKSYMS %s + +#CHECKSYMS: myfunc1@ +#CHECKSYMS: main@ +#CHECKSYMS: myvar1@ + +# The object file below was generated with the following code: +# +# (command line clang -c prog.c -o prog.o) +# +# int myvar1 = 22; +# +# static int mysecretvar = 11; +# +# int myfunc1() { +# return 23; +# } +# +# static int mysecretfunc() { +# return 42; +# } +# +# int main() { +# return mysecretfunc() + mysecretvar; +# } +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E5B8170000005DC30F1F440000554889E54883EC10C745FC00000000E81C000000030425000000004883C4105DC36666666666662E0F1F840000000000554889E5B82A0000005DC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000027 + Symbol: .data + Type: R_X86_64_32S + Addend: 4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: 160000000B000000 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' +Symbols: + Local: + - Name: mysecretfunc + Type: STT_FUNC + Section: .text + Value: 0x0000000000000040 + Size: 0x000000000000000B + - Name: mysecretvar + Type: STT_OBJECT + Section: .data + Value: 0x0000000000000004 + Size: 0x0000000000000004 + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000000010 + Size: 0x0000000000000021 + - Name: myfunc1 + Type: STT_FUNC + Section: .text + Size: 0x000000000000000B + - Name: myvar1 + Type: STT_OBJECT + Section: .data + Size: 0x0000000000000004 diff --git a/test/elf/filenotfound.test b/test/elf/filenotfound.test new file mode 100644 index 000000000000..d64568f2ea53 --- /dev/null +++ b/test/elf/filenotfound.test @@ -0,0 +1,3 @@ +# Check that a file that cannot be found results in a proper error message +RUN: not lld -flavor gnu -target x86_64 %p/Inputs/nofile.o 2>&1 | FileCheck %s +#CHECK: lld: cannot find file {{.+[\\/]}}nofile.o diff --git a/test/elf/gnulinkonce/gnulinkonce-report-discarded-reference.test b/test/elf/gnulinkonce/gnulinkonce-report-discarded-reference.test new file mode 100644 index 000000000000..e1d0f8e7b55e --- /dev/null +++ b/test/elf/gnulinkonce/gnulinkonce-report-discarded-reference.test @@ -0,0 +1,147 @@ +# Tests that the linker is able to read .gnu.linkonce sections and link them +# appropriately. The testcase has been created by using the following source +# code. +# TODO: This test should produce a discarded reference error message which it +# does not currently. +# linkoncea.s +# .section .gnu.linkonce.d.dummy,"aw" +#bar: +# .long 0 +# linkonceb.s +# .section .gnu.linkonce.d.dummy,"aw" +#foo: +# .long 0 +# .section .blah, "aw" +# .long foo +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.linkonce1a.o +#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.linkonce1b.o +#RUN: lld -flavor gnu -target x86_64 %t.linkonce1a.o %t.linkonce1b.o \ +#RUN: --noinhibit-exec --output-filetype=yaml -o %t2.out.yaml +#RUN: lld -flavor gnu -target x86_64 %t.linkonce1a.o %t.linkonce1b.o \ +#RUN: --noinhibit-exec -o %t2.out +#RUN: FileCheck %s -check-prefix=CHECKGNULINKONCE < %t2.out.yaml +#RUN: llvm-readobj -sections %t2.out | FileCheck %s -check-prefix=CHECKGNULINKONCESECTIONS +#CHECKGNULINKONCE: - name: .gnu.linkonce.d.dummy +#CHECKGNULINKONCE: scope: global +#CHECKGNULINKONCE: type: gnu-linkonce +#CHECKGNULINKONCE: section-choice: custom-required +#CHECKGNULINKONCE: section-name: .gnu.linkonce.d.dummy +#CHECKGNULINKONCE: permissions: rw- +#CHECKGNULINKONCE: references: +#CHECKGNULINKONCE: - kind: group-child +#CHECKGNULINKONCE: offset: 0 +#CHECKGNULINKONCE: target: bar +#CHECKGNULINKONCESECTIONS: Section { +#CHECKGNULINKONCESECTIONS: Name: .gnu.linkonce.d.dummy +#CHECKGNULINKONCESECTIONS: Type: SHT_PROGBITS +#CHECKGNULINKONCESECTIONS: Flags [ (0x3) +#CHECKGNULINKONCESECTIONS: SHF_ALLOC (0x2) +#CHECKGNULINKONCESECTIONS: SHF_WRITE (0x1) +#CHECKGNULINKONCESECTIONS: ] +#CHECKGNULINKONCESECTIONS: Size: 4 +#CHECKGNULINKONCESECTIONS: } +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .gnu.linkonce.d.dummy + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '00000000' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .gnu.linkonce.d.dummy + Type: STT_SECTION + Section: .gnu.linkonce.d.dummy + - Name: bar + Section: .gnu.linkonce.d.dummy +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .gnu.linkonce.d.dummy + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '00000000' + - Name: .blah + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '00000000' + - Name: .rela.blah + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .blah + Relocations: + - Offset: 0x0000000000000000 + Symbol: foo + Type: R_X86_64_32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .gnu.linkonce.d.dummy + Type: STT_SECTION + Section: .gnu.linkonce.d.dummy + - Name: foo + Section: .gnu.linkonce.d.dummy + - Name: .blah + Type: STT_SECTION + Section: .blah +... diff --git a/test/elf/gnulinkonce/gnulinkonce-report-undef.test b/test/elf/gnulinkonce/gnulinkonce-report-undef.test new file mode 100644 index 000000000000..c6d050dcd63a --- /dev/null +++ b/test/elf/gnulinkonce/gnulinkonce-report-undef.test @@ -0,0 +1,129 @@ +# Tests that the linker is able to read .gnu.linkonce sections and link them +# appropriately. The testcase has been created by using the following source +# code. This test checks that the linker produces an undefined error. +# linkoncea.s +# .section .gnu.linkonce.d.dummy,"aw" +#bar: +# .long 0 +# linkonceb.s +# .section .gnu.linkonce.d.dummy,"aw" +# .global foo +#foo: +# .long 0 +# .section .blah, "aw" +# .long foo +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.linkonce1a.o +#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.linkonce1b.o +#RUN: not lld -flavor gnu -target x86_64 %t.linkonce1a.o %t.linkonce1b.o \ +#RUN: --output-filetype=yaml -o %t2.out.yaml 2>&1 | FileCheck \ +#RUN: -check-prefix=UNDEFS %s +#RUN: not lld -flavor gnu -target x86_64 %t.linkonce1a.o %t.linkonce1b.o \ +#RUN: -o %t2.out 2>&1 | FileCheck -check-prefix=UNDEFS %s +#UNDEFS: Undefined symbol: {{.*}} foo +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .gnu.linkonce.d.dummy + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '00000000' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .gnu.linkonce.d.dummy + Type: STT_SECTION + Section: .gnu.linkonce.d.dummy + - Name: bar + Section: .gnu.linkonce.d.dummy +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .gnu.linkonce.d.dummy + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '00000000' + - Name: .blah + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '00000000' + - Name: .rela.blah + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .blah + Relocations: + - Offset: 0x0000000000000000 + Symbol: foo + Type: R_X86_64_32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .gnu.linkonce.d.dummy + Type: STT_SECTION + Section: .gnu.linkonce.d.dummy + - Name: .blah + Type: STT_SECTION + Section: .blah + Global: + - Name: foo + Section: .gnu.linkonce.d.dummy +... diff --git a/test/elf/gnulinkonce/gnulinkonce.test b/test/elf/gnulinkonce/gnulinkonce.test new file mode 100644 index 000000000000..17559f656328 --- /dev/null +++ b/test/elf/gnulinkonce/gnulinkonce.test @@ -0,0 +1,151 @@ +# Tests that the linker is able to read .gnu.linkonce sections and link them +# appropriately. The testcase has been created by using the following source +# code +# linkonce1a.s +# ------------ +# .section .gnu.linkonce.d.dummy,"aw" +#bar: +# .long 0 +# linkonce1b.s +# ------------ +# .globl main +# .globl start +# .globl _start +# .globl __start +# .text +#main: +#start: +#_start: +#__start: +# .long 0 +# +# .section .gnu.linkonce.d.dummy,"aw" +#foo: +# .long 0 +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.linkonce1a.o +#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.linkonce1b.o +#RUN: lld -flavor gnu -target x86_64 %t.linkonce1a.o %t.linkonce1b.o \ +#RUN: --noinhibit-exec --output-filetype=yaml -o %t2.out.yaml +#RUN: lld -flavor gnu -target x86_64 %t.linkonce1a.o %t.linkonce1b.o \ +#RUN: --noinhibit-exec -o %t2.out +#RUN: FileCheck %s -check-prefix=CHECKGNULINKONCE < %t2.out.yaml +#RUN: llvm-readobj -sections %t2.out | FileCheck %s -check-prefix=CHECKGNULINKONCESECTIONS +#CHECKGNULINKONCE: - name: .gnu.linkonce.d.dummy +#CHECKGNULINKONCE: scope: global +#CHECKGNULINKONCE: type: gnu-linkonce +#CHECKGNULINKONCE: section-choice: custom-required +#CHECKGNULINKONCE: section-name: .gnu.linkonce.d.dummy +#CHECKGNULINKONCE: permissions: rw- +#CHECKGNULINKONCE: references: +#CHECKGNULINKONCE: - kind: group-child +#CHECKGNULINKONCE: offset: 0 +#CHECKGNULINKONCE: target: bar +#CHECKGNULINKONCE: - kind: group-child +#CHECKGNULINKONCE: offset: 0 +#CHECKGNULINKONCESECTIONS: Section { +#CHECKGNULINKONCESECTIONS: Name: .gnu.linkonce.d.dummy +#CHECKGNULINKONCESECTIONS: Type: SHT_PROGBITS +#CHECKGNULINKONCESECTIONS: Flags [ (0x3) +#CHECKGNULINKONCESECTIONS: SHF_ALLOC (0x2) +#CHECKGNULINKONCESECTIONS: SHF_WRITE (0x1) +#CHECKGNULINKONCESECTIONS: ] +#CHECKGNULINKONCESECTIONS: Size: 4 +#CHECKGNULINKONCESECTIONS: } +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .gnu.linkonce.d.dummy + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '00000000' +Symbols: + Local: + - Name: bar + Section: .gnu.linkonce.d.dummy + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .gnu.linkonce.d.dummy + Type: STT_SECTION + Section: .gnu.linkonce.d.dummy +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '00000000' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .gnu.linkonce.d.dummy + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '00000000' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .gnu.linkonce.d.dummy + Type: STT_SECTION + Section: .gnu.linkonce.d.dummy + - Name: foo + Section: .gnu.linkonce.d.dummy + Global: + - Name: main + Section: .text + - Name: start + Section: .text + - Name: _start + Section: .text + - Name: __start + Section: .text +... diff --git a/test/elf/gotpcrel.test b/test/elf/gotpcrel.test new file mode 100644 index 000000000000..b6f83c16676d --- /dev/null +++ b/test/elf/gotpcrel.test @@ -0,0 +1,21 @@ +# This test checks that GOTPCREL entries are being handled properly +RUN: lld -flavor gnu -target x86_64-linux -static -e main --output-filetype=yaml \ +RUN: --noinhibit-exec %p/Inputs/gotpcrel.x86-64 \ +RUN: | FileCheck %s -check-prefix=YAML + +YAML: name: main +YAML: references: +YAML: kind: R_X86_64_GOTPCREL +YAML: offset: 3 +YAML: target: [[NULLGOT:[a-zA-Z0-9_]+]] +YAML: kind: R_X86_64_GOTPCREL +YAML: offset: 10 +YAML: target: [[MAINGOT:[a-zA-Z0-9_]+]] + +YAML: name: [[NULLGOT]] +YAML: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +YAML-NOT: references: + +YAML: name: [[MAINGOT]] +YAML: kind: R_X86_64_64 +YAML: target: main diff --git a/test/elf/gottpoff.test b/test/elf/gottpoff.test new file mode 100644 index 000000000000..9841ee1453d0 --- /dev/null +++ b/test/elf/gottpoff.test @@ -0,0 +1,120 @@ +# Test that GOTTPOFF reloc generates an outstanding R_X86_64_TPOFF64 +# to be processed at startup time. +# Reference: Ulrich Drepper's "ELF Handling for Thread-Local storage" + +#RUN: yaml2obj -format=elf %s -o %t.o +#RUN: lld -flavor gnu -target x86_64 %t.o -o %t -e=main --defsym=__tls_get_addr=0 +#RUN: llvm-readobj -r %t | FileCheck %s +# +#CHECK: Section (5) .rela.dyn { +#CHECK: 0x401098 R_X86_64_TPOFF64 - 0x0 +#CHECK: } + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_FREEBSD + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: E819000000640304250000000064030425000000006403042500000000C3488B0500000000648B00C3488D3D00000000E800000000488D8000000000C3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000009 + Symbol: tls1 + Type: R_X86_64_TPOFF32 + - Offset: 0x0000000000000011 + Symbol: tls0 + Type: R_X86_64_TPOFF32 + - Offset: 0x0000000000000019 + Symbol: tls2 + Type: R_X86_64_TPOFF32 + - Offset: 0x0000000000000021 + Symbol: tls2 + Type: R_X86_64_GOTTPOFF + Addend: -4 + - Offset: 0x000000000000002C + Symbol: tls0 + Type: R_X86_64_TLSLD + Addend: -4 + - Offset: 0x0000000000000031 + Symbol: __tls_get_addr + Type: R_X86_64_PLT32 + Addend: -4 + - Offset: 0x0000000000000038 + Symbol: tls0 + Type: R_X86_64_DTPOFF32 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .tbss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x0000000000000004 + Content: '01000000002E7265' + - Name: .tdata + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] + AddressAlign: 0x0000000000000004 + Content: '01000000' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .tbss + Type: STT_SECTION + Section: .tbss + - Name: .tdata + Type: STT_SECTION + Section: .tdata + Global: + - Name: GOTTPOFF + Type: STT_FUNC + Section: .text + Value: 0x000000000000001E + - Name: TLSLD + Type: STT_FUNC + Section: .text + Value: 0x0000000000000029 + - Name: main + Type: STT_FUNC + Section: .text + - Name: tls0 + Type: STT_TLS + Section: .tbss + Size: 0x0000000000000004 + - Name: tls1 + Type: STT_TLS + Section: .tbss + Value: 0x0000000000000004 + Size: 0x0000000000000004 + - Name: tls2 + Type: STT_TLS + Section: .tdata + Size: 0x0000000000000004 + - Name: _GLOBAL_OFFSET_TABLE_ + - Name: __tls_get_addr +... diff --git a/test/elf/group-cmd-search.test b/test/elf/group-cmd-search.test new file mode 100644 index 000000000000..5e153c1ac1ad --- /dev/null +++ b/test/elf/group-cmd-search.test @@ -0,0 +1,134 @@ +/* + XFAIL: win32 + + This test does not pass on Windows because a path starting with + "/" is not considered as an absolute path. (It needs a drive + letter.) +*/ + +/* + In general the linker scripts's GROUP command works like a pair + of command line options --start-group/--end-group. But there is + a difference in the files look up algorithm. + + The --start-group/--end-group commands use a trivial approach: + a) If the path has '-l' prefix, add 'lib' prefix and '.a'/'.so' + suffix and search the path through library search directories. + b) Otherwise, use the path 'as-is'. + + The GROUP command implements more compicated approach: + a) If the path has '-l' prefix, add 'lib' prefix and '.a'/'.so' + suffix and search the path through library search directories. + b) If the path does not have '-l' prefix, and sysroot is configured, + and the path starts with the / character, and the script being + processed is located inside the sysroot, search the path under + the sysroot. Otherwise, try to open the path in the current + directory. If it is not found, search through library search + directories. +*/ + +/* + This link should finish successfully. The --start-group/--end-group + contains an existing absolute path to the file. + +RUN: lld -flavor gnu -target x86_64 -shared \ +RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \ +RUN: --start-group %p/Inputs/shared.so-x86-64 --end-group -o %t1 +*/ + +/* + This link should fail with unknown input file format error. + There is no shared.so-x86-64 file in the current directory. + +RUN: not \ +RUN: lld -flavor gnu -target x86_64 -shared \ +RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \ +RUN: --start-group shared.so-x86-64 --end-group -o %t2 +*/ + +/* + This link should fail with unknown input file format error. + The absolute path /shared.so-x86-64 does not exist and the linker + should not attempt to search it under the sysroot directory. + +RUN: not \ +RUN: lld -flavor gnu -target x86_64 -shared --sysroot=%p/Inputs \ +RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \ +RUN: --start-group /shared.so-x86-64 --end-group -o %t3 +*/ + +/* + This link should finish successfully. The group-cmd-search-1.ls + script contains "GROUP ( shared.so-x86-64 )" command and the linker + has to search shared.so-x86-64 through the library search paths. + +RUN: lld -flavor gnu -target x86_64 -shared \ +RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \ +RUN: %p/Inputs/group-cmd-search-1.ls -o %t4 +*/ + +/* + This link should fail with unknown input file format error. + The group-cmd-search-2.ls script contains GROUP command with + a non-existing absolute path but there is no --sysroot argument. + +RUN: not \ +RUN: lld -flavor gnu -target x86_64 -shared \ +RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \ +RUN: %p/Inputs/group-cmd-search-2.ls -o %t5 +*/ + +/* + This link should finish successfully. The group-cmd-search-2.ls + script contains GROUP command with an absolute path and the sysroot + directory is provided. The linker has to search the absolute path + under the sysroot directory. + +RUN: lld -flavor gnu -target x86_64 -shared --sysroot=%p/Inputs \ +RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \ +RUN: %p/Inputs/group-cmd-search-2.ls -o %t6 +*/ + +/* + This link should finish successfully. The group-cmd-search-2.ls + script contains GROUP command with an absolute path and the sysroot + directory is provided. The linker has to search the absolute path + under the sysroot directory. + +RUN: lld -flavor gnu -target x86_64 -shared --sysroot=%p/Inputs/../Inputs \ +RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \ +RUN: %p/Inputs/group-cmd-search-2.ls -o %t6 +*/ + +/* + This link should finish successfully. The group-cmd-search-3.ls + script contains GROUP command with two elements. The first one + has a -l:<path> form and should be found by iterating through + lib dirs and searching the 'path' name exactly. The second element + has a -l<lib name> form and should be found by constructing a full + library name lib<lib name>.a and iterating through lib dirs. + +RUN: lld -flavor gnu -target x86_64 -shared \ +RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \ +RUN: %p/Inputs/group-cmd-search-3.ls -o %t8 +*/ + +/* + This link should fail with unknown input file format error. + The linker script from this file contains GROUP with an absolute + path which can be found under provided sysroot directory. + But the linker script itself is not under the sysroot. + +RUN: not \ +RUN: lld -flavor gnu -target x86_64 -shared --sysroot=%p/Inputs \ +RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \ +RUN: %s -o %t7 +*/ + +/* +RUN: lld -flavor gnu -target x86_64 -shared \ +RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \ +RUN: -l:group-cmd-search-1.ls -o %t9 +*/ + +GROUP ( /shared.so-x86-64 ) diff --git a/test/elf/hexagon-quickdata-sort.test b/test/elf/hexagon-quickdata-sort.test new file mode 100644 index 000000000000..efdf9480923d --- /dev/null +++ b/test/elf/hexagon-quickdata-sort.test @@ -0,0 +1,12 @@ +RUN: lld -flavor gnu -target hexagon %p/Inputs/quickdata-sort-test.o.elf-hexagon -o %t1 --noinhibit-exec +RUN: llvm-nm -n %t1 | FileCheck %s -check-prefix=quickdataSort + +quickdataSort: 00002000 D A1 +quickdataSort: 00002001 D AA1 +quickdataSort: 00002002 D B1 +quickdataSort: 00002004 D BB1 +quickdataSort: 00002008 D C1 +quickdataSort: 0000200c D CC1 +quickdataSort: 00002010 D D1 +quickdataSort: 00002018 D DD1 + diff --git a/test/elf/hexagon-quickdata-sortcommon.test b/test/elf/hexagon-quickdata-sortcommon.test new file mode 100644 index 000000000000..5b4690b43cb9 --- /dev/null +++ b/test/elf/hexagon-quickdata-sortcommon.test @@ -0,0 +1,16 @@ +RUN: lld -flavor gnu -target hexagon -o %t1 --noinhibit-exec \ +RUN: %p/Inputs/quickdata-sortcommon-test.o.elf-hexagon +RUN: llvm-nm -n %t1 | FileCheck %s -check-prefix=quickdataSortCommon + +quickdataSortCommon: 00002000 D A1 +quickdataSortCommon: 00002001 D AA1 +quickdataSortCommon: 00002002 D AAA1 +quickdataSortCommon: 00002004 D B1 +quickdataSortCommon: 00002006 D BB1 +quickdataSortCommon: 00002008 D BBB1 +quickdataSortCommon: 0000200c D C1 +quickdataSortCommon: 00002010 D CC1 +quickdataSortCommon: 00002014 D CCC1 +quickdataSortCommon: 00002018 D D1 +quickdataSortCommon: 00002020 D DD1 +quickdataSortCommon: 00002028 D DDD1 diff --git a/test/elf/ifunc.test b/test/elf/ifunc.test new file mode 100644 index 000000000000..c567c554cbbb --- /dev/null +++ b/test/elf/ifunc.test @@ -0,0 +1,69 @@ +# REQUIRES: x86 + +# This test checks that IRELATIVE relocations are created for symbols that +# need relocation even for static links. +RUN: lld -flavor gnu -target x86_64-linux --output-filetype=yaml -r \ +RUN: %p/Inputs/ifunc.x86-64 | FileCheck %s + +RUN: lld -flavor gnu -target x86_64-linux --output-filetype=yaml --noinhibit-exec \ +RUN: %p/Inputs/ifunc.x86-64 %p/Inputs/ifunc.cpp.x86-64 \ +RUN: | FileCheck %s --check-prefix=PLT + +RUN: lld -flavor gnu -target x86_64-linux -o %t %p/Inputs/ifunc.x86-64 \ +RUN: -e main -static %p/Inputs/ifunc.cpp.x86-64 +RUN: llvm-objdump -d -s %t| FileCheck %s --check-prefix=BIN +RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELATIVEADDEND + +# Test that STT_GNU_IFUNC symbols have type Code in SharedLibraryAtom. +RUN: lld -flavor gnu -target x86_64-linux --output-filetype=yaml \ +RUN: --noinhibit-exec %p/Inputs/ifunc.cpp.x86-64 -L%p/Inputs -lifunc.x86-64 \ +RUN: | FileCheck %s --check-prefix=SHARED + +PLT: defined-atoms: + +PLT: name: plt +PLT: scope: global +PLT: references: +PLT: kind: R_X86_64_PC32 +PLT: target: [[PLTNAME:[-a-zA-Z0-9_]+]] + +PLT: name: main +PLT: scope: global +PLT: references: +PLT: kind: R_X86_64_PC32 +PLT: target: [[PLTNAME]] + +// 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. +PLT: name: +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 + + +// This is a horribly brittle test. We need a way to do arithmetic on captured +// variables. +BIN: {{[0-9a-f]+}}: ff 25 {{[0-9a-f]+}} {{[0-9a-f]+}} 00 00 jmpq *{{[0-9]+}}(%rip) +BIN: .got.plt: +BIN-NEXT: {{[0-9a-f]+}} 00000000 00000000 + +RELATIVEADDEND: Relocations [ +RELATIVEADDEND-NEXT: Section (1) .rela.plt { +RELATIVEADDEND-NEXT: 0x401000 R_X86_64_IRELATIVE - 0x400110 +RELATIVEADDEND-NEXT: } +RELATIVEADDEND-NEXT: ] + +SHARED: shared-library-atoms +SHARED: name: hey +SHARED-NOT: data diff --git a/test/elf/ignore-unknownoption.test b/test/elf/ignore-unknownoption.test new file mode 100644 index 000000000000..56856ed9f2e4 --- /dev/null +++ b/test/elf/ignore-unknownoption.test @@ -0,0 +1,5 @@ +# This test tests that lld is able to print unknown options that are not +# recognized. +RUN: not lld -flavor gnu -target x86_64 --gc-sections 2> %t +RUN: FileCheck %s < %t +CHECK: warning: ignoring unknown argument: --gc-sections diff --git a/test/elf/init_array-order.test b/test/elf/init_array-order.test new file mode 100644 index 000000000000..b57b3807b69c --- /dev/null +++ b/test/elf/init_array-order.test @@ -0,0 +1,67 @@ +#RUN: yaml2obj -format=elf %s > %t +#RUN: lld -flavor gnu -target x86_64-linux %t --noinhibit-exec \ +#RUN: -o %t1.out +#RUN: llvm-objdump -s %t1.out | FileCheck %s + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: "1100000000000000" + AddressAlign: 8 + Flags: [SHF_ALLOC, SHF_EXECINSTR] +- Name: .init_array.2 + Type: SHT_INIT_ARRAY + Content: "0200000000000000" + AddressAlign: 8 + Flags: [SHF_ALLOC] +- Name: .init_array.3 + Type: SHT_INIT_ARRAY + Content: "0300000000000000" + AddressAlign: 8 + Flags: [SHF_ALLOC] +- Name: .init_array + Type: SHT_INIT_ARRAY + Content: "9900000000000000" + AddressAlign: 8 + Flags: [SHF_ALLOC] +- Name: .data + Type: SHT_PROGBITS + Content: "2200000000000000" + AddressAlign: 8 + Flags: [SHF_ALLOC, SHF_WRITE] +- Name: .init_array.1 + Type: SHT_INIT_ARRAY + Content: "0100000000000000" + AddressAlign: 8 + Flags: [SHF_ALLOC] + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .init_array.3 + Type: STT_SECTION + Section: .init_array.3 + - Name: .init_array.2 + Type: STT_SECTION + Section: .init_array.2 + - Name: .init_array.1 + Type: STT_SECTION + Section: .init_array.1 + - Name: .init_array + Type: STT_SECTION + Section: .init_array + +#CHECK: {{[0xa-f0-9]+}} 01000000 00000000 02000000 00000000 +#CHECK: {{[0xa-f0-9]+}} 03000000 00000000 99000000 00000000 diff --git a/test/elf/init_array.test b/test/elf/init_array.test new file mode 100644 index 000000000000..1acf4a7e7a28 --- /dev/null +++ b/test/elf/init_array.test @@ -0,0 +1,6 @@ +RUN: lld -flavor gnu -target x86_64-linux -o %t %p/Inputs/init_array.x86-64 \ +RUN: -e __init_array_start +RUN: llvm-objdump -t -section-headers %t | FileCheck %s + +CHECK: .init_array {{[0-9]+}} [[ADDR:[0-9]+]] +CHECK: [[ADDR]] g *ABS* {{[0-9]+}} __init_array_start diff --git a/test/elf/initfini-options.test-1.test b/test/elf/initfini-options.test-1.test new file mode 100644 index 000000000000..2fc1c3e32bda --- /dev/null +++ b/test/elf/initfini-options.test-1.test @@ -0,0 +1,33 @@ +# Check that if there are no -init/-fini options and _init/_fini symbols +# are undefined the linker does not emit DT_INIT/DT_FINI tags. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target x86_64 -shared --noinhibit-exec -o %t.so %t.o +# RUN: llvm-readobj -dynamic-table %t.so | FileCheck %s + +# CHECK-NOT: 0x000000000000000C INIT 0x{{[0-9A-F]+}} +# CHECK-NOT: 0x000000000000000D FINI 0x{{[0-9A-F]+}} + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x08 + +Symbols: + Global: + - Name: _start + Type: STT_FUNC + Section: .text + Size: 0x08 + - Name: _init + - Name: _fini +... diff --git a/test/elf/initfini-options.test-2.test b/test/elf/initfini-options.test-2.test new file mode 100644 index 000000000000..4742084c513b --- /dev/null +++ b/test/elf/initfini-options.test-2.test @@ -0,0 +1,47 @@ +# Check that if _init/_fini symbols are defined the linker emits +# DT_INIT/DT_FINI tags point to these symbols. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target x86_64 -shared -o %t.so %t.o +# RUN: llvm-readobj -symbols -dynamic-table %t.so | FileCheck %s + +# CHECK: Name: _init (8) +# CHECK-NEXT: Value: {{[0x0-9a-f]+}} +# CHECK: Name: _fini (14) +# CHECK-NEXT: Value: {{[0x0-9a-f]+}} +# +# CHECK: 0x000000000000000C INIT {{[0x0-9a-f]+}} +# CHECK: 0x000000000000000D FINI {{[0x0-9a-f]+}} + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x18 + +Symbols: + Global: + - Name: _start + Type: STT_FUNC + Section: .text + Value: 0x0 + Size: 0x8 + - Name: _init + Type: STT_FUNC + Section: .text + Value: 0x8 + Size: 0x8 + - Name: _fini + Type: STT_FUNC + Section: .text + Value: 0xF + Size: 0x8 +... diff --git a/test/elf/initfini-options.test-3.test b/test/elf/initfini-options.test-3.test new file mode 100644 index 000000000000..bf8b216775d9 --- /dev/null +++ b/test/elf/initfini-options.test-3.test @@ -0,0 +1,53 @@ +# Check that -init/-fini command line options override default function names +# and the linker uses these name to search symbols and setup DT_INIT/DT_FINI. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target x86_64 -shared -o %t.so %t.o \ +# RUN: -init _init -init _start -fini _fini -fini _stop +# RUN: llvm-readobj -symbols -dynamic-table %t.so | FileCheck %s + +# CHECK: Name: _start (1) +# CHECK-NEXT: Value: {{[0x0-9a-f]+}} +# CHECK: Name: _stop (8) +# CHECK-NEXT: Value: {{[0x0-9a-f]+}} +# +# CHECK: 0x000000000000000C INIT {{[0x0-9a-f]+}} +# CHECK: 0x000000000000000D FINI {{[0x0-9a-f]+}} + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Size: 0x20 + +Symbols: + Global: + - Name: _start + Type: STT_FUNC + Section: .text + Value: 0x0 + Size: 0x8 + - Name: _stop + Type: STT_FUNC + Section: .text + Value: 0x8 + Size: 0x8 + - Name: _init + Type: STT_FUNC + Section: .text + Value: 0xF + Size: 0x8 + - Name: _fini + Type: STT_FUNC + Section: .text + Value: 0x18 + Size: 0x8 +... diff --git a/test/elf/librarynotfound.test b/test/elf/librarynotfound.test new file mode 100644 index 000000000000..faa1728b478b --- /dev/null +++ b/test/elf/librarynotfound.test @@ -0,0 +1,5 @@ +# Tests the functionality of library not found +RUN: not lld -flavor gnu -lfn 2> %t1 +RUN: FileCheck %s < %t1 + +CHECK: Unable to find library -lfn diff --git a/test/elf/linker-as-ld.test b/test/elf/linker-as-ld.test new file mode 100644 index 000000000000..8ac75275f996 --- /dev/null +++ b/test/elf/linker-as-ld.test @@ -0,0 +1,16 @@ +REQUIRES: system-linker-elf + +RUN: mkdir -p %t.dir && cp `which lld` %t.dir/ld +RUN: %t.dir/ld -target x86_64-linux -o %t %p/Inputs/relocs.x86-64 \ +RUN: -e _start -static +RUN: llvm-readobj -t %t | FileCheck %s + +# Test linker run as "ld" on elf based system works like gnu linker. + + +CHECK: Symbol { +CHECK: Name: i +CHECK-NEXT: Value: +CHECK-NEXT: Size: +CHECK-NEXT: Binding: +CHECK-NEXT: Type: Object diff --git a/test/elf/linkerscript/Inputs/externs.ls b/test/elf/linkerscript/Inputs/externs.ls new file mode 100644 index 000000000000..20fdc0c3f980 --- /dev/null +++ b/test/elf/linkerscript/Inputs/externs.ls @@ -0,0 +1,3 @@ +/* A simple valid linker script used for testing the EXTERN command. + */ +EXTERN(_foo bar __baz) diff --git a/test/elf/linkerscript/Inputs/invalid.ls b/test/elf/linkerscript/Inputs/invalid.ls new file mode 100644 index 000000000000..894d4bef2732 --- /dev/null +++ b/test/elf/linkerscript/Inputs/invalid.ls @@ -0,0 +1 @@ +GROUP( diff --git a/test/elf/linkerscript/Inputs/prog1.o.yaml b/test/elf/linkerscript/Inputs/prog1.o.yaml new file mode 100644 index 000000000000..ded590e395d4 --- /dev/null +++ b/test/elf/linkerscript/Inputs/prog1.o.yaml @@ -0,0 +1,88 @@ +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E5B000E800000000BF01000000BA0E0000004889C6E80000000031C05DC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000007 + Symbol: prog2 + Type: R_X86_64_PC32 + Addend: -4 + - Offset: 0x0000000000000019 + Symbol: write + Type: R_X86_64_PC32 + Addend: -4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 00636C616E672076657273696F6E20332E372E302028687474703A2F2F6C6C766D2E6F72672F6769742F636C616E672E6769742036336134646334616430343938646139623934386330383263623735336430353735323938346638292028687474703A2F2F6C6C766D2E6F72672F6769742F6C6C766D2E67697420623838363135326664656538376564653738613565643965616638663664313839343033616266312900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C0708900100001C0000001C000000000000002100000000410E108602430D0600000000000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x0000000000000021 + - Name: prog2 + - Name: write +... diff --git a/test/elf/linkerscript/Inputs/prog2.o.yaml b/test/elf/linkerscript/Inputs/prog2.o.yaml new file mode 100644 index 000000000000..f88b0ddc96b2 --- /dev/null +++ b/test/elf/linkerscript/Inputs/prog2.o.yaml @@ -0,0 +1,89 @@ +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E548B800000000000000005DC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000006 + Symbol: .rodata.str1.1 + Type: R_X86_64_64 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .rodata.str1.1 + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 48656C6C6F2C20776F726C64210A00 + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 00636C616E672076657273696F6E20332E372E302028687474703A2F2F6C6C766D2E6F72672F6769742F636C616E672E6769742036336134646334616430343938646139623934386330383263623735336430353735323938346638292028687474703A2F2F6C6C766D2E6F72672F6769742F6C6C766D2E67697420623838363135326664656538376564653738613565643965616638663664313839343033616266312900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C0708900100001C0000001C000000000000001000000000410E108602430D0600000000000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .rodata.str1.1 + Type: STT_SECTION + Section: .rodata.str1.1 + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: prog2 + Type: STT_FUNC + Section: .text + Size: 0x0000000000000010 +... diff --git a/test/elf/linkerscript/Inputs/prog3.o.yaml b/test/elf/linkerscript/Inputs/prog3.o.yaml new file mode 100644 index 000000000000..76aa22267f0b --- /dev/null +++ b/test/elf/linkerscript/Inputs/prog3.o.yaml @@ -0,0 +1,52 @@ +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: B8010000000F05C3E800000000B83C0000000F05C3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000009 + Symbol: main + Type: R_X86_64_PC32 + Addend: -4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: _start + Section: .text + Value: 0x0000000000000008 + - Name: write + Section: .text + - Name: main +... diff --git a/test/elf/linkerscript/Inputs/simple.o.yaml b/test/elf/linkerscript/Inputs/simple.o.yaml new file mode 100644 index 000000000000..91d4e1b57786 --- /dev/null +++ b/test/elf/linkerscript/Inputs/simple.o.yaml @@ -0,0 +1,52 @@ +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: B80100000048C7C70100000048C7C60000000048C7C20E0000000F05C3E8DEFFFFFFB83C0000000F05C3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x000000000000000F + Symbol: .data + Type: R_X86_64_32S + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: 48656C6C6F2C20576F726C64210A00 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' +Symbols: + Local: + - Name: main + Section: .text + - Name: msg + Section: .data + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: _start + Section: .text + Value: 0x000000000000001D +... diff --git a/test/elf/linkerscript/Inputs/valid.ls b/test/elf/linkerscript/Inputs/valid.ls new file mode 100644 index 000000000000..43593602d3fb --- /dev/null +++ b/test/elf/linkerscript/Inputs/valid.ls @@ -0,0 +1,6 @@ +/* A simple valid linker script used for testing the -T/--script options. + * + * An unresolved symbol named '_entry_point' can be scanned for by the tests + * to determine that the linker script was processed. + */ +ENTRY(_entry_point) diff --git a/test/elf/linkerscript/externs.objtxt b/test/elf/linkerscript/externs.objtxt new file mode 100644 index 000000000000..154891eaf710 --- /dev/null +++ b/test/elf/linkerscript/externs.objtxt @@ -0,0 +1,21 @@ +# Check symbols defined with the EXTERN command are added as undefined +# symbols. + +# RUN: lld -flavor gnu -target x86_64 -T %p/Inputs/externs.ls -r %s \ +# RUN: --output-filetype=yaml | FileCheck %s + +defined-atoms: + - name: main + scope: global + content: [ B8, 00, 00, 00, 00, C7, 44, 24, FC, 00, 00, 00, 00, C3 ] + alignment: 2^4 + section-choice: custom-required + section-name: .text + +# CHECK: undefined-atoms: +# CHECK: - name: _foo +# CHECK: can-be-null: at-buildtime +# CHECK: - name: bar +# CHECK: can-be-null: at-buildtime +# CHECK: - name: __baz +# CHECK: can-be-null: at-buildtime diff --git a/test/elf/linkerscript/invalid-script-cli-1.test b/test/elf/linkerscript/invalid-script-cli-1.test new file mode 100644 index 000000000000..904ba17557c0 --- /dev/null +++ b/test/elf/linkerscript/invalid-script-cli-1.test @@ -0,0 +1,10 @@ +# Check that the -T/--script options issue an error when passed +# filenames for files that do not exist. + +RUN: not lld -flavor gnu -target x86_64 -T idonotexist.ls 2> %t.err +RUN: FileCheck %s < %t.err + +RUN: not lld -flavor gnu -target x86_64 --script=idonotexist.ls 2> %t.err +RUN: FileCheck %s < %t.err + +CHECK: {{.*}}lld: cannot find file {{.*}}idonotexist.ls diff --git a/test/elf/linkerscript/invalid-script-cli-2.test b/test/elf/linkerscript/invalid-script-cli-2.test new file mode 100644 index 000000000000..6e0e42adc71d --- /dev/null +++ b/test/elf/linkerscript/invalid-script-cli-2.test @@ -0,0 +1,6 @@ +# Check that linker script are *not* picked up with -lscript.ls. + +RUN: not lld -flavor gnu -target x86_64 -L%p/Inputs/ -lvalid.ls 2> %t.err +RUN: FileCheck %s < %t.err + +CHECK: {{.*}}: Unable to find library -lvalid.ls diff --git a/test/elf/linkerscript/invalid.test b/test/elf/linkerscript/invalid.test new file mode 100644 index 000000000000..42833a6664ff --- /dev/null +++ b/test/elf/linkerscript/invalid.test @@ -0,0 +1,5 @@ +# Check for errors from invalid linker scripts +RUN: not lld -flavor gnu -target x86_64 %p/Inputs/invalid.ls 2> %t.err +RUN: FileCheck %s < %t.err + +CHECK: {{.*}}invalid.ls: Error parsing linker script diff --git a/test/elf/linkerscript/sections-order.test b/test/elf/linkerscript/sections-order.test new file mode 100644 index 000000000000..85a172cb07ad --- /dev/null +++ b/test/elf/linkerscript/sections-order.test @@ -0,0 +1,97 @@ +/* +Tests a simple linker script that changes the order of output sections and +also changes the address of output sections by using simple expressions. + +This test uses three X86-64 input objects, prog1.o, prog2.o and prog3.o, +which were created with the following C or assembly code: + +*** prog1.o: + +(command line clang -c prog1.c -o prog1.o) + +const char *prog2(); +void write(int, const char *, int); + +int main() { + write(1, prog2(), 14); +} + +*** prog2.o: + +(command line clang -c prog2.c -o prog2.o) + +const char *prog2() { + return "Hello, world!\n"; +} + +*** prog3.o: + +(command line clang -c prog3.S -o prog3.o) + + .globl write +write: + mov $1, %eax + syscall + ret + + .globl _start +_start: + call main + mov $60, %eax + syscall + ret + +We use the following linker script for this test: +*/ + +ENTRY(_start) + +SECTIONS +{ + . = 0x500000; + .text : { prog1.o(.text) } + .mystring : { prog2.o(.rodata.str1.1) } + . = . + 0x6000; + .text.2 : {prog3.o(.text) prog2.o(.text) } +} + +/* +RUN: mkdir -p %T +RUN: yaml2obj -format=elf %p/Inputs/prog1.o.yaml -o=%T/prog1.o +RUN: yaml2obj -format=elf %p/Inputs/prog2.o.yaml -o=%T/prog2.o +RUN: yaml2obj -format=elf %p/Inputs/prog3.o.yaml -o=%T/prog3.o +RUN: cd %T + +RUN: lld -flavor gnu -target x86_64 -T %s prog1.o prog2.o prog3.o \ +RUN: -static -o %t1 +RUN: llvm-readobj -s %t1 | FileCheck -check-prefix CHECKSECTIONS %s + +CHECKSECTIONS: Index: 1 +CHECKSECTIONS: Name: .text +CHECKSECTIONS: Address: 0x500000 +CHECKSECTIONS: Size: 33 + +CHECKSECTIONS: Index: 2 +CHECKSECTIONS: Name: .mystring +CHECKSECTIONS: Address: 0x500021 +CHECKSECTIONS: Size: 15 + +CHECKSECTIONS: Index: 3 +CHECKSECTIONS: Name: .text.2 +CHECKSECTIONS: Address: 0x506030 +CHECKSECTIONS: Size: 48 + +RUN: llvm-readobj -symbols %t1 | FileCheck -check-prefix CHECKSYMS %s + +CHECKSYMS: Name: main +CHECKSYMS-NEXT: Value: 0x500000 + +CHECKSYMS: Name: write +CHECKSYMS-NEXT: Value: 0x506030 + +CHECKSYMS: Name: _start +CHECKSYMS-NEXT: Value: 0x506038 + +CHECKSYMS: Name: prog2 +CHECKSYMS-NEXT: Value: 0x506050 +*/ diff --git a/test/elf/linkerscript/sections-with-wildcards.test b/test/elf/linkerscript/sections-with-wildcards.test new file mode 100644 index 000000000000..6af80d0883de --- /dev/null +++ b/test/elf/linkerscript/sections-with-wildcards.test @@ -0,0 +1,88 @@ +/* +Tests a linker script that uses the SECTIONS command with rules containing +wildcards and simple SORT directives. It also tests that the linker script +evaluates the expressions in the same order as the one written in the script +file. + +This test uses three X86-64 input objects, prog1.o, prog2.o and prog3.o, +which were created with the following C or assembly code: + +*** prog1.o: + +(command line clang -c prog1.c -o prog1.o) + +const char *prog2(); +void write(int, const char *, int); + +int main() { + write(1, prog2(), 14); +} + +*** prog2.o: + +(command line clang -c prog2.c -o prog2.o) + +const char *prog2() { + return "Hello, world!\n"; +} + +*** prog3.o: + +(command line clang -c prog3.S -o prog3.o) + + .globl write +write: + mov $1, %eax + syscall + ret + + .globl _start +_start: + call main + mov $60, %eax + syscall + ret + +We use the following linker script for this test: +*/ + +ENTRY(_start) + +SECTIONS +{ + my_start_addr = 0x500000; + my_symbol = my_start_addr; + . = my_symbol; + .foo : { SORT(*)(.text .rodata*) } +} + +/* +RUN: mkdir -p %T +RUN: yaml2obj -format=elf %p/Inputs/prog1.o.yaml -o=%T/p1.o +RUN: yaml2obj -format=elf %p/Inputs/prog2.o.yaml -o=%T/p2.o +RUN: yaml2obj -format=elf %p/Inputs/prog3.o.yaml -o=%T/p3.o +RUN: cd %T + +RUN: lld -flavor gnu -target x86_64 -T %s p1.o p2.o p3.o \ +RUN: -static -o %t1 +RUN: llvm-readobj -s %t1 | FileCheck -check-prefix CHECKSECTIONS %s + +CHECKSECTIONS: Index: 1 +CHECKSECTIONS: Name: .foo +CHECKSECTIONS: Address: 0x500000 +CHECKSECTIONS: Size: 101 + +RUN: llvm-readobj -symbols %t1 | FileCheck -check-prefix CHECKSYMS %s + +CHECKSYMS: Name: main +CHECKSYMS-NEXT: Value: 0x500000 + +CHECKSYMS: Name: prog2 +CHECKSYMS-NEXT: Value: 0x500030 + +CHECKSYMS: Name: write +CHECKSYMS-NEXT: Value: 0x500050 + +CHECKSYMS: Name: _start +CHECKSYMS-NEXT: Value: 0x500058 +*/ diff --git a/test/elf/linkerscript/symbol-definition.test b/test/elf/linkerscript/symbol-definition.test new file mode 100644 index 000000000000..fc595bbe1f10 --- /dev/null +++ b/test/elf/linkerscript/symbol-definition.test @@ -0,0 +1,54 @@ +/* +We test whether we can define symbols in a linker script and have them exported +to the output file symbol table. + +This test uses a single X86-64 input object, simple.o, created with the +following X86-64 assembly code: + +*** simple.S: + +(command line clang -c simple.S -o simple.o) + + .text + main: + mov $1, %eax + movq $1, %rdi + movq $msg, %rsi + movq $14, %rdx + syscall + ret + + .globl _start + _start: + call main + mov $60, %eax + syscall + ret + + .data + msg: .asciz "Hello, World!\n" + + +We use the following linker script for this test: +*/ + +ENTRY(_start) + +SECTIONS +{ + . = 0x500000; + .text : { *(.text) } + MYSTRING = .; + .data : { *(.data) } +} + +/* +RUN: mkdir -p %T +RUN: yaml2obj -format=elf %p/Inputs/simple.o.yaml -o=%T/simple.o + +RUN: lld -flavor gnu -target x86_64 -T %s %T/simple.o -static -o %t1 +RUN: llvm-readobj -symbols %t1 | FileCheck -check-prefix CHECKSYMS %s + +CHECKSYMS: Name: MYSTRING +CHECKSYMS-NEXT: Value: 0x501000 +*/ diff --git a/test/elf/linkerscript/valid-script-cli.objtxt b/test/elf/linkerscript/valid-script-cli.objtxt new file mode 100644 index 000000000000..b68d430fd98e --- /dev/null +++ b/test/elf/linkerscript/valid-script-cli.objtxt @@ -0,0 +1,23 @@ +# Check that the linker script inputs are accepted properly. + +# RUN: lld -flavor gnu -target x86_64 %p/Inputs/valid.ls -r %s \ +# RUN: --output-filetype=yaml | FileCheck %s + +# RUN: lld -flavor gnu -target x86_64 -T %p/Inputs/valid.ls -r %s \ +# RUN: --output-filetype=yaml | FileCheck %s + +# RUN: lld -flavor gnu -target x86_64 --script=%p/Inputs/valid.ls -r %s \ +# RUN: --output-filetype=yaml | FileCheck %s + +# RUN: lld -flavor gnu -target x86_64 -L%p/Inputs/ -l:valid.ls -r %s \ +# RUN: --output-filetype=yaml | FileCheck %s + +defined-atoms: + - name: main + scope: global + content: [ B8, 00, 00, 00, 00, C7, 44, 24, FC, 00, 00, 00, 00, C3 ] + alignment: 2^4 + section-choice: custom-required + section-name: .text + +# CHECK: _entry_point diff --git a/test/elf/loginputfiles.test b/test/elf/loginputfiles.test new file mode 100644 index 000000000000..850570d8085e --- /dev/null +++ b/test/elf/loginputfiles.test @@ -0,0 +1,28 @@ +# Tests functionality of -t +# +# Tests generated using the source files below +# main file +# int main() +# { +# fn(); +# return 0; +# } +# +# archive file +# int fn() +# { +# return 0; +# } +# +# int fn1() +# { +# return 0; +# } +# gcc -c main.c fn.c fn1.c + +RUN: lld -flavor gnu -target x86_64-linux \ +RUN: %p/Inputs/mainobj.x86_64 %p/Inputs/libfnarchive.a -t --noinhibit-exec 2>&1 | \ +RUN: FileCheck -check-prefix INPUTFILES %s + +#INPUTFILES: mainobj.x86_64 +#INPUTFILES: libfnarchive.a(fn.o) diff --git a/test/elf/mergeatoms.test b/test/elf/mergeatoms.test new file mode 100644 index 000000000000..521eb5a12c3c --- /dev/null +++ b/test/elf/mergeatoms.test @@ -0,0 +1,6 @@ +# Tests that atoms are merged by testing it with --merge-strings option +RUN: lld -flavor gnu -target x86_64-linux --merge-strings -o %t1 \ +RUN: %p/Inputs/foo.o.x86-64 %p/Inputs/bar.o.x86-64 -e bar1 +RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=mergeAtoms %s + +mergeAtoms: 62617200 666f6f00 bar.foo. diff --git a/test/elf/mergeconstants.test b/test/elf/mergeconstants.test new file mode 100644 index 000000000000..3d06d2c94438 --- /dev/null +++ b/test/elf/mergeconstants.test @@ -0,0 +1,20 @@ +# The test checks for mergeable strings that appear in the object file +RUN: lld -flavor gnu --merge-strings --output-filetype=yaml -target x86_64 \ +RUN: %p/Inputs/constants-merge.x86-64 --noinhibit-exec \ +RUN: | FileCheck -check-prefix=mergeAtoms %s + +mergeAtoms: - ref-name: [[CONSTANT:[-a-zA-Z0-9_]+]] +mergeAtoms: type: constant +mergeAtoms: content: [ 62, 61, 72, 66, 6F, 6F, 00 ] +mergeAtoms: merge: by-content +mergeAtoms: section-choice: custom-required +mergeAtoms: section-name: .rodata.str1.1 +mergeAtoms: - name: foo +mergeAtoms: scope: global +mergeAtoms: type: data +mergeAtoms: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +mergeAtoms: alignment: 2^3 +mergeAtoms: references: +mergeAtoms: - kind: R_X86_64_64 +mergeAtoms: offset: 3 +mergeAtoms: target: [[CONSTANT]] diff --git a/test/elf/mergeglobalatoms.test b/test/elf/mergeglobalatoms.test new file mode 100644 index 000000000000..e71dca539915 --- /dev/null +++ b/test/elf/mergeglobalatoms.test @@ -0,0 +1,11 @@ +# ELF files can have mergeable strings which are global!, treat them as global +# defined atoms +RUN: lld -flavor gnu --output-filetype=yaml %p/Inputs/globalconst.o.x86-64 \ +RUN: --noinhibit-exec -target x86_64 | FileCheck -check-prefix=globalatoms %s + +globalatoms: - name: mystr +globalatoms: scope: global +globalatoms: type: constant +globalatoms: content: [ 66, 6F, 6F, 62, 61, 72, 00 ] +globalatoms: section-choice: custom-required +globalatoms: section-name: .rodata.str1.1 diff --git a/test/elf/note.test b/test/elf/note.test new file mode 100644 index 000000000000..f0e9c6b2f8d9 --- /dev/null +++ b/test/elf/note.test @@ -0,0 +1,49 @@ +# Check that the linker is not ignoring input sections. +# RUN: yaml2obj -format=elf %s > %t.obj +# RUN: lld -flavor gnu -target x86_64 %t.obj -o %t.exe --noinhibit-exec +# RUN: llvm-objdump -h %t.exe | FileCheck %s + +# CHECK: {{[0-9]+}} .note + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .note + Type: SHT_NOTE + AddressAlign: 0x0000000000000001 + Content: '00' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .note + Type: STT_SECTION + Section: .note +... diff --git a/test/elf/options/dynamic-linker.test b/test/elf/options/dynamic-linker.test new file mode 100644 index 000000000000..3d8feeb6e307 --- /dev/null +++ b/test/elf/options/dynamic-linker.test @@ -0,0 +1,17 @@ +# This tests the functionality of specifying dynamic-linker argument in the +# command line +RUN: lld -flavor gnu -target x86_64 --dynamic-linker="/xyz.so" \ +RUN: %p/../Inputs/foo.o.x86-64 --noinhibit-exec -o %t +RUN: llvm-objdump -s %t | FileCheck -check-prefix=DYNAMICINTERP1 %s +RUN: lld -flavor gnu -target x86_64 --dynamic-linker="" \ +RUN: %p/../Inputs/foo.o.x86-64 --noinhibit-exec -o %t1 +RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=DYNAMICINTERP2 %s +RUN: lld -flavor gnu -target x86_64 -dynamic-linker /xyz.so \ +RUN: %p/../Inputs/foo.o.x86-64 --noinhibit-exec -o %t2 +RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=DYNAMICINTERP1 %s + +DYNAMICINTERP1:Contents of section .interp: +DYNAMICINTERP1: 400158 2f78797a 2e736f00 /xyz.so. +DYNAMICINTERP2:Contents of section .interp: +DYNAMICINTERP2: 400158 00 + diff --git a/test/elf/phdr.test b/test/elf/phdr.test new file mode 100644 index 000000000000..c8ab73d31464 --- /dev/null +++ b/test/elf/phdr.test @@ -0,0 +1,99 @@ +# This test checks emission for program header for ELF binaries +RUN: lld -flavor gnu -target i386-linux -o %t1 -e main %p/Inputs/phdr.i386 \ +RUN: && llvm-readobj -program-headers %t1 | FileCheck -check-prefix=I386 %s +RUN: lld -flavor gnu -target x86_64-linux -o %t1 -e _start %p/Inputs/relocs.x86-64 -static \ +RUN: && llvm-objdump -p %t1 | FileCheck %s -check-prefix=X86_64 + + +I386: ProgramHeaders [ +I386-NEXT: ProgramHeader { +I386-NEXT: Type: PT_PHDR (0x6) +I386-NEXT: Offset: 0x34 +I386-NEXT: VirtualAddress: 0x34 +I386-NEXT: PhysicalAddress: 0x34 +I386-NEXT: FileSize: 224 +I386-NEXT: MemSize: 224 +I386-NEXT: Flags [ (0x5) +I386-NEXT: PF_R (0x4) +I386-NEXT: PF_X (0x1) +I386-NEXT: ] +I386-NEXT: Alignment: 8 +I386-NEXT: } +I386-NEXT: ProgramHeader { +I386-NEXT: Type: PT_INTERP (0x3) +I386-NEXT: Offset: 0x114 +I386-NEXT: VirtualAddress: 0x114 +I386-NEXT: PhysicalAddress: 0x114 +I386-NEXT: FileSize: 28 +I386-NEXT: MemSize: 28 +I386-NEXT: Flags [ (0x4) +I386-NEXT: PF_R (0x4) +I386-NEXT: ] +I386-NEXT: Alignment: 1 +I386-NEXT: } +I386-NEXT: ProgramHeader { +I386-NEXT: Type: PT_LOAD (0x1) +I386-NEXT: Offset: 0x0 +I386-NEXT: VirtualAddress: 0x0 +I386-NEXT: PhysicalAddress: 0x0 +I386-NEXT: FileSize: 556 +I386-NEXT: MemSize: 556 +I386-NEXT: Flags [ (0x5) +I386-NEXT: PF_R (0x4) +I386-NEXT: PF_X (0x1) +I386-NEXT: ] +I386-NEXT: Alignment: 4096 +I386-NEXT: } +I386-NEXT: ProgramHeader { +I386-NEXT: Type: PT_LOAD (0x1) +I386-NEXT: Offset: 0x1000 +I386-NEXT: VirtualAddress: 0x1000 +I386-NEXT: PhysicalAddress: 0x1000 +I386-NEXT: FileSize: 260 +I386-NEXT: MemSize: 260 +I386-NEXT: Flags [ (0x6) +I386-NEXT: PF_R (0x4) +I386-NEXT: PF_W (0x2) +I386-NEXT: ] +I386-NEXT: Alignment: 4096 +I386-NEXT: } +I386-NEXT: ProgramHeader { +I386-NEXT: Type: PT_LOAD (0x1) +I386-NEXT: Offset: 0x4000 +I386-NEXT: VirtualAddress: 0x4000 +I386-NEXT: PhysicalAddress: 0x4000 +I386-NEXT: FileSize: 4 +I386-NEXT: MemSize: 8 +I386-NEXT: Flags [ (0x6) +I386-NEXT: PF_R (0x4) +I386-NEXT: PF_W (0x2) +I386-NEXT: ] +I386-NEXT: Alignment: 16384 +I386-NEXT: } +I386-NEXT: ProgramHeader { +I386-NEXT: Type: PT_DYNAMIC (0x2) +I386-NEXT: Offset: 0x1FC +I386-NEXT: VirtualAddress: 0x1FC +I386-NEXT: PhysicalAddress: 0x1FC +I386-NEXT: FileSize: 48 +I386-NEXT: MemSize: 48 +I386-NEXT: Flags [ (0x4) +I386-NEXT: PF_R (0x4) +I386-NEXT: ] +I386-NEXT: Alignment: 4 +I386-NEXT: } +I386-NEXT: ProgramHeader { +I386-NEXT: Type: PT_GNU_EH_FRAME (0x6474E550) +I386-NEXT: Offset: 0x1F4 +I386-NEXT: VirtualAddress: 0x1F4 +I386-NEXT: PhysicalAddress: 0x1F4 +I386-NEXT: FileSize: 8 +I386-NEXT: MemSize: 8 +I386-NEXT: Flags [ (0x4) +I386-NEXT: PF_R (0x4) +I386-NEXT: ] +I386-NEXT: Alignment: 4 +I386-NEXT: } + +X86_64: LOAD off 0x0000000000000000 +X86_64: LOAD off 0x0000000000001000 diff --git a/test/elf/quickdata.test b/test/elf/quickdata.test new file mode 100644 index 000000000000..a07771517226 --- /dev/null +++ b/test/elf/quickdata.test @@ -0,0 +1,15 @@ +RUN: lld -flavor gnu -target hexagon --output-filetype=yaml %p/Inputs/quickdata-test.elf-hexagon \ +RUN: --noinhibit-exec | FileCheck %s -check-prefix hexagon + +hexagon: - name: ac1 +hexagon: scope: global +hexagon: type: zero-fill-quick +hexagon: size: 1 +hexagon: merge: as-tentative +hexagon: - name: init +hexagon: scope: global +hexagon: type: quick-data +hexagon: - name: bss1 +hexagon: scope: global +hexagon: type: zero-fill-quick + diff --git a/test/elf/reloc.test b/test/elf/reloc.test new file mode 100644 index 000000000000..0ecf0b174fe8 --- /dev/null +++ b/test/elf/reloc.test @@ -0,0 +1,38 @@ +RUN: lld -flavor gnu -target i386 --merge-strings -r --output-filetype=yaml \ +RUN: %p/Inputs/reloc-test.elf-i386 | FileCheck %s -check-prefix ELF-i386 + +ELF-i386: defined-atoms: +ELF-i386: - ref-name: [[STRNAMEA:[-a-zA-Z0-9_]+]] +ELF-i386: type: constant +ELF-i386: content: [ 68, 65, 6C, 6C, 6F, 20, 77, 6F, 72, 6C, 64, 00 ] +ELF-i386: merge: by-content +ELF-i386: - ref-name: [[STRNAMEB:[-a-zA-Z0-9_]+]] +ELF-i386: alignment: 2^4 +ELF-i386: section-choice: custom-required +ELF-i386: section-name: .text.startup +ELF-i386: references: +ELF-i386: - kind: layout-after +ELF-i386: offset: 0 +ELF-i386: target: main +ELF-i386: - name: main +ELF-i386: scope: global +ELF-i386: content: [ 55, 89, E5, 83, E4, F0, 83, EC, 10, C7, 04, 24, +ELF-i386: 00, 00, 00, 00, E8, FC, FF, FF, FF, 31, C0, C9, +ELF-i386: C3 ] +ELF-i386: alignment: 2^4 +ELF-i386: section-choice: custom-required +ELF-i386: section-name: .text.startup +ELF-i386: references: +ELF-i386: - kind: R_386_32 +ELF-i386: offset: 12 +ELF-i386: target: [[STRNAMEA]] +ELF-i386: - kind: R_386_PC32 +ELF-i386: offset: 17 +ELF-i386: target: puts +ELF-i386: addend: 252 +ELF-i386: undefined-atoms: +ELF-i386: - name: puts +ELF-i386: absolute-atoms: +ELF-i386: - name: test.c +ELF-i386: scope: static +ELF-i386: value: 0x0000000000000000 diff --git a/test/elf/responsefile.test b/test/elf/responsefile.test new file mode 100644 index 000000000000..5957471bb661 --- /dev/null +++ b/test/elf/responsefile.test @@ -0,0 +1,6 @@ +# RUN: not lld -flavor gnu --abc @%p/Inputs/responsefile --baz >& %t.log +# RUN: FileCheck %s < %t.log + +CHECK: warning: ignoring unknown argument: --abc +CHECK: warning: ignoring unknown argument: --inresponsefile +CHECK: warning: ignoring unknown argument: --baz diff --git a/test/elf/rodata.test b/test/elf/rodata.test new file mode 100644 index 000000000000..dfe6985c0733 --- /dev/null +++ b/test/elf/rodata.test @@ -0,0 +1,5 @@ +RUN: lld -flavor gnu -target x86_64-linux -o %t %p/Inputs/constdata.x86-64 \ +RUN: -static -e _start +RUN: llvm-objdump -s %t | FileCheck %s + +CHECK: Hellooooooooo diff --git a/test/elf/rosegment.test b/test/elf/rosegment.test new file mode 100644 index 000000000000..32638d8fce6f --- /dev/null +++ b/test/elf/rosegment.test @@ -0,0 +1,26 @@ +# Tests that the option --rosegment produces an output file with a separate +# segment created for read only data. +RUN: lld -flavor gnu -target x86_64 %p/Inputs/rodata.o -o %t1.elf \ +RUN: --noinhibit-exec +RUN: lld -flavor gnu -target x86_64 %p/Inputs/rodata.o --rosegment -o %t2.elf \ +RUN: --noinhibit-exec +RUN: llvm-readobj -program-headers %t1.elf | FileCheck %s -check-prefix=NORO-SEGMENT +RUN: llvm-readobj -program-headers %t2.elf | FileCheck %s -check-prefix=RO-SEGMENT + +#NORO-SEGMENT: Type: PT_PHDR +#NORO-SEGMENT: Type: PT_INTERP +#NORO-SEGMENT: Type: PT_LOAD +#NORO-SEGMENT: Type: PT_LOAD +#NORO-SEGMENT: Type: PT_DYNAMIC +#NORO-SEGMENT: Type: PT_GNU_EH_FRAME + +#RO-SEGMENT: Type: PT_PHDR +#RO-SEGMENT: Type: PT_INTERP +#RO-SEGMENT: Type: PT_LOAD +#RO-SEGMENT: Type: PT_LOAD +#RO-SEGMENT: Flags [ +#RO-SEGMENT: PF_R (0x4) +#RO-SEGMENT: ] +#RO-SEGMENT: Type: PT_LOAD +#RO-SEGMENT: Type: PT_DYNAMIC +#RO-SEGMENT: Type: PT_GNU_EH_FRAME diff --git a/test/elf/sectionGroups/sectiongroup-new-members.test b/test/elf/sectionGroups/sectiongroup-new-members.test new file mode 100644 index 000000000000..d270c5fec94a --- /dev/null +++ b/test/elf/sectionGroups/sectiongroup-new-members.test @@ -0,0 +1,153 @@ +# Checks that the linker picks the first group in the output file when the file +# have some members dont appear in the first group. +# 1a.s +# ------ +# +# .section .text,"axG",%progbits,foo_group,comdat +# .weak foo +#foo: +# .word 0 +# 1b.s +# ----- +# .section .text,"axG",%progbits,foo_group,comdat +# .global foo +# .global bar +#foo: +# .word 0 +#bar: +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.group1a.o +#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.group1b.o +#RUN: lld -flavor gnu -target x86_64 %t.group1a.o %t.group1b.o \ +#RUN: --noinhibit-exec --output-filetype=yaml -o %t2.out.yaml +#RUN: lld -flavor gnu -target x86_64 %t.group1a.o %t.group1b.o \ +#RUN: --noinhibit-exec -o %t2.out +#RUN: FileCheck %s -check-prefix=CHECKGROUP < %t2.out.yaml +#RUN: llvm-readobj -sections %t2.out | FileCheck %s -check-prefix=CHECKGROUPSECTIONS +#RUN: llvm-readobj -symbols %t2.out | FileCheck %s -check-prefix=CHECKSYMBOLS +#CHECKGROUP: - name: foo +#CHECKGROUP: scope: global +#CHECKGROUP: merge: as-weak +#CHECKGROUP: section-name: .text +#CHECKGROUP: - name: foo_group +#CHECKGROUP: scope: global +#CHECKGROUP: type: group-comdat +#CHECKGROUP: section-choice: custom-required +#CHECKGROUP: section-name: .group +#CHECKGROUP: permissions: --- +#CHECKGROUP: references: +#CHECKGROUP: - kind: group-child +#CHECKGROUP: offset: 0 +#CHECKGROUP: target: foo +#CHECKGROUPSECTIONS: Section { +#CHECKGROUPSECTIONS: Name: .text +#CHECKGROUPSECTIONS: Type: SHT_PROGBITS +#CHECKGROUPSECTIONS: Flags [ (0x6) +#CHECKGROUPSECTIONS: SHF_ALLOC (0x2) +#CHECKGROUPSECTIONS: SHF_EXECINSTR (0x4) +#CHECKGROUPSECTIONS: ] +#CHECKGROUPSECTIONS: Size: 2 +#CHECKGROUPSECTIONS: AddressAlignment: 1 +#CHECKGROUPSECTIONS: } +#CHECKSYMBOLS: Name: foo +#CHECKSYMBOLS: Type: Function +#CHECKSYMBOLS: Section: .text +#CHECKSYMBOLS-NOT: Name: bar +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: foo_group + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .text + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '0000' +Symbols: + Local: + - Name: foo_group + Section: .group + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Weak: + - Name: foo + Section: .text +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: foo_group + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .text + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '0000' +Symbols: + Local: + - Name: foo_group + Section: .group + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: bar + Section: .text + Value: 0x0000000000000002 + - Name: foo + Section: .text +... diff --git a/test/elf/sectionGroups/sectiongroup-simple.test b/test/elf/sectionGroups/sectiongroup-simple.test new file mode 100644 index 000000000000..25be6033b0ef --- /dev/null +++ b/test/elf/sectionGroups/sectiongroup-simple.test @@ -0,0 +1,146 @@ +# Checks that the linker picks the first group in the output file when the file +# have some members dont appear in the first group. +# 1a.s +# ------ +# .section .text,"axG",%progbits,foo_group,comdat +# .weak foo +#foo: +# .word 0 +# 1b.s +# ----- +# .section .text,"axG",%progbits,foo_group,comdat +# .global bar +#bar: +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.group1a.o +#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.group1b.o +#RUN: lld -flavor gnu -target x86_64 %t.group1a.o %t.group1b.o \ +#RUN: --noinhibit-exec --output-filetype=yaml -o %t2.out.yaml +#RUN: lld -flavor gnu -target x86_64 %t.group1a.o %t.group1b.o \ +#RUN: --noinhibit-exec -o %t2.out +#RUN: FileCheck %s -check-prefix=CHECKGROUP < %t2.out.yaml +#RUN: llvm-readobj -sections %t2.out | FileCheck %s -check-prefix=CHECKGROUPSECTIONS +#RUN: llvm-readobj -symbols %t2.out | FileCheck %s -check-prefix=CHECKSYMBOLS +#CHECKGROUP: - name: foo +#CHECKGROUP: scope: global +#CHECKGROUP: merge: as-weak +#CHECKGROUP: section-name: .text +#CHECKGROUP: - name: foo_group +#CHECKGROUP: scope: global +#CHECKGROUP: type: group-comdat +#CHECKGROUP: section-choice: custom-required +#CHECKGROUP: section-name: .group +#CHECKGROUP: permissions: --- +#CHECKGROUP: references: +#CHECKGROUP: - kind: group-child +#CHECKGROUP: offset: 0 +#CHECKGROUP: target: foo +#CHECKGROUPSECTIONS: Section { +#CHECKGROUPSECTIONS: Name: .text +#CHECKGROUPSECTIONS: Type: SHT_PROGBITS +#CHECKGROUPSECTIONS: Flags [ (0x6) +#CHECKGROUPSECTIONS: SHF_ALLOC (0x2) +#CHECKGROUPSECTIONS: SHF_EXECINSTR (0x4) +#CHECKGROUPSECTIONS: ] +#CHECKGROUPSECTIONS: Size: 2 +#CHECKGROUPSECTIONS: AddressAlignment: 1 +#CHECKGROUPSECTIONS: } +#CHECKSYMBOLS: Name: foo +#CHECKSYMBOLS: Type: Function +#CHECKSYMBOLS: Section: .text + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: foo_group + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .text + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '0000' +Symbols: + Local: + - Name: foo_group + Section: .group + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Weak: + - Name: foo + Section: .text +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: foo_group + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .text + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Local: + - Name: foo_group + Section: .group + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: bar + Section: .text +... diff --git a/test/elf/sectionGroups/sectiongroup-undef-member-other.test b/test/elf/sectionGroups/sectiongroup-undef-member-other.test new file mode 100644 index 000000000000..78a5f276a4ca --- /dev/null +++ b/test/elf/sectionGroups/sectiongroup-undef-member-other.test @@ -0,0 +1,158 @@ +# Tests that linker throws an error for an undefined symbol in the section +# group, which is the same as the signature in the next input file. +# comdat1.s +# ------------ +# .section .foo,"axG",@progbits,g1,comdat +# .word g1 +#comdat2.s +#----------- +# .global g1 +# .section .bar,"axG",@progbits,g1,comdat +#g2: +# nop +# .section .car,"axG",@progbits,g1,comdat +#g3: +# nop +# +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.group1a.o +#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.group1b.o +#RUN: lld -flavor gnu -target x86_64 %t.group1a.o %t.group1b.o \ +#RUN: --noinhibit-exec -o %t2.out 2>&1 | FileCheck %s +#CHECK: Undefined symbol: {{.*}} g1 +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: g1 + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .foo + - SectionOrType: .rela.foo + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '0000' + - Name: .rela.foo + Type: SHT_RELA + Flags: [ SHF_GROUP ] + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .foo + Relocations: + - Offset: 0x0000000000000000 + Symbol: g1 + Type: R_X86_64_16 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .foo + Type: STT_SECTION + Section: .foo + - Name: .group + Type: STT_SECTION + Section: .group + Global: + - Name: g1 +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: g1 + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .bar + - SectionOrType: .car + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bar + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '90' + - Name: .car + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '90' +Symbols: + Local: + - Name: g2 + Section: .bar + - Name: g3 + Section: .car + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .bar + Type: STT_SECTION + Section: .bar + - Name: .car + Type: STT_SECTION + Section: .car + - Name: .group + Type: STT_SECTION + Section: .group + Global: + - Name: g1 + Section: .group +... diff --git a/test/elf/sectionGroups/sectiongroup-undef-member.test b/test/elf/sectionGroups/sectiongroup-undef-member.test new file mode 100644 index 000000000000..2f6804d254d8 --- /dev/null +++ b/test/elf/sectionGroups/sectiongroup-undef-member.test @@ -0,0 +1,144 @@ +# Tests that linker throws an error for an undefined symbol in the section +# group. +# +#comdata.s +#------------ +# .section .foo,"axG",@progbits,g1,comdat +# .word g1 +# +#comdatb.s +#------------ +# .global g1 +# .section .foo,"axG",@progbits,g1,comdat +#g1: +# nop +# +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.group1a.o +#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.group1b.o +#RUN: lld -flavor gnu -target x86_64 %t.group1a.o %t.group1b.o \ +#RUN: --noinhibit-exec -o %t2.out 2>&1 | FileCheck %s +#CHECK: Undefined symbol: {{.*}} g1 +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: g1 + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .foo + - SectionOrType: .rela.foo + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '0000' + - Name: .rela.foo + Type: SHT_RELA + Flags: [ SHF_GROUP ] + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .foo + Relocations: + - Offset: 0x0000000000000000 + Symbol: g1 + Type: R_X86_64_16 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .foo + Type: STT_SECTION + Section: .foo + - Name: .group + Type: STT_SECTION + Section: .group + Global: + - Name: g1 +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: g1 + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .foo + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '90' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .foo + Type: STT_SECTION + Section: .foo + - Name: .group + Type: STT_SECTION + Section: .group + Global: + - Name: g1 + Section: .foo +... diff --git a/test/elf/sectionGroups/sectiongroup-with-globalsymbols.test b/test/elf/sectionGroups/sectiongroup-with-globalsymbols.test new file mode 100644 index 000000000000..0a28e3c98907 --- /dev/null +++ b/test/elf/sectionGroups/sectiongroup-with-globalsymbols.test @@ -0,0 +1,253 @@ +# This tests that comdat weak symbol can be overridden by a global symbol. +# comdat1.s +#------------------------ +# .weak g1 +# .section .foo,"axG",@progbits,g1,comdat +#g1: +# nop +# .global g2 +#g2: +# nop +#! +# +#comdat2.s << \! +#----------------- +# .global g1 +# .section .foo,"axG",@progbits,g1,comdat +#g1: +# nop +# .global g2 +#g2: +# nop +# +#cat > g1.c << \! +#int g1() { +# return 0; +#} +# +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.comdat1.o +#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.comdat2.o +#RUN: yaml2obj -format=elf -docnum 3 %s -o %t.g1.o +#RUN: lld -flavor gnu -target x86_64 %t.comdat1.o %t.comdat2.o \ +#RUN: %t.g1.o --noinhibit-exec --output-filetype=yaml -o %t2.out.yaml +#RUN: lld -flavor gnu -target x86_64 %t.comdat1.o %t.comdat2.o \ +#RUN: %t.g1.o --noinhibit-exec -o %t2.out +#RUN: FileCheck %s -check-prefix=CHECKGROUP < %t2.out.yaml +#RUN: llvm-readobj -sections %t2.out | FileCheck %s -check-prefix=CHECKGROUPSECTIONS +#RUN: llvm-readobj -symbols %t2.out | FileCheck %s -check-prefix=CHECKSYMBOLS +#CHECKGROUP: - name: g2 +#CHECKGROUP: content: [ 90 ] +#CHECKGROUP: section-choice: custom-required +#CHECKGROUP: section-name: .foo +#CHECKGROUP: - name: g1 +#CHECKGROUP: scope: global +#CHECKGROUP: content: [ 55, 48, 89, E5, 31, C0, 5D, C3 ] +#CHECKGROUP: alignment: 2^4 +#CHECKGROUP: section-name: .text +#CHECKGROUPSECTIONS: Name: .text +#CHECKGROUPSECTIONS: Type: SHT_PROGBITS +#CHECKGROUPSECTIONS: Flags [ +#CHECKGROUPSECTIONS: SHF_ALLOC +#CHECKGROUPSECTIONS: SHF_EXECINSTR +#CHECKGROUPSECTIONS: ] +#CHECKGROUPSECTIONS: Size: 8 +#CHECKGROUPSECTIONS: Name: .foo +#CHECKGROUPSECTIONS: Type: SHT_PROGBITS +#CHECKGROUPSECTIONS: Flags [ +#CHECKGROUPSECTIONS: SHF_ALLOC +#CHECKGROUPSECTIONS: SHF_EXECINSTR +#CHECKGROUPSECTIONS: ] +#CHECKGROUPSECTIONS: Size: 2 +#CHECKSYMBOLS: Name: g2 +#CHECKSYMBOLS: Section: .foo +#CHECKSYMBOLS: Name: g1 +#CHECKSYMBOLS: Section: .text +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: g1 + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .foo + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '9090' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .foo + Type: STT_SECTION + Section: .foo + Global: + - Name: g2 + Section: .foo + Value: 0x0000000000000001 + Weak: + - Name: g1 + Section: .foo +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: g1 + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .foo + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '9090' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .foo + Type: STT_SECTION + Section: .foo + Global: + - Name: g1 + Section: .foo + - Name: g2 + Section: .foo + Value: 0x0000000000000001 +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E531C05DC3 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 00636C616E672076657273696F6E20332E372E3020287472756E6B203232393535372920286C6C766D2F7472756E6B203232393536332900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C0708900100001C0000001C000000000000000800000000410E108602430D0600000000000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 +Symbols: + Local: + - Name: g1.c + Type: STT_FILE + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: g1 + Type: STT_FUNC + Section: .text + Size: 0x0000000000000008 +... diff --git a/test/elf/sectionGroups/sectiongroup-with-undef-external-reference.test b/test/elf/sectionGroups/sectiongroup-with-undef-external-reference.test new file mode 100644 index 000000000000..a90034ae6d21 --- /dev/null +++ b/test/elf/sectionGroups/sectiongroup-with-undef-external-reference.test @@ -0,0 +1,239 @@ +# This tests that comdat undef symbol is overridden by a global symbol. +# comdat1.s +#------------------------ +# .global g1 +# .section .foo,"axG",@progbits,g1,comdat +#g1: +# .word 5 +# +#comdat2.s << \! +#----------------- +# .global g1 +# .section .foo,"axG",@progbits,g1,comdat +#g1: +# nop +# +#g1.c +#----------- +#extern int g1; +#int fn() { return g1;} +# +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.comdat1.o +#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.comdat2.o +#RUN: yaml2obj -format=elf -docnum 3 %s -o %t.g1.o +#RUN: lld -flavor gnu -target x86_64 %t.comdat1.o %t.comdat2.o \ +#RUN: %t.g1.o --noinhibit-exec --output-filetype=yaml -o %t2.out.yaml +#RUN: lld -flavor gnu -target x86_64 %t.comdat1.o %t.comdat2.o \ +#RUN: %t.g1.o --noinhibit-exec -o %t2.out +#RUN: FileCheck %s -check-prefix=CHECKGROUP < %t2.out.yaml +#RUN: llvm-readobj -sections %t2.out | FileCheck %s -check-prefix=CHECKGROUPSECTIONS +#RUN: llvm-readobj -symbols %t2.out | FileCheck %s -check-prefix=CHECKSYMBOLS +#CHECKGROUP: - name: g1 +#CHECKGROUP: scope: global +#CHECKGROUP: content: [ 05, 00 ] +#CHECKGROUP: section-name: .foo +#CHECKGROUPSECTIONS: Section { +#CHECKGROUPSECTIONS: Name: .foo +#CHECKGROUPSECTIONS: Type: SHT_PROGBITS +#CHECKGROUPSECTIONS: Flags [ +#CHECKGROUPSECTIONS: SHF_ALLOC +#CHECKGROUPSECTIONS: SHF_EXECINSTR +#CHECKGROUPSECTIONS: ] +#CHECKGROUPSECTIONS: Size: 2 +#CHECKGROUPSECTIONS: } +#CHECKSYMBOLS: Name: g1 +#CHECKSYMBOLS: Section: .foo +#CHECKSYMBOLS: Name: fn +#CHECKSYMBOLS: Section: .text +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: g1 + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .foo + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '0500' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .foo + Type: STT_SECTION + Section: .foo + Global: + - Name: g1 + Section: .foo +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: g1 + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .foo + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '90' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .foo + Type: STT_SECTION + Section: .foo + Global: + - Name: g1 + Section: .foo +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E58B0425000000005DC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000007 + Symbol: g1 + Type: R_X86_64_32S + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 00636C616E672076657273696F6E20332E372E3020287472756E6B203232393535372920286C6C766D2F7472756E6B203232393536332900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C0708900100001C0000001C000000000000000D00000000410E108602430D0600000000000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 +Symbols: + Local: + - Name: global-g1.c + Type: STT_FILE + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: fn + Type: STT_FUNC + Section: .text + Size: 0x000000000000000D + - Name: g1 +... diff --git a/test/elf/sectionGroups/sectiongroup-with-undef-signature.test b/test/elf/sectionGroups/sectiongroup-with-undef-signature.test new file mode 100644 index 000000000000..11cb5de40a63 --- /dev/null +++ b/test/elf/sectionGroups/sectiongroup-with-undef-signature.test @@ -0,0 +1,222 @@ +# This tests that comdat undef symbol is overridden by a global symbol. +# comdat1.s +#------------------------ +# .section .foo,"axG",@progbits,g1,comdat +# word g1 +# +#comdat2.s << \! +#----------------- +# .global g1 +# .section .foo,"axG",@progbits,g1,comdat +#g1: +# nop +# +#global-g1.c +#----------- +#int g1=10; +# +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.comdat1.o +#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.comdat2.o +#RUN: yaml2obj -format=elf -docnum 3 %s -o %t.g1.o +#RUN: lld -flavor gnu -target x86_64 %t.comdat1.o %t.comdat2.o \ +#RUN: %t.g1.o --noinhibit-exec --output-filetype=yaml -o %t2.out.yaml +#RUN: lld -flavor gnu -target x86_64 %t.comdat1.o %t.comdat2.o \ +#RUN: %t.g1.o --noinhibit-exec -o %t2.out +#RUN: FileCheck %s -check-prefix=CHECKGROUP < %t2.out.yaml +#RUN: llvm-readobj -sections %t2.out | FileCheck %s -check-prefix=CHECKGROUPSECTIONS +#RUN: llvm-readobj -symbols %t2.out | FileCheck %s -check-prefix=CHECKSYMBOLS +#CHECKGROUP: - name: g1 +#CHECKGROUP: scope: global +#CHECKGROUP: content: [ 0A, 00, 00, 00 ] +#CHECKGROUP: section-name: .data +#CHECKGROUPSECTIONS: Name: .foo +#CHECKGROUPSECTIONS: Type: SHT_PROGBITS +#CHECKGROUPSECTIONS: Flags [ +#CHECKGROUPSECTIONS: SHF_ALLOC +#CHECKGROUPSECTIONS: SHF_EXECINSTR +#CHECKGROUPSECTIONS: ] +#CHECKGROUPSECTIONS: Size: 2 +#CHECKGROUPSECTIONS: Name: .data +#CHECKGROUPSECTIONS: Type: SHT_PROGBITS +#CHECKGROUPSECTIONS: Flags [ +#CHECKGROUPSECTIONS: SHF_ALLOC +#CHECKGROUPSECTIONS: SHF_WRITE +#CHECKGROUPSECTIONS: ] +#CHECKGROUPSECTIONS: Size: 4 +#CHECKSYMBOLS: Name: g1 +#CHECKSYMBOLS: Section: .data +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: g1 + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .foo + - SectionOrType: .rela.foo + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '0000' + - Name: .rela.foo + Type: SHT_RELA + Flags: [ SHF_GROUP ] + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .foo + Relocations: + - Offset: 0x0000000000000000 + Symbol: g1 + Type: R_X86_64_16 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .foo + Type: STT_SECTION + Section: .foo + Global: + - Name: g1 +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: g1 + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .foo + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + AddressAlign: 0x0000000000000001 + Content: '90' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .foo + Type: STT_SECTION + Section: .foo + Global: + - Name: g1 + Section: .foo +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: 0A000000 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 00636C616E672076657273696F6E20332E372E3020287472756E6B203232393535372920286C6C766D2F7472756E6B203232393536332900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + Local: + - Name: global-g1.c + Type: STT_FILE + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + Global: + - Name: g1 + Type: STT_OBJECT + Section: .data + Size: 0x0000000000000004 +... diff --git a/test/elf/sections.test b/test/elf/sections.test new file mode 100644 index 000000000000..8839aa6d4e8a --- /dev/null +++ b/test/elf/sections.test @@ -0,0 +1,142 @@ +# This test checks if sections are created properly in the output that appear in +# the input +RUN: lld -flavor gnu -target i386 -o %t1 %p/Inputs/section-test.i386 \ +RUN: -static -e baz +RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=OBJDUMP %s +RUN: llvm-readobj -h -s -t %t1 | FileCheck -check-prefix=READOBJ %s + +OBJDUMP: 0 00000000 0000000000000000 +OBJDUMP: 1 .text 0000000a 0000000000000074 TEXT DATA +OBJDUMP: 2 .data 00000004 0000000000001000 DATA +OBJDUMP: 3 .special 00000004 0000000000001004 DATA +OBJDUMP: 4 .anotherspecial 00000004 0000000000001008 DATA +OBJDUMP: 5 .bss 00000004 000000000000100c BSS +OBJDUMP: 6 .shstrtab {{[0-9a-f]+}} 0000000000000000 +OBJDUMP: 7 .symtab {{[0-9a-f]+}} 0000000000000000 +OBJDUMP: 8 .strtab {{[0-9a-f]+}} 0000000000000000 + +READOBJ: Format: ELF32-i386 +READOBJ: Arch: i386 +READOBJ: AddressSize: 32bit +READOBJ: ElfHeader { +READOBJ: Ident { +READOBJ: DataEncoding: LittleEndian (0x1) +READOBJ: } +READOBJ: Machine: EM_386 +READOBJ: } + +READOBJ: Sections [ +READOBJ: Section { +READOBJ: Index: 0 +READOBJ: Name: (0) +READOBJ: Type: SHT_NULL +READOBJ: Flags [ (0x0) +READOBJ: ] +READOBJ: Address: 0x0 +READOBJ: Size: 0 +READOBJ: } +READOBJ: Section { +READOBJ: Index: 1 +READOBJ: Name: .text +READOBJ: Type: SHT_PROGBITS +READOBJ: Flags [ (0x6) +READOBJ: SHF_ALLOC +READOBJ: SHF_EXECINSTR +READOBJ: ] +READOBJ: Address: 0x74 +READOBJ: Size: 10 +READOBJ: AddressAlignment: 4 +READOBJ: } +READOBJ: Section { +READOBJ: Index: 2 +READOBJ: Name: .data +READOBJ: Type: SHT_PROGBITS +READOBJ: Flags [ (0x3) +READOBJ: SHF_ALLOC +READOBJ: SHF_WRITE +READOBJ: ] +READOBJ: Address: 0x1000 +READOBJ: Size: 4 +READOBJ: AddressAlignment: 4 +READOBJ: } +READOBJ: Section { +READOBJ: Index: 3 +READOBJ: Name: .special +READOBJ: Type: SHT_PROGBITS +READOBJ: Flags [ (0x3) +READOBJ: SHF_ALLOC +READOBJ: SHF_WRITE +READOBJ: ] +READOBJ: Address: 0x1004 +READOBJ: Size: 4 +READOBJ: } +READOBJ: Section { +READOBJ: Index: 4 +READOBJ: Name: .anotherspecial +READOBJ: Type: SHT_PROGBITS +READOBJ: Flags [ (0x3) +READOBJ: SHF_ALLOC +READOBJ: SHF_WRITE +READOBJ: ] +READOBJ: Address: 0x1008 +READOBJ: Size: 4 +READOBJ: } +READOBJ: Section { +READOBJ: Index: 5 +READOBJ: Name: .bss +READOBJ: Type: SHT_NOBITS +READOBJ: Flags [ (0x3) +READOBJ: SHF_ALLOC +READOBJ: SHF_WRITE +READOBJ: ] +READOBJ: Address: 0x100C +READOBJ: Size: 4 +READOBJ: } +READOBJ: Section { +READOBJ: Index: 6 +READOBJ: Name: .shstrtab +READOBJ: Type: SHT_STRTAB +READOBJ: Flags [ (0x0) +READOBJ: ] +READOBJ: Address: 0x0 +READOBJ: Link: 0 +READOBJ: AddressAlignment: 1 +READOBJ: } +READOBJ: Section { +READOBJ: Index: 7 +READOBJ: Name: .symtab +READOBJ: Type: SHT_SYMTAB +READOBJ: Flags [ (0x0) +READOBJ: ] +READOBJ: Address: 0x0 +READOBJ: Link: 8 +READOBJ: AddressAlignment: 4 +READOBJ: EntrySize: 16 +READOBJ: } +READOBJ: Section { +READOBJ: Index: 8 +READOBJ: Name: .strtab +READOBJ: Type: SHT_STRTAB +READOBJ: Flags [ (0x0) +READOBJ: ] +READOBJ: Address: 0x0 +READOBJ: } +READOBJ: ] + +READOBJ: Symbols [ +READOBJ: Symbol { +READOBJ: Name: baz +READOBJ: Value: 0x74 +READOBJ: Size: 10 +READOBJ: Binding: Global +READOBJ: Type: Function +READOBJ: Section: .text +READOBJ: } +READOBJ: Symbol { +READOBJ: Name: y +READOBJ: Value: 0x1004 +READOBJ: Size: 4 +READOBJ: Binding: Global +READOBJ: Type: Object +READOBJ: Section: .special +READOBJ: } diff --git a/test/elf/sh_addralign.test b/test/elf/sh_addralign.test new file mode 100644 index 000000000000..9c7a050f565c --- /dev/null +++ b/test/elf/sh_addralign.test @@ -0,0 +1,38 @@ +# Check handling of section alignment. +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target arm64 -o %t-exe %t-obj +# RUN: llvm-objdump -h %t-exe | FileCheck %s + +# CHECK: 8 .data 00000000 0000000000402000 DATA + +!ELF +FileHeader: !FileHeader + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_AARCH64 + +Sections: +- Name: .text + Type: SHT_PROGBITS + Content: '' + AddressAlign: 0 + Flags: [SHF_ALLOC, SHF_EXECINSTR] +- Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 1 + Content: '' + Size: 0x1000 +- Name: .data + Type: SHT_PROGBITS + Content: '' + AddressAlign: 4096 + Flags: [SHF_ALLOC, SHF_WRITE] + +Symbols: + Global: + - Name: _start + Section: .text + Value: 0x0 + Size: 4 diff --git a/test/elf/soname.test b/test/elf/soname.test new file mode 100644 index 000000000000..79c089ec607c --- /dev/null +++ b/test/elf/soname.test @@ -0,0 +1,6 @@ +RUN: lld -flavor gnu -shared -target i386 -e main %p/Inputs/writersyms.o \ +RUN: -o %t -soname libtest.so +RUN: llvm-readobj -dynamic-table %t | FileCheck %s + +CHECK: LoadName: libtest.so +CHECK: 0x0000000E SONAME LibrarySoname (libtest.so) diff --git a/test/elf/strip-all.test b/test/elf/strip-all.test new file mode 100644 index 000000000000..44a41c2a0d9f --- /dev/null +++ b/test/elf/strip-all.test @@ -0,0 +1,107 @@ +# Tests the --strip-all (-s) flag. We expect the symbol table to not contain +# any symbol in the output file. +# +# The following code was used to generate the object. +# $ clang -c blah.c -o blah +# +# void +# callMeMaybe(int *v) +# { +# *v += 1; +# } +# +# int +# main(void) +# { +# +# int blah = 42; +# callMeMaybe(&blah); +# } + +#RUN: yaml2obj -format=elf %s -o=%t.o +#RUN: lld -flavor gnu -target x86_64 %t.o -e=main --strip-all -o %t1 +#RUN: llvm-readobj -dt %t1 | FileCheck -check-prefix CHECKSYMS %s + +#CHECKSYMS: @ + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_FREEBSD + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 554889E548897DF8488B7DF88B07050100000089075DC3660F1F840000000000554889E54883EC10488D7DFCC745FC2A000000E8C8FFFFFFB8000000004883C4105DC3 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 004672656542534420636C616E672076657273696F6E20332E342E312028746167732F52454C454153455F33342F646F74312D66696E616C203230383033322920323031343035313200 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000017A5200017810011B0C070890010000180000001C000000000000001700000000410E108602430D060000001800000038000000000000002300000000410E108602430D06000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 + - Offset: 0x000000000000003C + Symbol: .text + Type: R_X86_64_PC32 + Addend: 32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: callMeMaybe + Type: STT_FUNC + Section: .text + Size: 0x0000000000000017 + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000000020 + Size: 0x0000000000000023 +... diff --git a/test/elf/stripped-empty.test b/test/elf/stripped-empty.test new file mode 100644 index 000000000000..0403808db2eb --- /dev/null +++ b/test/elf/stripped-empty.test @@ -0,0 +1,4 @@ +RUN: lld -flavor gnu -shared -o test.so \ +RUN: -target x86_64 %p/Inputs/stripped-empty.x86_64 + +test that we handle files without a symbol table. diff --git a/test/elf/symbols.test b/test/elf/symbols.test new file mode 100644 index 000000000000..7f6bbdbc8c1d --- /dev/null +++ b/test/elf/symbols.test @@ -0,0 +1,33 @@ +# Tests the functionality of archive libraries reading +# and resolution +# Note: The binary files would not be required once we have support to generate +# binary archives from textual(yaml) input +# +# Tests generated using the source files below +# main file +# +#extern int __bss_start __attribute__ ((weak)); +#int a; +#int main() +#{ +# return 0; +#} +# + +RUN: lld -flavor gnu -target i386 -e main %p/Inputs/writersyms.o -o %t1 +RUN: llvm-nm -n %t1 | FileCheck -check-prefix CHECKSYMS %s +RUN: lld -flavor gnu -shared -target i386 -e main %p/Inputs/writersyms.o -o %t1 +RUN: llvm-nm -n %t1 | FileCheck -check-prefix CHECKSHAREDSYMS %s + +CHECKSYMS: {{[0-9a-f]+}} a 1.c +CHECKSYMS: {{[0-9a-f]+}} T main +CHECKSYMS: {{[0-9a-f]+}} A __bss_start +CHECKSYMS: {{[0-9a-f]+}} B a +CHECKSYMS: {{[0-9a-f]+}} A __bss_end +CHECKSYMS: {{[0-9a-f]+}} A _end +CHECKSYMS: {{[0-9a-f]+}} A end + +CHECKSHAREDSYMS: {{[0-9a-f]+}} a 1.c +CHECKSHAREDSYMS: {{[0-9a-f]+}} T main +CHECKSHAREDSYMS: {{[0-9a-f]+}} B a +CHECKSHAREDSYMS: {{[0-9a-f]+}} A _end diff --git a/test/elf/tls.test b/test/elf/tls.test new file mode 100644 index 000000000000..038889406b67 --- /dev/null +++ b/test/elf/tls.test @@ -0,0 +1,43 @@ +# REQUIRES: x86 + +# This tests verifies that TLS variables have correct offsets +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 -static \ +RUN: --output-filetype=yaml --noinhibit-exec | FileCheck %s -check-prefix=YAML + +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 -o %t \ +RUN: --noinhibit-exec -e main -static && llvm-objdump -d %t | FileCheck %s + +// Verify that the TLS accesses have the correct offsets. + +YAML: name: main +YAML: references: +YAML: kind: R_X86_64_TPOFF32 +YAML: offset: 9 +YAML: target: tls1 +YAML: kind: R_X86_64_TPOFF32 +YAML: offset: 17 +YAML: target: tls0 +YAML: kind: R_X86_64_TPOFF32 +YAML: offset: 25 +YAML: target: tls2 + +YAML: name: GOTTPOFF +YAML: kind: R_X86_64_PC32 +YAML: target: [[GOTNAME:[a-zA-Z0-9_]+]] + +YAML: type: got +YAML: references: +YAML: kind: R_X86_64_TPOFF64 +YAML: target: tls2 + +// main +CHECK: addl %fs:-4 +CHECK: addl %fs:-8 +CHECK: addl %fs:-12 + +// GOTTPOFF +CHECK: movq {{[0-9]+}}(%rip) + +// TLSLD +CHECK: movq %fs:0, %rax +CHECK: leaq -8(%rax), %rax diff --git a/test/elf/tlsAddr.test b/test/elf/tlsAddr.test new file mode 100644 index 000000000000..6bc5e3e9bf78 --- /dev/null +++ b/test/elf/tlsAddr.test @@ -0,0 +1,7 @@ +# This tests verifies that TLS variables have correct offsets +# and that TBSS doesn't occupy memory +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tlsAddr.x86-64 -static \ +RUN: -o %t --noinhibit-exec +RUN: llvm-objdump -section-headers %t | FileCheck -check-prefix=CHECKADDR %s + +CHECKADDR: {{[0-9]+}} .data 00000000 0000000000401008 DATA diff --git a/test/elf/undef-from-dso-to-main.test b/test/elf/undef-from-dso-to-main.test new file mode 100644 index 000000000000..71d0b51499dd --- /dev/null +++ b/test/elf/undef-from-dso-to-main.test @@ -0,0 +1,52 @@ +# Tests that a reference from a DSO to a regular object +# forces the final executable to export the symbol. + +#RUN: yaml2obj -format=elf %p/Inputs/undef2-so.o.yaml -o=%t.o.so +#RUN: lld -flavor gnu -target x86_64 -shared %t.o.so -o %T/libundef2.so +#RUN: yaml2obj -format=elf %s -o=%t.o +#RUN: lld -flavor gnu -target x86_64 %t.o -L%T -lundef2 -o %t1 +#RUN: llvm-readobj -dyn-symbols %t1 | FileCheck -check-prefix CHECKSYMS %s + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000001 + Content: C3 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '002E7379' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + Global: + - Name: myexportedsymbol + Type: STT_OBJECT + Section: .bss + Size: 0x0000000000000004 + - Name: _start + Section: .text + Size: 0x0000000000000001 + +#CHECKSYMS: myexportedsymbol diff --git a/test/elf/undef-from-main-dso.test b/test/elf/undef-from-main-dso.test new file mode 100644 index 000000000000..43faef0e74c4 --- /dev/null +++ b/test/elf/undef-from-main-dso.test @@ -0,0 +1,43 @@ +RUN: lld -flavor gnu -target x86_64 -e main -o %t -L%p/Inputs \ +RUN: %p/Inputs/undef.o -lundef +RUN: llvm-readobj -relocations -symbols -dyn-symbols %t | FileCheck %s + +RUN: lld -flavor gnu -target x86_64 -e main -o %t -L%p/Inputs \ +RUN: %p/Inputs/undef-pc32.o -lundef +RUN: llvm-readobj -relocations -symbols -dyn-symbols %t | FileCheck %s + +# DSO source code: +# int x[2] = { 1, 2 }; +# +# Main binary source code: +# +# extern int x[2]; +# +# int main(void) +# { +# x[0] = 2; +# } +# + +CHECK: Relocations [ +CHECK-NEXT: Section ({{[0-9]+}}) .rela.dyn { +CHECK-NEXT: 0x{{[1-9A-F][0-9A-F]*}} R_X86_64_COPY x 0x0 +CHECK-NEXT: } +CHECK-NEXT: ] + +CHECK: Name: x ({{[0-9]+}} +CHECK-NEXT: Value: 0x{{[1-9A-F][0-9A-F]*}} +CHECK-NEXT: Size: 8 +CHECK-NEXT: Binding: Global (0x1) +CHECK-NEXT: Type: Object (0x1) +CHECK-NEXT: Other: 0 +CHECK-NEXT: Section: .bss + +CHECK: Name: x@ ({{[0-9]+}} +CHECK-NEXT: Value: 0x{{[1-9A-F][0-9A-F]*}} +CHECK-NEXT: Size: 8 +CHECK-NEXT: Binding: Global (0x1) +CHECK-NEXT: Type: Object (0x1) +CHECK-NEXT: Other: 0 +CHECK-NEXT: Section: .bss + diff --git a/test/elf/weaksym.test b/test/elf/weaksym.test new file mode 100644 index 000000000000..0e265028e5ed --- /dev/null +++ b/test/elf/weaksym.test @@ -0,0 +1,7 @@ +# Tests that a weak reference remains a weak reference, +# even if a shared library defines the symbol weak as well. + +RUN: lld -flavor gnu -target x86_64 -shared %p/Inputs/weaksym.o -L%p/Inputs -lweaksym -o %t1 +RUN: llvm-nm -n %t1 | FileCheck -check-prefix CHECKSYMS %s + +CHECKSYMS: w weaksym diff --git a/test/elf/wrap.test b/test/elf/wrap.test new file mode 100644 index 000000000000..997439f8f5b4 --- /dev/null +++ b/test/elf/wrap.test @@ -0,0 +1,279 @@ +# This tests the functionality of using the --wrap option. +# The test case is extracted by compiling and linking the following code. +# +#cat > main.c << \! +#int main() { +# foo(); +# return 0; +#} +#! +# +#cat > wrapfoo.c << \! +#int __wrap_foo() { +# __real_foo(); +# return 0; +#} +#! +# +#cat > realfoo.c << \! +#int foo() { +# return 0; +#} +#! +# +#clang main.c wrapfoo.c realfoo.c -Xlinker --wrap -Xlinker foo +#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.main.o +#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.wrapfoo.o +#RUN: yaml2obj -format=elf -docnum 3 %s -o %t.realfoo.o +#RUN: lld -flavor gnu -target x86_64 %t.main.o %t.wrapfoo.o %t.realfoo.o \ +#RUN: --wrap foo --wrap foo --noinhibit-exec --output-filetype=yaml -o %t2.out +#RUN: lld -flavor gnu -target x86_64 %t.main.o %t.wrapfoo.o \ +#RUN: --wrap foo --wrap foo --noinhibit-exec --output-filetype=yaml -o %t2.out.undef 2>&1 | \ +#RUN: FileCheck %s -check-prefix=CHECKUNDEF +#CHECKWRAP: - name: main +#CHECKWRAP: references: +#CHECKWRAP: - kind: R_X86_64_PC32 +#CHECKWRAP: target: __wrap_foo +#CHECKWRAP: - name: __wrap_foo +#CHECKWRAP: references: +#CHECKWRAP: - kind: R_X86_64_PC32 +#CHECKWRAP: target: foo +#CHECKUNDEF: Undefined symbol: {{.*}}main.o: foo +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 5031C0E80000000031C05AC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000004 + Symbol: foo + Type: R_X86_64_PC32 + Addend: -4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 00636C616E672076657273696F6E20332E372E3020287472756E6B203232383733392920286C6C766D2F7472756E6B203232383734382900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C070890010000140000001C000000000000000C00000000410E1000000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: main + Type: STT_FUNC + Section: .text + Size: 0x000000000000000C + - Name: foo +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 5031C0E80000000031C05AC3 + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: + - Offset: 0x0000000000000004 + Symbol: __real_foo + Type: R_X86_64_PC32 + Addend: -4 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 00636C616E672076657273696F6E20332E372E3020287472756E6B203232383733392920286C6C766D2F7472756E6B203232383734382900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C070890010000140000001C000000000000000C00000000410E1000000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: __wrap_foo + Type: STT_FUNC + Section: .text + Size: 0x000000000000000C + - Name: __real_foo +... +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: 31C0C3 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 00636C616E672076657273696F6E20332E372E3020287472756E6B203232383733392920286C6C766D2F7472756E6B203232383734382900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000008 + Content: 1400000000000000037A5200017810011B0C070890010000140000001C00000000000000030000000000000000000000 + - Name: .rela.eh_frame + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .eh_frame + Relocations: + - Offset: 0x0000000000000020 + Symbol: .text + Type: R_X86_64_PC32 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .comment + Type: STT_SECTION + Section: .comment + - Name: .note.GNU-stack + Type: STT_SECTION + Section: .note.GNU-stack + - Name: .eh_frame + Type: STT_SECTION + Section: .eh_frame + Global: + - Name: foo + Type: STT_FUNC + Section: .text + Size: 0x0000000000000003 +... diff --git a/test/elf/x86-64-dynamic-relocs.test b/test/elf/x86-64-dynamic-relocs.test new file mode 100644 index 000000000000..325693e3f714 --- /dev/null +++ b/test/elf/x86-64-dynamic-relocs.test @@ -0,0 +1,26 @@ +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/relocs-dynamic.x86-64 \ +RUN: --output-filetype=yaml --noinhibit-exec | FileCheck %s + +path: <linker-internal> +defined-atoms: + - name: main + scope: global + content: [ E8, 00, 00, 00, 00, C3 ] + alignment: 2^4 + section-choice: custom-required + section-name: .text + references: + - kind: R_X86_64_PLT32 + offset: 1 + target: foo + addend: -4 + - name: foo + scope: global + content: [ C3 ] + alignment: 6 mod 2^4 + section-choice: custom-required + section-name: .text + +# Don't generate a PLT/GOT entry for a PLT32 relocation to a non-shared symbol. +CHECK-NOT: got +CHECK-NOT: stub diff --git a/test/elf/x86-64-dynamic.test b/test/elf/x86-64-dynamic.test new file mode 100644 index 000000000000..4e24e954a20e --- /dev/null +++ b/test/elf/x86-64-dynamic.test @@ -0,0 +1,79 @@ +# Checks that linking an object file with a shared object creates the necessary +# PLT/GOT Entries +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared.x86-64 \ +RUN: %p/Inputs/shared.so-x86-64 --output-filetype=yaml -o %t1 --noinhibit-exec +RUN: FileCheck %s < %t1 + +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared-32s.x86-64 \ +RUN: %p/Inputs/shared.so-x86-64 --output-filetype=yaml --noinhibit-exec \ +RUN: | FileCheck %s --check-prefix=32S + +CHECK: - name: main +CHECK: scope: global +CHECK: references: +CHECK: - kind: R_X86_64_PC32 +CHECK: offset: 18 +CHECK: target: [[PLTNAME:[-a-zA-Z0-9_]+]] +CHECK: addend: -4 +CHECK: - kind: R_X86_64_GOTPCREL +CHECK: offset: 25 +CHECK: target: [[GOTNAME:[-a-zA-Z0-9_]+]] +CHECK: addend: -4 + + - name: .PLT0 +CHECK: type: stub +CHECK: content: [ FF, 35, 00, 00, 00, 00, FF, 25, 00, 00, 00, 00, +CHECK: 90, 90, 90, 90 ] +CHECK: alignment: 2^4 +CHECK: section-choice: custom-required +CHECK: section-name: .plt +CHECK: references: +CHECK: - kind: R_X86_64_PC32 +CHECK: offset: 2 + target: __got0 +CHECK: addend: -4 +CHECK: - kind: R_X86_64_PC32 +CHECK: offset: 8 + target: __got1 +CHECK: addend: -4 + - name: [[PLTNAME]] +CHECK: type: stub +CHECK: content: [ FF, 25, 00, 00, 00, 00, 68, 00, 00, 00, 00, E9, +CHECK: 00, 00, 00, 00 ] +CHECK: alignment: 2^4 +CHECK: section-choice: custom-required +CHECK: section-name: .plt +CHECK: references: +CHECK: - kind: R_X86_64_PC32 +CHECK: offset: 2 + target: __got_foo +CHECK: addend: -4 +CHECK: - kind: LLD_R_X86_64_GOTRELINDEX +CHECK: offset: 7 + target: __got_foo +CHECK: - kind: R_X86_64_PC32 +CHECK: offset: 12 + target: .PLT0 +CHECK: addend: -4 + +// Don't check the GOT and PLT names as they are only present in assert builds. +CHECK: type: got +CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +CHECK: section-choice: custom-required +CHECK: section-name: .got +CHECK: permissions: rw- +CHECK: references: +CHECK: - kind: R_X86_64_GLOB_DAT +CHECK: offset: 0 +CHECK: target: i + +CHECK:shared-library-atoms: +CHECK: - name: foo +CHECK: load-name: shared.so-x86-64 + +32S: name: main +32S: kind: R_X86_64_PC32 +32S: target: func +32S: kind: R_X86_64_32S +32S: kind: R_X86_64_PC32 +32S: type: stub diff --git a/test/elf/x86.test b/test/elf/x86.test new file mode 100644 index 000000000000..6b68837193e6 --- /dev/null +++ b/test/elf/x86.test @@ -0,0 +1,38 @@ +# Source for input file: reloc-xb.x86 +# xb.S: +# .section .text, "ax", @progbits +# .align 0x4 +# .globl _start +# _start: +# .globl back +# back: +# call target +# +# Source for input file: reloc-xt.x86 +# xt.S: +# .section .text, "ax", @progbits +# +# .globl target +# target: +# call back +# +# Assembled with: "as --32" + +RUN: lld -flavor gnu -target i386 -e back --output-filetype=yaml %p/Inputs/reloc-xb.x86 %p/Inputs/reloc-xt.x86 | FileCheck %s -check-prefix x86-yaml + +x86-yaml: - name: back +x86-yaml: scope: global +x86-yaml: content: [ E8, FC, FF, FF, FF ] +x86-yaml: references: +x86-yaml: - kind: R_386_PC32 +x86-yaml: offset: 1 +x86-yaml: target: target + +x86-yaml: - name: target +x86-yaml: scope: global +x86-yaml: content: [ E8, FC, FF, FF, FF ] +x86-yaml: references: +x86-yaml: - kind: R_386_PC32 +x86-yaml: offset: 1 +x86-yaml: target: back + diff --git a/test/elf/x86_64-kinds.test b/test/elf/x86_64-kinds.test new file mode 100644 index 000000000000..49586059d953 --- /dev/null +++ b/test/elf/x86_64-kinds.test @@ -0,0 +1,23 @@ +REQUIRES: x86 + +RUN: lld -flavor gnu -target x86_64-linux -o %t1 %p/Inputs/relocs.x86-64 \ +RUN: -e _start -static +RUN: llvm-objdump -d %t1 | FileCheck %s -check-prefix=RELOCS + +RUN: lld -flavor gnu -target x86_64-linux --output-filetype=yaml -e _start -static \ +RUN: %p/Inputs/relocs.x86-64 | FileCheck %s -check-prefix=X86_64 + +RELOCS: ELF64-x86-64 + +// R_X86_64_32S +RELOCS: c7 04 25 +RELOCS-NOT: 00 00 00 00 +RELOCS: 05 00 00 00 movl + +// R_X86_64_PC32 +RELOCS: e8 +RELOCS-NOT: 00 00 00 00 +RELOCS: callq + +X86_64: R_X86_64_32S +X86_64: R_X86_64_PC32 diff --git a/test/lit.cfg b/test/lit.cfg new file mode 100644 index 000000000000..5b49765f7894 --- /dev/null +++ b/test/lit.cfg @@ -0,0 +1,167 @@ +# -*- Python -*- + +import os +import platform +import re +import subprocess +import locale + +import lit.formats +import lit.util + +# Configuration file for the 'lit' test runner. + +# name: The name of this test suite. +config.name = 'lld' + +# testFormat: The test format to use to interpret tests. +# +# For now we require '&&' between commands, until they get globally killed and +# the test runner updated. +execute_external = (platform.system() != 'Windows' + or lit_config.getBashPath() not in [None, ""]) +config.test_format = lit.formats.ShTest(execute_external) + +# suffixes: A list of file extensions to treat as test files. +config.suffixes = ['.objtxt', '.test'] + +# test_source_root: The root path where tests are located. +config.test_source_root = os.path.dirname(__file__) + +# test_exec_root: The root path where tests should be run. +lld_obj_root = getattr(config, 'lld_obj_root', None) +if lld_obj_root is not None: + config.test_exec_root = os.path.join(lld_obj_root, 'test') + +# Set llvm_{src,obj}_root for use by others. +config.llvm_src_root = getattr(config, 'llvm_src_root', None) +config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) + +# Tweak the PATH to include the tools dir and the scripts dir. +if lld_obj_root is not None: + llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) + if not llvm_tools_dir: + lit_config.fatal('No LLVM tools dir set!') + path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) + path = os.path.pathsep.join((os.path.join(getattr(config, 'llvm_src_root', None),'test','Scripts'),path)) + + config.environment['PATH'] = path + + llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) + if not llvm_libs_dir: + lit_config.fatal('No LLVM libs dir set!') + path = os.path.pathsep.join((llvm_libs_dir, + config.environment.get('LD_LIBRARY_PATH',''))) + config.environment['LD_LIBRARY_PATH'] = path + + # Propagate LLVM_SRC_ROOT into the environment. + config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '') + + # Propagate PYTHON_EXECUTABLE into the environment + config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable', + '') +### + +# Check that the object root is known. +if config.test_exec_root is None: + # Otherwise, we haven't loaded the site specific configuration (the user is + # probably trying to run on a test file directly, and either the site + # configuration hasn't been created by the build system, or we are in an + # out-of-tree build situation). + + # Check for 'lld_site_config' user parameter, and use that if available. + site_cfg = lit_config.params.get('lld_site_config', None) + if site_cfg and os.path.exists(site_cfg): + lit_config.load_config(config, site_cfg) + raise SystemExit + + # Try to detect the situation where we are using an out-of-tree build by + # looking for 'llvm-config'. + # + # FIXME: I debated (i.e., wrote and threw away) adding logic to + # automagically generate the lit.site.cfg if we are in some kind of fresh + # build situation. This means knowing how to invoke the build system though, + # and I decided it was too much magic. We should solve this by just having + # the .cfg files generated during the configuration step. + + llvm_config = lit.util.which('llvm-config', config.environment['PATH']) + if not llvm_config: + lit_config.fatal('No site specific configuration available!') + + # Get the source and object roots. + llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() + llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() + lld_src_root = os.path.join(llvm_src_root, "tools", "lld") + lld_obj_root = os.path.join(llvm_obj_root, "tools", "lld") + + # Validate that we got a tree which points to here, using the standard + # tools/lld layout. + this_src_root = os.path.dirname(config.test_source_root) + if os.path.realpath(lld_src_root) != os.path.realpath(this_src_root): + lit_config.fatal('No site specific configuration available!') + + # Check that the site specific configuration exists. + site_cfg = os.path.join(lld_obj_root, 'test', 'lit.site.cfg') + if not os.path.exists(site_cfg): + lit_config.fatal( + 'No site specific configuration available! You may need to ' + 'run "make test" in your lld build directory.') + + # Okay, that worked. Notify the user of the automagic, and reconfigure. + lit_config.note('using out-of-tree build at %r' % lld_obj_root) + lit_config.load_config(config, site_cfg) + raise SystemExit + +# When running under valgrind, we mangle '-vg' onto the end of the triple so we +# can check it with XFAIL and XTARGET. +if lit_config.useValgrind: + config.target_triple += '-vg' + +# Shell execution +if platform.system() not in ['Windows'] or lit_config.getBashPath() != '': + config.available_features.add('shell') + +# Running on Darwin OS +if platform.system() in ['Darwin']: + config.available_features.add('system-linker-mach-o') + +# Running on ELF based *nix +if platform.system() in ['FreeBSD', 'Linux']: + config.available_features.add('system-linker-elf') + +# llvm-config knows whether it is compiled with asserts (and) +# whether we are operating in release/debug mode. +import subprocess +try: + llvm_config_cmd = \ + subprocess.Popen([os.path.join(llvm_tools_dir, 'llvm-config'), + '--build-mode', '--assertion-mode', '--targets-built'], + stdout = subprocess.PIPE) +except OSError as why: + print("Could not find llvm-config in " + llvm_tools_dir) + exit(42) + +llvm_config_output = llvm_config_cmd.stdout.read().decode('utf_8') +llvm_config_output_list = llvm_config_output.split("\n") + +if re.search(r'DEBUG', llvm_config_output_list[0]): + config.available_features.add('debug') +if re.search(r'ON', llvm_config_output_list[1]): + config.available_features.add('asserts') +if re.search(r'ARM', llvm_config_output_list[2]): + config.available_features.add('arm') +if re.search(r'Mips', llvm_config_output_list[2]): + config.available_features.add('mips') +if re.search(r'X86', llvm_config_output_list[2]): + config.available_features.add('x86') +llvm_config_cmd.wait() + +# Check if Windows resource file compiler exists. +cvtres = lit.util.which('cvtres', config.environment['PATH']) +rc = lit.util.which('rc', config.environment['PATH']) +if cvtres and rc: + config.available_features.add('winres') + +# Check if "lib.exe" command exists. +if lit.util.which('lib.exe', config.environment['PATH']): + config.available_features.add('winlib') diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in new file mode 100644 index 000000000000..0eeb889d1b20 --- /dev/null +++ b/test/lit.site.cfg.in @@ -0,0 +1,22 @@ +## Autogenerated by LLVM/lld configuration. +# Do not edit! +config.llvm_src_root = "@LLVM_SOURCE_DIR@" +config.llvm_obj_root = "@LLVM_BINARY_DIR@" +config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" +config.llvm_libs_dir = "@LLVM_LIBS_DIR@" +config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" +config.lld_obj_root = "@LLD_BINARY_DIR@" +config.target_triple = "@TARGET_TRIPLE@" +config.python_executable = "@PYTHON_EXECUTABLE@" + +# Support substitution of the tools and libs dirs with user parameters. This is +# used when we can't determine the tool dir at configuration time. +try: + config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params + config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params +except KeyError as e: + key, = e.args + lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key)) + +# Let the main config do the real work. +lit_config.load_config(config, "@LLD_SOURCE_DIR@/test/lit.cfg") diff --git a/test/mach-o/Inputs/DependencyDump.py b/test/mach-o/Inputs/DependencyDump.py new file mode 100755 index 000000000000..0f4d49d6fb9a --- /dev/null +++ b/test/mach-o/Inputs/DependencyDump.py @@ -0,0 +1,30 @@ +# -*- Python -*- + + +# +# Dump out Xcode binary dependency file. +# + +import sys + +f = open(sys.argv[1], "rb") +byte = f.read(1) +while byte != b'': + if byte == b'\000': + sys.stdout.write("linker-vers: ") + elif byte == b'\020': + sys.stdout.write("input-file: ") + elif byte == b'\021': + sys.stdout.write("not-found: ") + elif byte == b'\100': + sys.stdout.write("output-file: ") + byte = f.read(1) + while byte != b'\000': + if byte != b'\012': + sys.stdout.write(byte.decode("ascii")) + byte = f.read(1) + sys.stdout.write("\n") + byte = f.read(1) + +f.close() + diff --git a/test/mach-o/Inputs/bar.yaml b/test/mach-o/Inputs/bar.yaml new file mode 100644 index 000000000000..5605e67e7c35 --- /dev/null +++ b/test/mach-o/Inputs/bar.yaml @@ -0,0 +1,18 @@ + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xC3 ] +global-symbols: + - name: _bar + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 diff --git a/test/mach-o/Inputs/exported_symbols_list.exp b/test/mach-o/Inputs/exported_symbols_list.exp new file mode 100644 index 000000000000..ff6653342472 --- /dev/null +++ b/test/mach-o/Inputs/exported_symbols_list.exp @@ -0,0 +1,6 @@ +# +# For use with exported_symbols_list.yaml +# +_foo +_b + diff --git a/test/mach-o/Inputs/full.filelist b/test/mach-o/Inputs/full.filelist new file mode 100644 index 000000000000..abf98b633377 --- /dev/null +++ b/test/mach-o/Inputs/full.filelist @@ -0,0 +1,3 @@ +/foo/bar/a.o +/foo/bar/b.o +/foo/x.a diff --git a/test/mach-o/Inputs/lib-search-paths/usr/lib/libmyshared.dylib b/test/mach-o/Inputs/lib-search-paths/usr/lib/libmyshared.dylib Binary files differnew file mode 100755 index 000000000000..71185fbdf736 --- /dev/null +++ b/test/mach-o/Inputs/lib-search-paths/usr/lib/libmyshared.dylib diff --git a/test/mach-o/Inputs/lib-search-paths/usr/lib/libmystatic.a b/test/mach-o/Inputs/lib-search-paths/usr/lib/libmystatic.a Binary files differnew file mode 100644 index 000000000000..b12062941f37 --- /dev/null +++ b/test/mach-o/Inputs/lib-search-paths/usr/lib/libmystatic.a diff --git a/test/mach-o/Inputs/lib-search-paths/usr/local/lib/file.o b/test/mach-o/Inputs/lib-search-paths/usr/local/lib/file.o Binary files differnew file mode 100644 index 000000000000..f9a923d37db3 --- /dev/null +++ b/test/mach-o/Inputs/lib-search-paths/usr/local/lib/file.o diff --git a/test/mach-o/Inputs/libSystem.yaml b/test/mach-o/Inputs/libSystem.yaml new file mode 100644 index 000000000000..2a7f46381dcc --- /dev/null +++ b/test/mach-o/Inputs/libSystem.yaml @@ -0,0 +1,13 @@ +# +# For use by test cases that create dynamic output types which may needs stubs +# and therefore will need a dylib definition of dyld_stub_binder. +# + +--- +shared-library-atoms: + - name: dyld_stub_binder + load-name: /usr/lib/libSystem.B.dylib + type: code + size: 0 + +... diff --git a/test/mach-o/Inputs/libbar.a b/test/mach-o/Inputs/libbar.a Binary files differnew file mode 100644 index 000000000000..64cae6c749ee --- /dev/null +++ b/test/mach-o/Inputs/libbar.a diff --git a/test/mach-o/Inputs/libfoo.a b/test/mach-o/Inputs/libfoo.a Binary files differnew file mode 100644 index 000000000000..21194efbabf9 --- /dev/null +++ b/test/mach-o/Inputs/libfoo.a diff --git a/test/mach-o/Inputs/order_file-basic.order b/test/mach-o/Inputs/order_file-basic.order new file mode 100644 index 000000000000..0ac90cb79da7 --- /dev/null +++ b/test/mach-o/Inputs/order_file-basic.order @@ -0,0 +1,11 @@ + +# input file for order_file-basic.yaml + +_func2 +libfoo.a(foo.o):_foo # tests file specific ordering within archive +i386:_func3 # wrong arch, so ignored +armv7:_func3 # wrong arch, so ignored +_func1 +_notfound # unknown symbol silently ignored +_data3 # data symbols should be orderable + diff --git a/test/mach-o/Inputs/partial.filelist b/test/mach-o/Inputs/partial.filelist new file mode 100644 index 000000000000..281581bf00fc --- /dev/null +++ b/test/mach-o/Inputs/partial.filelist @@ -0,0 +1,3 @@ +bar/a.o +bar/b.o +x.a diff --git a/test/mach-o/Inputs/use-dylib-install-names.yaml b/test/mach-o/Inputs/use-dylib-install-names.yaml new file mode 100644 index 000000000000..cec2559f2435 --- /dev/null +++ b/test/mach-o/Inputs/use-dylib-install-names.yaml @@ -0,0 +1,28 @@ +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0xE8, 0x00, 0x00, 0x00, + 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x00, + 0x00, 0x00, 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00, + 0xE8, 0x00, 0x00, 0x00, 0x00, 0x5D, 0xE9, 0x00, + 0x00, 0x00, 0x00 ] +global-symbols: + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _myGlobal + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 diff --git a/test/mach-o/PIE.yaml b/test/mach-o/PIE.yaml new file mode 100644 index 000000000000..2e50951a4544 --- /dev/null +++ b/test/mach-o/PIE.yaml @@ -0,0 +1,44 @@ +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t && \ +# RUN: llvm-objdump -macho -private-headers %t | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -pie -o %t\ +# RUN: && llvm-objdump -macho -private-headers %t | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -no_pie -o %t\ +# RUN: && llvm-objdump -macho -private-headers %t \ +# RUN: | FileCheck --check-prefix=CHECK_NO_PIE %s +# +# Test various PIE options. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xC3 ] +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +install-name: /usr/lib/libSystem.B.dylib +exports: + - name: dyld_stub_binder + +... + +# CHECK: MH_MAGIC_64 {{[0-9a-zA-Z _]+}} TWOLEVEL PIE +# CHECK_NO_PIE-NOT: MH_MAGIC_64 {{[0-9a-zA-Z _]+}} TWOLEVEL PIE diff --git a/test/mach-o/align_text.yaml b/test/mach-o/align_text.yaml new file mode 100644 index 000000000000..5ddbf911b9e5 --- /dev/null +++ b/test/mach-o/align_text.yaml @@ -0,0 +1,45 @@ +# RUN: lld -flavor darwin -arch x86_64 -r %s -o %t -print_atoms | FileCheck %s +# RUN: lld -flavor darwin -arch x86_64 -r %t -o %t2 -print_atoms | FileCheck %s +# +# Test that alignment info round trips through -r +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0x90, 0x90, 0x90, 0xC3, 0xC3, 0xC3 ] +local-symbols: + - name: _f1 + type: N_SECT + sect: 1 + value: 0x0000000000000003 + - name: _f2 + type: N_SECT + sect: 1 + value: 0x0000000000000004 + - name: _f3 + type: N_SECT + sect: 1 + value: 0x0000000000000005 +... + +# CHECK: defined-atoms: +# CHECK: - content: [ 90, 90, 90 ] +# CHECK: alignment: 2^4 +# CHECK: - name: _f1 +# CHECK: content: [ C3 ] +# CHECK: alignment: 3 mod 2^4 +# CHECK: - name: _f2 +# CHECK: content: [ C3 ] +# CHECK: alignment: 4 mod 2^4 +# CHECK: - name: _f3 +# CHECK: content: [ C3 ] +# CHECK: alignment: 5 mod 2^4 diff --git a/test/mach-o/arm-interworking-movw.yaml b/test/mach-o/arm-interworking-movw.yaml new file mode 100644 index 000000000000..59d2f0ddd3d9 --- /dev/null +++ b/test/mach-o/arm-interworking-movw.yaml @@ -0,0 +1,393 @@ +# REQUIRES: arm +# RUN: lld -flavor darwin -arch armv7 -r -print_atoms %s -o %t | FileCheck %s +# RUN: lld -flavor darwin -arch armv7 -dylib -print_atoms %t -o %t2 \ +# RUN: %p/Inputs/libSystem.yaml -sectalign __TEXT __text 0x1000 | FileCheck %s +# RUN: llvm-objdump -d -macho %t2 | FileCheck -check-prefix=CODE %s +# +# Test thumb and arm branches round trip through -r. +# Test movw/movt pairs have low bit set properly for thumb vs arm. +# +# + +--- !mach-o +arch: armv7 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0x40, 0xF2, 0x25, 0x00, 0xC0, 0xF2, 0x00, 0x00, + 0x40, 0xF2, 0x01, 0x01, 0xC0, 0xF2, 0x00, 0x01, + 0x40, 0xF2, 0x4E, 0x02, 0xC0, 0xF2, 0x00, 0x02, + 0x40, 0xF2, 0x2A, 0x03, 0xC0, 0xF2, 0x00, 0x03, + 0x78, 0x44, 0x70, 0x47, 0x70, 0x47, 0x25, 0x00, + 0x00, 0xE3, 0x00, 0x00, 0x40, 0xE3, 0xD7, 0x1F, + 0x0F, 0xE3, 0xFF, 0x1F, 0x4F, 0xE3, 0x4E, 0x20, + 0x00, 0xE3, 0x00, 0x20, 0x40, 0xE3, 0x00, 0x30, + 0x00, 0xE3, 0x00, 0x30, 0x40, 0xE3, 0x0F, 0x00, + 0x80, 0xE0, 0x1E, 0xFF, 0x2F, 0xE1, 0x1E, 0xFF, + 0x2F, 0xE1 ] + relocations: + - offset: 0x00000042 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 1 + pc-rel: false + value: 0x0000004E + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 1 + pc-rel: false + value: 0x00000046 + - offset: 0x0000003E + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 0 + pc-rel: false + value: 0x0000004E + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 0 + pc-rel: false + value: 0x00000046 + - offset: 0x0000003A + type: ARM_RELOC_HALF + length: 1 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x0000004E + type: ARM_RELOC_PAIR + length: 1 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000036 + type: ARM_RELOC_HALF + length: 0 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 0 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000032 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 1 + pc-rel: false + value: 0x00000024 + - offset: 0x0000FFD6 + scattered: true + type: ARM_RELOC_PAIR + length: 1 + pc-rel: false + value: 0x00000046 + - offset: 0x0000002E + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 0 + pc-rel: false + value: 0x00000024 + - offset: 0x0000FFFF + scattered: true + type: ARM_RELOC_PAIR + length: 0 + pc-rel: false + value: 0x00000046 + - offset: 0x0000002A + type: ARM_RELOC_HALF + length: 1 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000025 + type: ARM_RELOC_PAIR + length: 1 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000026 + type: ARM_RELOC_HALF + length: 0 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 0 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x0000001C + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 3 + pc-rel: false + value: 0x0000004E + - offset: 0x0000002A + scattered: true + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + value: 0x00000020 + - offset: 0x00000018 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 2 + pc-rel: false + value: 0x0000004E + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x00000020 + - offset: 0x00000014 + type: ARM_RELOC_HALF + length: 3 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x0000004E + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000010 + type: ARM_RELOC_HALF + length: 2 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x0000000C + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 3 + pc-rel: false + value: 0x00000024 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + value: 0x00000020 + - offset: 0x00000008 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000024 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x00000020 + - offset: 0x00000004 + type: ARM_RELOC_HALF + length: 3 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000025 + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000000 + type: ARM_RELOC_HALF + length: 2 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + extern: false + symbol: 16777215 +local-symbols: + - name: _t1 + type: N_SECT + sect: 1 + desc: [ N_ARM_THUMB_DEF ] + value: 0x0000000000000000 + - name: _t2 + type: N_SECT + sect: 1 + desc: [ N_ARM_THUMB_DEF ] + value: 0x0000000000000024 + - name: _a2 + type: N_SECT + sect: 1 + value: 0x000000000000004E + - name: _a1 + type: N_SECT + sect: 1 + value: 0x0000000000000026 +... + +# CHECK: defined-atoms: +# CHECK: - name: _t1 +# CHECK: references: +# CHECK: - kind: modeThumbCode +# CHECK: offset: 0 +# CHECK: target: _t1 +# CHECK: - kind: thumb_movw +# CHECK: offset: 0 +# CHECK: target: _t2 +# CHECK-NOT: addend: +# CHECK: - kind: thumb_movt +# CHECK: offset: 4 +# CHECK: target: _t2 +# CHECK-NOT: addend: +# CHECK: - kind: thumb_movw_funcRel +# CHECK: offset: 8 +# CHECK: target: _t2 +# CHECK: addend: -36 +# CHECK: - kind: thumb_movt_funcRel +# CHECK: offset: 12 +# CHECK: target: _t2 +# CHECK: addend: -36 +# CHECK: - kind: thumb_movw +# CHECK: offset: 16 +# CHECK: target: _a2 +# CHECK-NOT: addend: +# CHECK: - kind: thumb_movt +# CHECK: offset: 20 +# CHECK: target: _a2 +# CHECK-NOT: addend: +# CHECK: - kind: thumb_movw_funcRel +# CHECK: offset: 24 +# CHECK: target: _a2 +# CHECK: addend: -36 +# CHECK: - kind: thumb_movt_funcRel +# CHECK: offset: 28 +# CHECK: target: _a2 +# CHECK: addend: -36 +# CHECK: - name: _t2 +# CHECK: references: +# CHECK: - kind: modeThumbCode +# CHECK: offset: 0 +# CHECK: target: _t2 +# CHECK: - name: _a1 +# CHECK: references: +# CHECK: - kind: arm_movw +# CHECK: offset: 0 +# CHECK: target: _t2 +# CHECK-NOT: addend: +# CHECK: - kind: arm_movt +# CHECK: offset: 4 +# CHECK: target: _t2 +# CHECK-NOT: addend: +# CHECK: - kind: arm_movw_funcRel +# CHECK: offset: 8 +# CHECK: target: _t2 +# CHECK: addend: -40 +# CHECK: - kind: arm_movt_funcRel +# CHECK: offset: 12 +# CHECK: target: _t2 +# CHECK: addend: -40 +# CHECK: - kind: arm_movw +# CHECK: offset: 16 +# CHECK: target: _a2 +# CHECK-NOT: addend: +# CHECK: - kind: arm_movt +# CHECK: offset: 20 +# CHECK: target: _a2 +# CHECK-NOT: addend: +# CHECK: - kind: arm_movw_funcRel +# CHECK: offset: 24 +# CHECK: target: _a2 +# CHECK: addend: -40 +# CHECK: - kind: arm_movt_funcRel +# CHECK: offset: 28 +# CHECK: target: _a2 +# CHECK: addend: -40 +# CHECK: - name: _a2 + + +# CODE: _t1: +# CODE-NEXT: movw r0, #4133 +# CODE-NEXT: movt r0, #0 +# CODE-NEXT: movw r1, #1 +# CODE-NEXT: movt r1, #0 +# CODE-NEXT: movw r2, _a2 +# CODE-NEXT: movt r2, #0 +# CODE-NEXT: movw r3, #42 +# CODE-NEXT: movt r3, #0 + + +# CODE: _a1: +# CODE-NEXT: movw r0, #4133 +# CODE-NEXT: movt r0, #0 +# CODE-NEXT: movw r1, #65495 +# CODE-NEXT: movt r1, #65535 +# CODE-NEXT: movw r2, _a2 +# CODE-NEXT: movt r2, #0 +# CODE-NEXT: movw r3, #0 +# CODE-NEXT: movt r3, #0 + + + +# .syntax unified +# .align 2 +# +# .code 16 +# .thumb_func _t1 +#_t1: +# movw r0, :lower16:(_t2) +# movt r0, :upper16:(_t2) +# movw r1, :lower16:(_t2-(L0+4)) +# movt r1, :upper16:(_t2-(L0+4)) +# movw r2, :lower16:(_a2) +# movt r2, :upper16:(_a2) +# movw r3, :lower16:(_a2-(L0+4)) +# movt r3, :upper16:(_a2-(L0+4)) +#L0: +# add r0, pc +# bx lr +# +# +# .code 16 +# .thumb_func _t2 +#_t2: +# bx lr +# +# +# +# .code 32 +#_a1: +# movw r0, :lower16:(_t2) +# movt r0, :upper16:(_t2) +# movw r1, :lower16:(_t2-(L1+8)) +# movt r1, :upper16:(_t2-(L1+8)) +# movw r2, :lower16:(_a2) +# movt r2, :upper16:(_a2) +# movw r3, :lower16:(_a2-(L1+8)) +# movt r3, :upper16:(_a2-(L1+8)) +#L1: +# add r0, pc +# bx lr +# +#_a2: +# bx lr + diff --git a/test/mach-o/arm-interworking.yaml b/test/mach-o/arm-interworking.yaml new file mode 100644 index 000000000000..f7e04e65c9f0 --- /dev/null +++ b/test/mach-o/arm-interworking.yaml @@ -0,0 +1,362 @@ +# RUN: lld -flavor darwin -arch armv7 -r -print_atoms %s -o %t | FileCheck %s \ +# RUN: && lld -flavor darwin -arch armv7 -dylib -print_atoms \ +# RUN: %p/Inputs/libSystem.yaml %t -o %t2 | FileCheck %s \ +# RUN: && macho-dump --dump-section-data %t2 | FileCheck -check-prefix=CODE %s +# +# Test thumb and arm branches round trip through -r. +# Test bl/blx instructions are fixed up properly. +# +# + +--- !mach-o +arch: armv7 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0xFF, 0xF7, 0xFE, 0xFF, 0xC0, 0x46, 0xFF, 0xF7, + 0xFC, 0xEF, 0xC0, 0x46, 0xFF, 0xF7, 0xF8, 0xEF, + 0xFF, 0xF7, 0xF6, 0xFF, 0xC0, 0x46, 0xFF, 0xF7, + 0xF3, 0xFF, 0xC0, 0x46, 0x00, 0xF0, 0x06, 0xE8, + 0xC0, 0x46, 0x00, 0xF0, 0x03, 0xF8, 0x00, 0xF0, + 0x02, 0xF8, 0x70, 0x47, 0x70, 0x47, 0x70, 0x47 ] + relocations: + - offset: 0x00000026 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: false + symbol: 1 + - offset: 0x00000022 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: false + symbol: 1 + - offset: 0x0000001C + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: false + symbol: 1 + - offset: 0x00000016 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: false + symbol: 1 + - offset: 0x00000010 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: false + symbol: 1 + - offset: 0x0000000C + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: true + symbol: 5 + - offset: 0x00000006 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: true + symbol: 5 + - offset: 0x00000000 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: true + symbol: 4 + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + address: 0x0000000000000030 + content: [ 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000004 + type: ARM_RELOC_VANILLA + length: 2 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x00000000 + type: ARM_RELOC_VANILLA + length: 2 + pc-rel: false + extern: false + symbol: 1 +local-symbols: + - name: _t3 + type: N_SECT + sect: 1 + desc: [ N_ARM_THUMB_DEF ] + value: 0x000000000000002E + - name: _d1 + type: N_SECT + sect: 2 + value: 0x0000000000000030 +global-symbols: + - name: _t1 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_ARM_THUMB_DEF ] + value: 0x0000000000000000 + - name: _t2 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_ARM_THUMB_DEF ] + value: 0x000000000000002C +undefined-symbols: + - name: _a1 + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _a2 + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +--- !mach-o +arch: armv7 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0xFE, 0xFF, 0xFF, 0xEB, 0x02, 0x00, 0x00, 0xFA, + 0xFC, 0xFF, 0xFF, 0xEB, 0xFB, 0xFF, 0xFF, 0xFA, + 0x1E, 0xFF, 0x2F, 0xE1, 0x1E, 0xFF, 0x2F, 0xE1 ] + relocations: + - offset: 0x0000000C + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: true + symbol: 4 + - offset: 0x00000008 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: true + symbol: 3 + - offset: 0x00000004 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: false + symbol: 1 + - offset: 0x00000000 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: false + symbol: 1 + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + address: 0x0000000000000018 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000004 + type: ARM_RELOC_VANILLA + length: 2 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000000 + type: ARM_RELOC_VANILLA + length: 2 + pc-rel: false + extern: true + symbol: 3 +local-symbols: + - name: _d2 + type: N_SECT + sect: 2 + value: 0x0000000000000018 +global-symbols: + - name: _a1 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: _a2 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000014 +undefined-symbols: + - name: _t1 + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _t2 + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + + +# CHECK: defined-atoms: +# CHECK: - name: _d1 +# CHECK: type: data +# CHECK: references: +# CHECK: - kind: pointer32 +# CHECK: offset: 0 +# CHECK: target: _t2 +# CHECK: - kind: pointer32 +# CHECK: offset: 4 +# CHECK: target: _a1 +# CHECK: - name: _d2 +# CHECK: type: data +# CHECK: references: +# CHECK: - kind: pointer32 +# CHECK: offset: 0 +# CHECK: target: _t1 +# CHECK: - kind: pointer32 +# CHECK: offset: 4 +# CHECK: target: _a1 +# CHECK: - name: _t1 +# CHECK: scope: global +# CHECK: references: +# CHECK: - kind: modeThumbCode +# CHECK: offset: 0 +# CHECK: target: _t1 +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 0 +# CHECK: target: _a1 +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 6 +# CHECK: target: _a2 +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 12 +# CHECK: target: _a2 +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 16 +# CHECK: target: _t1 +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 22 +# CHECK: target: _t1 +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 28 +# CHECK: target: _t2 +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 34 +# CHECK: target: _t2 +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 38 +# CHECK: target: _t3 +# CHECK: - name: _t2 +# CHECK: scope: global +# CHECK: content: [ 70, 47 ] +# CHECK: references: +# CHECK: - kind: modeThumbCode +# CHECK: offset: 0 +# CHECK: target: _t2 +# CHECK: - name: _t3 +# CHECK: content: [ 70, 47 ] +# CHECK: references: +# CHECK: - kind: modeThumbCode +# CHECK: offset: 0 +# CHECK: target: _t3 +# CHECK: - name: _a1 +# CHECK: scope: global +# CHECK: references: +# CHECK: - kind: arm_bl24 +# CHECK: offset: 0 +# CHECK: target: _a1 +# CHECK: - kind: arm_bl24 +# CHECK: offset: 4 +# CHECK: target: _a2 +# CHECK: - kind: arm_bl24 +# CHECK: offset: 8 +# CHECK: target: _t1 +# CHECK: - kind: arm_bl24 +# CHECK: offset: 12 +# CHECK: target: _t2 +# CHECK: - name: _a2 +# CHECK: scope: global + + +# CODE: (('section_name', '__text\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +# CODE: ('segment_name', '__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +# CODE: ('_section_data', '00f016e8 c04600f0 1ee8c046 00f01ae8 fff7f6ff c046fff7 f3ffc046 00f006f8 c04600f0 03f800f0 02f87047 70477047 feffffeb 020000eb f0fffffa fafffffa 1eff2fe1 1eff2fe1') +# When we get a good mach-o disassembler the above __text section content check can be change to be symbolic. + +# CODE: (('section_name', '__data\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +# CODE: ('segment_name', '__DATA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +# CODE: ('_section_data', '{{[0-9a-f]}}{{[13579bdf]}}{{[0-9a-f]+}} {{[0-9a-f]}}{{[02468ade]}}{{[0-9a-f]+}} {{[0-9a-f]}}{{[13579bdf]}}{{[0-9a-f]+}} {{[0-9a-f]}}{{[02468ade]}}{{[0-9a-f]+}}') +# Verify the low (thumb) bit is set on the first and third pointers but not the second and fourth. + + + +# Input file one: +# +# .align 2 +# .code 16 +# .globl _t1 +# .thumb_func _t1 +#_t1: +# bl _a1 +# nop +# blx _a2 +# nop +# blx _a2 +# bl _t1 +# nop +# bl _t1 +# nop +# blx _t2 +# nop +# blx _t2 +# bx lr +# +# .globl _t2 +# .thumb_func _t2 +#_t2: +# bx lr +# +# .data +#_d1: .long _t2 +# .long _a1 + + + +# Input file two: +# +# .align 2 +# .code 32 +# .globl _a1 +#_a1: +# bl _a1 +# blx _a2 +# bl _t1 +# blx _t2 +# bx lr +# +# .globl _a2 +#_a2: +# bx lr +# +# .data +#_d2: .long _t1 +# .long _a1 + + + +
\ No newline at end of file diff --git a/test/mach-o/arm-shims.yaml b/test/mach-o/arm-shims.yaml new file mode 100644 index 000000000000..68a401ca78e8 --- /dev/null +++ b/test/mach-o/arm-shims.yaml @@ -0,0 +1,179 @@ +# RUN: lld -flavor darwin -arch armv7 %s -dylib %p/Inputs/libSystem.yaml -o %t +# RUN: macho-dump --dump-section-data %t | FileCheck %s +# +# Test b from arm to thumb or vice versa has shims added.s +# +# + +--- !mach-o +arch: armv7 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0x00, 0xBF, 0xFF, 0xF7, 0xFE, 0xEF, 0xFF, 0xF7, + 0xFB, 0xBF, 0x00, 0x00, 0x00, 0xF0, 0x20, 0xE3, + 0xFA, 0xFF, 0xFF, 0xFA, 0xF9, 0xFF, 0xFF, 0xEA ] + relocations: + - offset: 0x00000014 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: true + symbol: 3 + - offset: 0x00000010 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: true + symbol: 3 + - offset: 0x00000006 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: true + symbol: 2 + - offset: 0x00000002 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: true + symbol: 2 +global-symbols: + - name: _a1 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x000000000000000C + - name: _t1 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_ARM_THUMB_DEF ] + value: 0x0000000000000000 +undefined-symbols: + - name: _a2 + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _t2 + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + + +--- !mach-o +arch: armv7 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0x00, 0xBF, 0xFF, 0xF7, 0xFE, 0xEF, 0xFF, 0xF7, + 0xFB, 0xBF, 0x00, 0x00, 0x00, 0xF0, 0x20, 0xE3, + 0xFA, 0xFF, 0xFF, 0xFA, 0xF9, 0xFF, 0xFF, 0xEA ] + relocations: + - offset: 0x00000014 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: true + symbol: 3 + - offset: 0x00000010 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: true + symbol: 3 + - offset: 0x00000006 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: true + symbol: 2 + - offset: 0x00000002 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: true + symbol: 2 +global-symbols: + - name: _a2 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x000000000000000C + - name: _t2 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_ARM_THUMB_DEF ] + value: 0x0000000000000000 +undefined-symbols: + - name: _a1 + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _t1 + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +... + + +# CHECK: (('section_name', '__text\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +# CHECK: ('segment_name', '__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +# CHECK: ('_section_data', '00bf00f0 10e800f0 19b80000 00f020e3 000000fa 0f0000ea 00bffff7 f8ef00f0 07b80000 00f020e3 f4fffffa 050000ea dff804c0 ff446047 d4ffffff dff804c0 ff446047 e0ffffff 04c09fe5 0cc08fe0 1cff2fe1 adffffff 04c09fe5 0cc08fe0 1cff2fe1 b5ffffff') + +# When we get a good mach-o disassembler the above __text section content check can be change to be symbolic. + + +# Input file one: +# +# .align 2 +# .code 16 +# .globl _t1 +# .thumb_func _t1 +#_t1: +# nop +# blx _a2 +# b _a2 +# +# .code 32 +# .align 2 +# .globl _a1 +#_a1: +# nop +# blx _t2 +# b _t2 + + + +# Input file two: +# +# .align 2 +# .code 16 +# .globl _t2 +# .thumb_func _t2 +#_t2: +# nop +# blx _a1 +# b _a1 +# +# .code 32 +# .align 2 +# .globl _a2 +#_a2: +# nop +# blx _t1 +# b _t1 diff --git a/test/mach-o/arm-subsections-via-symbols.yaml b/test/mach-o/arm-subsections-via-symbols.yaml new file mode 100644 index 000000000000..b704568f37b1 --- /dev/null +++ b/test/mach-o/arm-subsections-via-symbols.yaml @@ -0,0 +1,60 @@ +# RUN: lld -flavor darwin -arch armv7 %s -r -print_atoms -o %t | FileCheck %s +# +# Test that assembly written without .subsections_via_symbols is parsed so +# that atoms are non-dead-strip and there is a layout-after references +# chaining atoms together. +# + +--- !mach-o +arch: armv7 +file-type: MH_OBJECT +flags: [ ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0x04, 0x10, 0x9F, 0xE5, 0x04, 0x20, 0x9F, 0xE5, + 0x1E, 0xFF, 0x2F, 0xE1, 0x78, 0x56, 0x34, 0x12, + 0x21, 0x43, 0x65, 0x87 ] +local-symbols: + - name: constants1 + type: N_SECT + sect: 1 + value: 0x000000000000000C + - name: constants2 + type: N_SECT + sect: 1 + value: 0x0000000000000010 +global-symbols: + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +... + + +# CHECK:defined-atoms: +# CHECK: - name: _foo +# CHECK: scope: global +# CHECK: content: [ 04, 10, 9F, E5, 04, 20, 9F, E5, 1E, FF, 2F, E1 ] +# CHECK: dead-strip: never +# CHECK: references: +# CHECK: - kind: layout-after +# CHECK: offset: 0 +# CHECK: target: constants1 +# CHECK: - name: constants1 +# CHECK: content: [ 78, 56, 34, 12 ] +# CHECK: dead-strip: never +# CHECK: references: +# CHECK: - kind: layout-after +# CHECK: offset: 0 +# CHECK: target: constants2 +# CHECK: - name: constants2 +# CHECK: content: [ 21, 43, 65, 87 ] +# CHECK: dead-strip: never diff --git a/test/mach-o/cstring-sections.yaml b/test/mach-o/cstring-sections.yaml new file mode 100644 index 000000000000..940f048b5c6c --- /dev/null +++ b/test/mach-o/cstring-sections.yaml @@ -0,0 +1,91 @@ +# RUN: lld -flavor darwin -arch x86_64 -r %s -o %t -print_atoms | FileCheck %s +# +# Test -keep_private_externs in -r mode. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __objc_methname + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x0000000000000000 + content: [ 0x61, 0x62, 0x63, 0x00, 0x64, 0x65, 0x66, 0x00 ] + - segment: __TEXT + section: __objc_classname + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x0000000000000006 + content: [ 0x61, 0x62, 0x63, 0x00, 0x67, 0x68, 0x69, 0x00 ] + - segment: __TEXT + section: __cstring + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x000000000000000A + content: [ 0x61, 0x62, 0x63, 0x00, 0x6A, 0x6B, 0x6C, 0x00 ] + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __objc_methname + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x0000000000000000 + content: [ 0x61, 0x62, 0x63, 0x00 ] + - segment: __TEXT + section: __objc_classname + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x0000000000000006 + content: [ 0x61, 0x62, 0x63, 0x00 ] + - segment: __TEXT + section: __cstring + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x000000000000000A + content: [ 0x61, 0x62, 0x63, 0x00 ] + + +... + +# CHECK: defined-atoms: +# CHECK: - scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 61, 62, 63, 00 ] +# CHECK: merge: by-content +# CHECK: section-choice: custom-required +# CHECK: section-name: __TEXT/__objc_methname +# CHECK: - scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 64, 65, 66, 00 ] +# CHECK: merge: by-content +# CHECK: section-choice: custom-required +# CHECK: section-name: __TEXT/__objc_methname +# CHECK: - scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 61, 62, 63, 00 ] +# CHECK: merge: by-content +# CHECK: section-choice: custom-required +# CHECK: section-name: __TEXT/__objc_classname +# CHECK: - scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 67, 68, 69, 00 ] +# CHECK: merge: by-content +# CHECK: section-choice: custom-required +# CHECK: section-name: __TEXT/__objc_classname +# CHECK: - scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 61, 62, 63, 00 ] +# CHECK: merge: by-content +# CHECK: - scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 6A, 6B, 6C, 00 ] +# CHECK: merge: by-content diff --git a/test/mach-o/data-only-dylib.yaml b/test/mach-o/data-only-dylib.yaml new file mode 100644 index 000000000000..c285066ad778 --- /dev/null +++ b/test/mach-o/data-only-dylib.yaml @@ -0,0 +1,27 @@ +# RUN: lld -flavor darwin -arch x86_64 -dylib %s -o %t %p/Inputs/libSystem.yaml +# RUN: llvm-nm %t | FileCheck %s +# +# Test that a data-only dylib can be built. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0x00, 0x00, 0x00, 0x00 ] +global-symbols: + - name: _myData + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +... + +# CHECK: _myData diff --git a/test/mach-o/demangle.yaml b/test/mach-o/demangle.yaml new file mode 100644 index 000000000000..640545808477 --- /dev/null +++ b/test/mach-o/demangle.yaml @@ -0,0 +1,74 @@ +# REQUIRES: system-linker-mach-o +# +# RUN: not lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s \ +# RUN: -dylib -o %t %p/Inputs/libSystem.yaml 2> %t.err +# RUN: FileCheck %s < %t.err +# +# RUN: not lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s \ +# RUN: -dylib -o %t %p/Inputs/libSystem.yaml -demangle 2> %t.err2 +# RUN: FileCheck %s --check-prefix=DCHECK < %t.err2 +# +# Test -demangle option works on undefined symbol errors. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xE8, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x00, 0x00, + 0x00, 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x0000000B + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 2 + - offset: 0x00000006 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 3 + - offset: 0x00000001 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 1 +global-symbols: + - name: __Z1xv + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: __Znam + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: __Znotcpp + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _foo + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +... + +# CHECK: __Znotcpp +# CHECK: __Znam +# CHECK: _foo + +# DCHECK: __Znotcpp +# DCHECK: operator new[](unsigned long) +# DCHECK: _foo + diff --git a/test/mach-o/dependency_info.yaml b/test/mach-o/dependency_info.yaml new file mode 100644 index 000000000000..dcce4381dfd3 --- /dev/null +++ b/test/mach-o/dependency_info.yaml @@ -0,0 +1,24 @@ +# XFAIL: win32 +# This test fails on Windows because the linker would use '\' instead +# of '/' as a path separator when concatenating path components. +# So the output from the linker would be different. + +# Test -dependency_info option +# +# RUN: lld -flavor darwin -arch x86_64 -test_file_usage \ +# RUN: -dependency_info %t.info \ +# RUN: -path_exists /System/Library/Frameworks \ +# RUN: -path_exists /System/Library/Frameworks/Foo.framework/Foo \ +# RUN: -path_exists /Custom/Frameworks \ +# RUN: -path_exists /Custom/Frameworks/Bar.framework/Bar \ +# RUN: -F/Custom/Frameworks \ +# RUN: -framework Bar \ +# RUN: -framework Foo +# RUN: python %p/Inputs/DependencyDump.py %t.info | FileCheck %s + + +# CHECK: linker-vers: lld +# CHECK: input-file: /Custom/Frameworks/Bar.framework/Bar +# CHECK: not-found: /Custom/Frameworks/Foo.framework/Foo +# CHECK: input-file: /System/Library/Frameworks/Foo.framework/Foo +# CHECK: output-file: a.out diff --git a/test/mach-o/dso_handle.yaml b/test/mach-o/dso_handle.yaml new file mode 100644 index 000000000000..d39d2c230806 --- /dev/null +++ b/test/mach-o/dso_handle.yaml @@ -0,0 +1,62 @@ +# RUN: lld -flavor darwin -arch x86_64 %s %p/Inputs/libSystem.yaml -o %t1 +# RUN: llvm-nm -m -n %t1 | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 %s %p/Inputs/libSystem.yaml -dead_strip -o %t2 +# RUN: llvm-nm -m -n %t2 | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 %s %p/Inputs/libSystem.yaml -dylib -o %t3 +# RUN: llvm-nm -m -n %t3 | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 %s %p/Inputs/libSystem.yaml -bundle -o %t4 +# RUN: llvm-nm -m -n %t4 | FileCheck %s +# +# Test that ___dso_handle symbol is available for executables, bundles, and dylibs +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x31, 0xC0, 0x5D, 0xC3 ] + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 3 + address: 0x0000000000000008 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000000 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 2 +global-symbols: + - name: _d + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x0000000000000008 + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: ___dso_handle + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + + +... + +# CHECK_NOT: ___dso_handle +# CHECK: _main diff --git a/test/mach-o/dylib-exports.yaml b/test/mach-o/dylib-exports.yaml new file mode 100644 index 000000000000..0a00dfe1e952 --- /dev/null +++ b/test/mach-o/dylib-exports.yaml @@ -0,0 +1,41 @@ +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 -dylib \ +# RUN: %s %p/Inputs/libSystem.yaml -o %t && \ +# RUN: llvm-objdump -exports-trie %t | FileCheck %s +# +# +# Tests that exports trie builds properly. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xC3, 0xC3, 0xC3 ] +global-symbols: + - name: _myHidden + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 1 + value: 0x0000000000000000 + - name: _myRegular + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000001 + - name: _myWeak + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_WEAK_DEF ] + value: 0x0000000000000002 +... + +# CHECK-NOT: _myHidden +# CHECK: _myRegular +# CHECK: _myWeak [weak_def] diff --git a/test/mach-o/dylib-install-names.yaml b/test/mach-o/dylib-install-names.yaml new file mode 100644 index 000000000000..845085be42ab --- /dev/null +++ b/test/mach-o/dylib-install-names.yaml @@ -0,0 +1,74 @@ +# Check we accept -install_name correctly: +# RUN: lld -flavor darwin -arch x86_64 -install_name libwibble.dylib -dylib \ +# RUN: -compatibility_version 2.0 -current_version 5.3 \ +# RUN: %p/Inputs/libSystem.yaml %s -o %t.dylib +# RUN: llvm-objdump -private-headers %t.dylib | FileCheck %s --check-prefix=CHECK-BINARY-WRITE + +# Check we read LC_ID_DYLIB correctly: +# RUN: lld -flavor darwin -arch x86_64 %p/Inputs/use-dylib-install-names.yaml \ +# RUN: %p/Inputs/libSystem.yaml %t.dylib -dylib -o %t2.dylib +# RUN: llvm-objdump -private-headers %t2.dylib | FileCheck %s --check-prefix=CHECK-BINARY-READ + +# Check we default the install-name to the output file: +# RUN: lld -flavor darwin -arch x86_64 -dylib %s -o libwibble.dylib \ +# RUN: -compatibility_version 2.0 -current_version 5.3 \ +# RUN: %p/Inputs/libSystem.yaml +# RUN: llvm-objdump -private-headers libwibble.dylib | FileCheck %s --check-prefix=CHECK-BINARY-WRITE +# RUN: rm -f libwibble.dylib + +# Check -single_module does nothing +# RUN: lld -flavor darwin -arch x86_64 -dylib %s -install_name libwibble.dylib \ +# RUN: -compatibility_version 2.0 -current_version 5.3 \ +# RUN: -single_module -o %t2.dylib %p/Inputs/libSystem.yaml +# RUN: llvm-objdump -private-headers %t2.dylib | FileCheck %s --check-prefix=CHECK-BINARY-WRITE + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0xCC, 0xC3, 0x90, 0xC3, 0x90, 0x90, 0xC3, 0x90, + 0x90, 0x90, 0xC3, 0x90, 0x90, 0x90, 0x90, 0xC3, + 0x31, 0xC0, 0xC3 ] +local-symbols: + - name: _myStatic + type: N_SECT + sect: 1 + value: 0x000000000000000B +global-symbols: + - name: _myGlobal + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000001 +... + + +# CHECK-BINARY-WRITE: cmd LC_ID_DYLIB +# CHECK-BINARY-WRITE-NEXT: cmdsize 40 +# CHECK-BINARY-WRITE-NEXT: name libwibble.dylib (offset 24) +# CHECK-BINARY-WRITE-NEXT: time stamp 1 +# CHECK-BINARY-WRITE-NEXT: current version 5.3.0 +# CHECK-BINARY-WRITE-NEXT: compatibility version 2.0.0 + +# CHECK-BINARY-READ: cmd LC_LOAD_DYLIB +# CHECK-BINARY-READ-NEXT: cmdsize 56 +# CHECK-BINARY-READ-NEXT: name /usr/lib/libSystem.B.dylib (offset 24) +# CHECK-BINARY-READ-NEXT: time stamp 2 +# CHECK-BINARY-READ-NEXT: current version 0.16.0 +# CHECK-BINARY-READ-NEXT: compatibility version 0.16.0 + +# CHECK-BINARY-READ: cmd LC_LOAD_DYLIB +# CHECK-BINARY-READ-NEXT: cmdsize 40 +# CHECK-BINARY-READ-NEXT: name libwibble.dylib (offset 24) +# CHECK-BINARY-READ-NEXT: time stamp 2 +# CHECK-BINARY-READ-NEXT: current version 5.3.0 +# CHECK-BINARY-READ-NEXT: compatibility version 2.0.0 diff --git a/test/mach-o/exe-offsets.yaml b/test/mach-o/exe-offsets.yaml new file mode 100644 index 000000000000..a751507432ee --- /dev/null +++ b/test/mach-o/exe-offsets.yaml @@ -0,0 +1,45 @@ +# RUN: lld -flavor darwin -arch x86_64 %s -o %t -e start %p/Inputs/libSystem.yaml +# RUN: llvm-readobj -sections %t | FileCheck %s + +# Make sure data gets put at offset + +--- !native +defined-atoms: + - name: start + scope: global + content: [ 90 ] + + - name: _s1 + type: data + content: [ 31, 32, 33, 34 ] + + - name: _s2 + type: zero-fill + size: 8192 + + - name: _s3 + type: zero-fill + size: 100 + + - name: _s4 + type: data + content: [ 01 ] + + +# CHECK-LABEL: Section { +# CHECK: Name: __text +# CHECK: Segment: __TEXT +# CHECK: Size: 0x1 +# CHECK: Offset: 0 + +# CHECK-LABEL: Section { +# CHECK: Name: __data +# CHECK: Segment: __DATA +# CHECK: Size: 0x5 +# CHECK: Offset: 4096 + +# CHECK-LABEL: Section { +# CHECK: Name: __bss +# CHECK: Segment: __DATA +# CHECK: Size: 0x2064 +# CHECK: Offset: 0 diff --git a/test/mach-o/exe-segment-overlap.yaml b/test/mach-o/exe-segment-overlap.yaml new file mode 100644 index 000000000000..a416ee3ca73b --- /dev/null +++ b/test/mach-o/exe-segment-overlap.yaml @@ -0,0 +1,44 @@ +# RUN: lld -flavor darwin -arch x86_64 %s -o %t %p/Inputs/libSystem.yaml +# RUN: llvm-readobj -sections -section-data %t | FileCheck %s + +--- !native +defined-atoms: + - name: _main + scope: global + content: [ 90 ] + + - name: _s2 + type: data + content: [ 31, 32, 33, 34 ] + + - name: _kustom + scope: global + type: unknown + content: [ 01, 02, 03, 04, 05, 06, 07, 08 ] + section-choice: custom-required + section-name: __CUST/__custom + + +# CHECK-LABEL: Section { +# CHECK: Name: __text +# CHECK: Segment: __TEXT +# CHECK: Size: 0x1 +# CHECK: Offset: 4095 + +# CHECK-LABEL: Section { +# CHECK: Name: __data +# CHECK: Segment: __DATA +# CHECK: Size: 0x4 +# CHECK: Offset: 4096 +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 31323334 +# CHECK-NEXT: ) + +# CHECK-LABEL: Section { +# CHECK: Name: __custom{{ }} +# CHECK: Segment: __CUST{{ }} +# CHECK: Size: 0x8 +# CHECK: Offset: 8192 +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 01020304 05060708 +# CHECK-NEXT: ) diff --git a/test/mach-o/exported_symbols_list-dylib.yaml b/test/mach-o/exported_symbols_list-dylib.yaml new file mode 100644 index 000000000000..71121d7400f6 --- /dev/null +++ b/test/mach-o/exported_symbols_list-dylib.yaml @@ -0,0 +1,77 @@ +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 -dylib \ +# RUN: %s %p/Inputs/libSystem.yaml -o %t \ +# RUN: -exported_symbols_list %p/Inputs/exported_symbols_list.exp && \ +# RUN: llvm-nm -m %t | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 -dylib \ +# RUN: %s %p/Inputs/libSystem.yaml -o %t2 \ +# RUN: -exported_symbol _foo -exported_symbol _b && \ +# RUN: llvm-nm -m %t2 | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 -dylib \ +# RUN: %s %p/Inputs/libSystem.yaml -o %t3 \ +# RUN: -unexported_symbol _bar -unexported_symbol _a && \ +# RUN: llvm-nm -m %t3 | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 -dylib \ +# RUN: %s %p/Inputs/libSystem.yaml -dead_strip -o %t \ +# RUN: -exported_symbols_list %p/Inputs/exported_symbols_list.exp && \ +# RUN: llvm-nm -m %t | FileCheck -check-prefix=CHECK_DEAD %s +# +# Test -exported_symbols_list and -exported_symbol properly changes visibility. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x5D, 0xC3, 0x55, 0x48, + 0x89, 0xE5, 0x5D, 0xC3 ] + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x000000000000000C + content: [ 0x0A, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 ] + +global-symbols: + - name: _a + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x000000000000000C + - name: _b + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x0000000000000010 + - name: _bar + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000006 + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + + +... + +# CHECK: (__DATA,__data) non-external (was a private external) _a +# CHECK: (__DATA,__data) external _b +# CHECK: (__TEXT,__text) non-external (was a private external) _bar +# CHECK: (__TEXT,__text) external _foo + +# CHECK_DEAD-NOT: (__DATA,__data) non-external (was a private external) _a +# CHECK_DEAD: (__DATA,__data) external _b +# CHECK_DEAD-NOT: (__TEXT,__text) non-external (was a private external) _bar +# CHECK_DEAD: (__TEXT,__text) external _foo diff --git a/test/mach-o/exported_symbols_list-obj.yaml b/test/mach-o/exported_symbols_list-obj.yaml new file mode 100644 index 000000000000..735162dfedc8 --- /dev/null +++ b/test/mach-o/exported_symbols_list-obj.yaml @@ -0,0 +1,67 @@ +# RUN: lld -flavor darwin -arch x86_64 -r %s -o %t -exported_symbol _bar \ +# RUN: && llvm-nm -m %t | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 -r %s -o %t2 -keep_private_externs \ +# RUN: -exported_symbol _bar && \ +# RUN: llvm-nm -m %t2 | FileCheck -check-prefix=CHECK_KPE %s +# +# RUN: not lld -flavor darwin -arch x86_64 -r %s -o %t3 \ +# RUN: -exported_symbol _foo 2> %t4 + +# Test -exported_symbols_list properly changes visibility in -r mode. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x5D, 0xC3, 0x55, 0x48, + 0x89, 0xE5, 0x5D, 0xC3 ] + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x000000000000000C + content: [ 0x0A, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 ] + +global-symbols: + - name: _a + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x000000000000000C + - name: _b + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 2 + value: 0x0000000000000010 + - name: _bar + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000006 + - name: _foo + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 1 + value: 0x0000000000000000 + + +... + +# CHECK: (__DATA,__data) non-external (was a private external) _a +# CHECK: (__DATA,__data) non-external (was a private external) _b +# CHECK: (__TEXT,__text) external _bar +# CHECK: (__TEXT,__text) non-external (was a private external) _foo + +# CHECK_KPE: (__DATA,__data) non-external (was a private external) _a +# CHECK_KPE: (__DATA,__data) private external _b +# CHECK_KPE: (__TEXT,__text) external _bar +# CHECK_KPE: (__TEXT,__text) private external _foo diff --git a/test/mach-o/exported_symbols_list-undef.yaml b/test/mach-o/exported_symbols_list-undef.yaml new file mode 100644 index 000000000000..c6a8d8f4022f --- /dev/null +++ b/test/mach-o/exported_symbols_list-undef.yaml @@ -0,0 +1,55 @@ +# RUN: not lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 -dylib \ +# RUN: %s %p/Inputs/libSystem.yaml -o %t -exported_symbol _foobar 2> %t2 +# +# Test -exported_symbol fails if exported symbol not found. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x5D, 0xC3, 0x55, 0x48, + 0x89, 0xE5, 0x5D, 0xC3 ] + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x000000000000000C + content: [ 0x0A, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 ] + +global-symbols: + - name: _a + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x000000000000000C + - name: _b + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x0000000000000010 + - name: _bar + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000006 + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + + +... + +# CHECK: (__DATA,__data) private external _a +# CHECK: (__DATA,__data) external _b +# CHECK: (__TEXT,__text) private external _bar +# CHECK: (__TEXT,__text) external _foo diff --git a/test/mach-o/fat-archive.yaml b/test/mach-o/fat-archive.yaml new file mode 100644 index 000000000000..5db7fd96ff0e --- /dev/null +++ b/test/mach-o/fat-archive.yaml @@ -0,0 +1,45 @@ +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t \ +# RUN: -L %p/Inputs -lfoo %p/Inputs/libSystem.yaml +# RUN: llvm-nm -m -n %t | FileCheck %s +# +# Test that fat archives are handled. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x48, 0x83, 0xEC, 0x10, + 0xC7, 0x45, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xB0, + 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x31, 0xC0, + 0x48, 0x83, 0xC4, 0x10, 0x5D, 0xC3 ] + relocations: + - offset: 0x00000012 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 1 +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _foo + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +... + +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _foo diff --git a/test/mach-o/filelist.yaml b/test/mach-o/filelist.yaml new file mode 100644 index 000000000000..28bfeb74d02b --- /dev/null +++ b/test/mach-o/filelist.yaml @@ -0,0 +1,18 @@ +# RUN: lld -flavor darwin -test_file_usage \ +# RUN: -filelist %p/Inputs/full.filelist \ +# RUN: -path_exists /foo/bar/a.o \ +# RUN: -path_exists /foo/bar/b.o \ +# RUN: -path_exists /foo/x.a \ +# RUN: 2>&1 | FileCheck %s +# +# RUN: lld -flavor darwin -test_file_usage -t \ +# RUN: -filelist %p/Inputs/partial.filelist,/foo \ +# RUN: -path_exists /foo/bar/a.o \ +# RUN: -path_exists /foo/bar/b.o \ +# RUN: -path_exists /foo/x.a \ +# RUN: 2>&1 | FileCheck %s + + +# CHECK: Found filelist entry /foo/bar/a.o +# CHECK: Found filelist entry /foo/bar/b.o +# CHECK: Found filelist entry /foo/x.a diff --git a/test/mach-o/force_load-dylib.yaml b/test/mach-o/force_load-dylib.yaml new file mode 100644 index 000000000000..0b932e159882 --- /dev/null +++ b/test/mach-o/force_load-dylib.yaml @@ -0,0 +1,45 @@ +# RUN: lld -flavor darwin -arch x86_64 -dylib %p/Inputs/bar.yaml \ +# RUN: -install_name /usr/lib/libbar.dylib %p/Inputs/libSystem.yaml -o %t1.dylib +# RUN: lld -flavor darwin -arch x86_64 -dylib %s -all_load %t1.dylib \ +# RUN: -install_name /usr/lib/libfoo.dylib %p/Inputs/libSystem.yaml -o %t +# RUN: llvm-nm -m %t | FileCheck %s +# +# +# Test -all_load does not break linking with dylibs +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x31, 0xC0, 0x5D, 0xE9, + 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000008 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 1 +global-symbols: + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _bar + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +... + + +# CHECK: (__TEXT,__text) external _foo diff --git a/test/mach-o/force_load-x86_64.yaml b/test/mach-o/force_load-x86_64.yaml new file mode 100644 index 000000000000..35905effd2c4 --- /dev/null +++ b/test/mach-o/force_load-x86_64.yaml @@ -0,0 +1,38 @@ +# RUN: lld -flavor darwin -arch x86_64 %s %p/Inputs/libSystem.yaml \ +# RUN: %p/Inputs/libfoo.a %p/Inputs/libbar.a -o %t1 +# RUN: llvm-nm -m -n %t1 | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 %s %p/Inputs/libSystem.yaml \ +# RUN: -force_load %p/Inputs/libfoo.a %p/Inputs/libbar.a -o %t2 +# RUN: llvm-nm -m -n %t2 | FileCheck --check-prefix=CHECKF %s +# +# Test that -force_load causes members of static library to be loaded. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xC3 ] +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +... + +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main +# CHECK-NOT: {{[0-9a-f]+}} (__TEXT,__text) external _main + +# CHECKF: {{[0-9a-f]+}} (__TEXT,__text) external _main +# CHECKF: {{[0-9a-f]+}} (__TEXT,__text) external _foo +# CHECKF-NOT: {{[0-9a-f]+}} (__TEXT,__text) external _bar diff --git a/test/mach-o/framework-user-paths.yaml b/test/mach-o/framework-user-paths.yaml new file mode 100644 index 000000000000..f6ac64779a71 --- /dev/null +++ b/test/mach-o/framework-user-paths.yaml @@ -0,0 +1,41 @@ +# +# Test framework and SDK search paths. +# myFrameworks is not an absolute path, so it should not by found in SDK +# /Custom/Frameworks should be found in SDK +# /opt/Frameworks should not be found in SDK +# /System/Library/Frameworks is implicit and should be in SDK +# +# RUN: lld -flavor darwin -arch x86_64 -r -test_file_usage -v \ +# RUN: -path_exists myFrameworks \ +# RUN: -path_exists myFrameworks/my.framework/my \ +# RUN: -path_exists /opt/Frameworks \ +# RUN: -path_exists /opt/Frameworks/other.framework/other \ +# RUN: -path_exists /Custom/Frameworks \ +# RUN: -path_exists /Custom/Frameworks/Bar.framework/Bar \ +# RUN: -path_exists /System/Library/Frameworks \ +# RUN: -path_exists /System/Library/Frameworks/Foo.framework/Foo \ +# RUN: -path_exists /SDK/myFrameworks \ +# RUN: -path_exists /SDK/myFrameworks/my.framework/my \ +# RUN: -path_exists /SDK/Custom/Frameworks \ +# RUN: -path_exists /SDK/Custom/Frameworks/Bar.framework/Bar \ +# RUN: -path_exists /SDK/System/Library/Frameworks \ +# RUN: -path_exists /SDK/System/Library/Frameworks/Foo.framework/Foo \ +# RUN: -syslibroot /SDK \ +# RUN: -FmyFrameworks \ +# RUN: -F/Custom/Frameworks \ +# RUN: -F/opt/Frameworks \ +# RUN: -framework my \ +# RUN: -framework Bar \ +# RUN: -framework Foo \ +# RUN: -framework other \ +# RUN: 2>&1 | FileCheck %s + +# CHECK: Framework search paths: +# CHECK-NEXT: myFrameworks +# CHECK-NEXT: /SDK/Custom/Frameworks +# CHECK-NEXT: /opt/Frameworks +# CHECK-NEXT: /SDK/System/Library/Frameworks +# CHECK: Found framework myFrameworks/my.framework/my +# CHECK: Found framework /SDK/Custom/Frameworks/Bar.framework/Bar +# CHECK: Found framework /SDK/System/Library/Frameworks/Foo.framework/Foo +# CHECK: Found framework /opt/Frameworks/other.framework/other diff --git a/test/mach-o/got-order.yaml b/test/mach-o/got-order.yaml new file mode 100644 index 000000000000..fbbc4e0397f2 --- /dev/null +++ b/test/mach-o/got-order.yaml @@ -0,0 +1,134 @@ +# RUN: lld -flavor darwin -arch x86_64 %s -o %t %p/Inputs/libSystem.yaml +# RUN: llvm-objdump -bind %t | FileCheck %s +# +# Test that GOT slots are sorted by name +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x48, 0x8B, 0x0D, 0x00, + 0x00, 0x00, 0x00, 0x48, 0x8B, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x8B, 0x00, 0x03, 0x01, 0x48, 0x8B, + 0x0D, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x5D, + 0xC3 ] + relocations: + - offset: 0x00000019 + type: X86_64_RELOC_GOT_LOAD + length: 2 + pc-rel: true + extern: true + symbol: 2 + - offset: 0x0000000E + type: X86_64_RELOC_GOT_LOAD + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x00000007 + type: X86_64_RELOC_GOT_LOAD + length: 2 + pc-rel: true + extern: true + symbol: 3 +global-symbols: + - name: _func + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _aaa + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _fff + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _zzz + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x48, 0x8B, 0x0D, 0x00, + 0x00, 0x00, 0x00, 0x48, 0x8B, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x8B, 0x00, 0x03, 0x01, 0x48, 0x8B, + 0x0D, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x5D, + 0xC3 ] + relocations: + - offset: 0x00000019 + type: X86_64_RELOC_GOT_LOAD + length: 2 + pc-rel: true + extern: true + symbol: 2 + - offset: 0x0000000E + type: X86_64_RELOC_GOT_LOAD + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x00000007 + type: X86_64_RELOC_GOT_LOAD + length: 2 + pc-rel: true + extern: true + symbol: 3 +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _bar + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _foo + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _zazzle + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +install-name: /usr/lib/libfoobar.dylib +exports: + - name: _bar + - name: _zazzle + - name: _foo + - name: _aaa + - name: _fff + - name: _zzz +... + + +# CHECK: __DATA __got {{[0-9a-zA-Z _]+}} pointer 0 libfoobar _aaa +# CHECK-NEXT: __DATA __got {{[0-9a-zA-Z _]+}} pointer 0 libfoobar _bar +# CHECK-NEXT: __DATA __got {{[0-9a-zA-Z _]+}} pointer 0 libfoobar _fff +# CHECK-NEXT: __DATA __got {{[0-9a-zA-Z _]+}} pointer 0 libfoobar _foo +# CHECK-NEXT: __DATA __got {{[0-9a-zA-Z _]+}} pointer 0 libfoobar _zazzle +# CHECK-NEXT: __DATA __got {{[0-9a-zA-Z _]+}} pointer 0 libfoobar _zzz diff --git a/test/mach-o/hello-world-arm64.yaml b/test/mach-o/hello-world-arm64.yaml new file mode 100644 index 000000000000..a0555e9cc426 --- /dev/null +++ b/test/mach-o/hello-world-arm64.yaml @@ -0,0 +1,104 @@ +# RUN: lld -flavor darwin -arch arm64 %s -o %t +# RUN: llvm-nm -m -n %t | FileCheck %s +# +# Test that arm64 hello-world can be linked into a mach-o executable +# + +--- !mach-o +arch: arm64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0xFD, 0x7B, 0xBF, 0xA9, 0xFD, 0x03, 0x00, 0x91, + 0x08, 0x00, 0x00, 0x90, 0x08, 0x01, 0x40, 0xF9, + 0x00, 0x01, 0x40, 0xF9, 0x01, 0x00, 0x00, 0x90, + 0x21, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x94, + 0x00, 0x00, 0x80, 0x52, 0xFD, 0x7B, 0xC1, 0xA8, + 0xC0, 0x03, 0x5F, 0xD6 ] + relocations: + - offset: 0x0000001C + type: ARM64_RELOC_BRANCH26 + length: 2 + pc-rel: true + extern: true + symbol: 5 + - offset: 0x00000018 + type: ARM64_RELOC_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000014 + type: ARM64_RELOC_PAGE21 + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x0000000C + type: ARM64_RELOC_GOT_LOAD_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x00000008 + type: ARM64_RELOC_GOT_LOAD_PAGE21 + length: 2 + pc-rel: true + extern: true + symbol: 4 + - segment: __TEXT + section: __cstring + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x000000000000002C + content: [ 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x0A, 0x00 ] +local-symbols: + - name: ltmp0 + type: N_SECT + sect: 1 + value: 0x0000000000000000 + - name: l_.str + type: N_SECT + sect: 2 + value: 0x000000000000002C + - name: ltmp1 + type: N_SECT + sect: 2 + value: 0x000000000000002C +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: ___stdoutp + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _fprintf + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + +--- !mach-o +arch: arm64 +file-type: MH_DYLIB +install-name: /usr/lib/libSystem.B.dylib +exports: + - name: _fprintf + - name: ___stdoutp + - name: dyld_stub_binder +... + +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main +# CHECK: (undefined) external ___stdoutp (from libSystem) +# CHECK: (undefined) external _fprintf (from libSystem) +# CHECK: (undefined) external dyld_stub_binder (from libSystem) diff --git a/test/mach-o/hello-world-armv6.yaml b/test/mach-o/hello-world-armv6.yaml new file mode 100644 index 000000000000..746ee094da68 --- /dev/null +++ b/test/mach-o/hello-world-armv6.yaml @@ -0,0 +1,72 @@ +# RUN: lld -flavor darwin -arch armv6 %s -o %t +# RUN: llvm-nm -m %t | FileCheck %s +# +# Test that armv6 (arm) hello-world can be linked into a mach-o executable +# + +--- !mach-o +arch: armv6 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0x80, 0x40, 0x2D, 0xE9, 0x10, 0x00, 0x9F, 0xE5, + 0x0D, 0x70, 0xA0, 0xE1, 0x00, 0x00, 0x8F, 0xE0, + 0xFA, 0xFF, 0xFF, 0xEB, 0x00, 0x00, 0xA0, 0xE3, + 0x80, 0x80, 0xBD, 0xE8, 0x0C, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x0000001C + scattered: true + type: ARM_RELOC_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000020 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x0000000C + - offset: 0x00000010 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: true + symbol: 1 + - segment: __TEXT + section: __cstring + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x0000000000000020 + content: [ 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x0A, 0x00 ] +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _printf + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +--- !mach-o +arch: armv6 +file-type: MH_DYLIB +install-name: /usr/lib/libSystem.B.dylib +exports: + - name: _printf + - name: dyld_stub_binder +... + +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main +# CHECK: (undefined) external _printf (from libSystem) +# CHECK: (undefined) external dyld_stub_binder (from libSystem) diff --git a/test/mach-o/hello-world-armv7.yaml b/test/mach-o/hello-world-armv7.yaml new file mode 100644 index 000000000000..bfc03c382a05 --- /dev/null +++ b/test/mach-o/hello-world-armv7.yaml @@ -0,0 +1,85 @@ +# RUN: lld -flavor darwin -arch armv7 %s -o %t +# RUN: llvm-nm -m -n %t | FileCheck %s +# +# Test that armv7 (thumb) hello-world can be linked into a mach-o executable +# + +--- !mach-o +arch: armv7 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0x80, 0xB5, 0x40, 0xF2, 0x06, 0x00, 0x6F, 0x46, + 0xC0, 0xF2, 0x00, 0x00, 0x78, 0x44, 0xFF, 0xF7, + 0xF8, 0xEF, 0x00, 0x20, 0x80, 0xBD ] + relocations: + - offset: 0x0000000E + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x00000008 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 3 + pc-rel: false + value: 0x00000016 + - offset: 0x00000006 + scattered: true + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + value: 0x0000000C + - offset: 0x00000002 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000016 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x0000000C + - segment: __TEXT + section: __cstring + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x0000000000000016 + content: [ 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x0A, 0x00 ] +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_ARM_THUMB_DEF ] + value: 0x0000000000000000 +undefined-symbols: + - name: _printf + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + +--- !mach-o +arch: armv7 +file-type: MH_DYLIB +install-name: /usr/lib/libSystem.B.dylib +exports: + - name: _printf + - name: dyld_stub_binder +... + +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external [Thumb] _main +# CHECK: (undefined) external _printf (from libSystem) +# CHECK: (undefined) external dyld_stub_binder (from libSystem) diff --git a/test/mach-o/hello-world-x86.yaml b/test/mach-o/hello-world-x86.yaml new file mode 100644 index 000000000000..de453ed1ac45 --- /dev/null +++ b/test/mach-o/hello-world-x86.yaml @@ -0,0 +1,71 @@ +# RUN: lld -flavor darwin -arch i386 %s -o %t +# RUN: llvm-nm -m %t | FileCheck %s +# +# Test that i386 hello-world can be linked into a mach-o executable +# + +--- !mach-o +arch: x86 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x89, 0xE5, 0x83, 0xEC, 0x08, 0xE8, 0x00, + 0x00, 0x00, 0x00, 0x58, 0x8D, 0x80, 0x16, 0x00, + 0x00, 0x00, 0x89, 0x04, 0x24, 0xE8, 0xE6, 0xFF, + 0xFF, 0xFF, 0x31, 0xC0, 0x83, 0xC4, 0x08, 0x5D, + 0xC3 ] + relocations: + - offset: 0x00000016 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x0000000E + scattered: true + type: GENERIC_RELOC_LOCAL_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000021 + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x0000000B + - segment: __TEXT + section: __cstring + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x0000000000000021 + content: [ 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x0A, 0x00 ] +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _printf + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +--- !mach-o +arch: x86 +file-type: MH_DYLIB +install-name: /usr/lib/libSystem.B.dylib +exports: + - name: _printf + - name: dyld_stub_binder + +... + +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main +# CHECK: (undefined) external _printf (from libSystem) +# CHECK: (undefined) external dyld_stub_binder (from libSystem) diff --git a/test/mach-o/hello-world-x86_64.yaml b/test/mach-o/hello-world-x86_64.yaml new file mode 100644 index 000000000000..83d4fcb32601 --- /dev/null +++ b/test/mach-o/hello-world-x86_64.yaml @@ -0,0 +1,126 @@ +# RUN: lld -flavor darwin -arch x86_64 %s -o %t +# RUN: llvm-nm -m -n %t | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 %s -dead_strip -o %t2 +# RUN: llvm-nm -m -n %t2 | FileCheck %s +# +# Test that x86_64 hello-world can be linked into a mach-o executable +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x48, 0x8B, 0x05, 0x00, + 0x00, 0x00, 0x00, 0x48, 0x8B, 0x38, 0x48, 0x8D, + 0x35, 0x00, 0x00, 0x00, 0x00, 0x31, 0xC0, 0xE8, + 0x00, 0x00, 0x00, 0x00, 0x31, 0xC0, 0x5D, 0xC3 ] + relocations: + - offset: 0x00000018 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 5 + - offset: 0x00000011 + type: X86_64_RELOC_SIGNED + length: 2 + pc-rel: true + extern: true + symbol: 0 + - offset: 0x00000007 + type: X86_64_RELOC_GOT_LOAD + length: 2 + pc-rel: true + extern: true + symbol: 4 + - segment: __TEXT + section: __cstring + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x0000000000000020 + content: [ 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x0A, 0x00 ] + - segment: __LD + section: __compact_unwind + type: S_REGULAR + attributes: [ ] + alignment: 3 + address: 0x0000000000000028 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000000 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: false + symbol: 1 + - segment: __TEXT + section: __eh_frame + type: S_COALESCED + attributes: [ ] + alignment: 3 + address: 0x0000000000000048 + content: [ 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x7A, 0x52, 0x00, 0x01, 0x78, 0x10, 0x01, + 0x10, 0x0C, 0x07, 0x08, 0x90, 0x01, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, + 0x98, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x41, 0x0E, 0x10, 0x86, 0x02, 0x43, 0x0D, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] +local-symbols: + - name: L1 + type: N_SECT + sect: 2 + value: 0x0000000000000020 + - name: EH_frame0 + type: N_SECT + sect: 4 + value: 0x0000000000000048 +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: _main.eh + type: N_SECT + scope: [ N_EXT ] + sect: 4 + value: 0x0000000000000060 +undefined-symbols: + - name: ___stdoutp + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _fprintf + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +install-name: /usr/lib/libSystem.B.dylib +exports: + - name: _fprintf + - name: dyld_stub_binder + - name: ___stdoutp + +... + +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main +# CHECK: (undefined) external ___stdoutp (from libSystem) +# CHECK: (undefined) external _fprintf (from libSystem) +# CHECK: (undefined) external dyld_stub_binder (from libSystem) diff --git a/test/mach-o/image-base.yaml b/test/mach-o/image-base.yaml new file mode 100644 index 000000000000..cc272491bc55 --- /dev/null +++ b/test/mach-o/image-base.yaml @@ -0,0 +1,27 @@ +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.9 %s -o %t -image_base 31415926000 %p/Inputs/libSystem.yaml +# RUN: macho-dump %t | FileCheck %s +# RUN: not lld -flavor darwin -arch x86_64 -image_base 0x31415926530 %s >/dev/null 2> %t +# RUN: FileCheck < %t %s --check-prefix=CHECK-ERROR-MISPAGED +# RUN: not lld -flavor darwin -arch x86_64 -image_base 1000 %s >/dev/null 2> %t +# RUN: FileCheck < %t %s --check-prefix=CHECK-ERROR-OVERLAP +# RUN: not lld -flavor darwin -arch x86_64 -image_base hithere %s >/dev/null 2> %t +# RUN: FileCheck < %t %s --check-prefix=CHECK-ERROR-NOTHEX + +--- !native +defined-atoms: + - name: _main + scope: global + content: [] + + # Unfortunately, llvm-objdump and llvm-readobj are too generic and don't give + # us easy access to the MachO segment model, so we have to check the uglier + # macho-dump output. +# CHECK: 'segment_name', '__TEXT +# CHECK-NEXT: 'vm_addr', 3384796143616 + + +# CHECK-ERROR-MISPAGED: error: image_base must be a multiple of page size (0x1000) + +# CHECK-ERROR-OVERLAP: error: image_base overlaps with __PAGEZERO + +# CHECK-ERROR-NOTHEX: error: image_base expects a hex number diff --git a/test/mach-o/infer-arch.yaml b/test/mach-o/infer-arch.yaml new file mode 100644 index 000000000000..94f8543bd72e --- /dev/null +++ b/test/mach-o/infer-arch.yaml @@ -0,0 +1,29 @@ +# RUN: lld -flavor darwin -arch i386 -macosx_version_min 10.8 %s -r -o %t \ +# RUN: && lld -flavor darwin -r %t -o %t2 -print_atoms | FileCheck %s +# +# Test linker can detect architecture without -arch option. +# + +--- !mach-o +arch: x86 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xC3 ] +global-symbols: + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + +... + + +# CHECK: defined-atoms: +# CHECK: - name: _foo diff --git a/test/mach-o/interposing-section.yaml b/test/mach-o/interposing-section.yaml new file mode 100644 index 000000000000..856d4b91f3d2 --- /dev/null +++ b/test/mach-o/interposing-section.yaml @@ -0,0 +1,79 @@ +# RUN: lld -flavor darwin -arch x86_64 %s -dylib -o %t %p/Inputs/libSystem.yaml +# RUN: llvm-objdump -private-headers %t | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 %s -r -o %t1 +# RUN: llvm-objdump -private-headers %t1 | FileCheck %s +# +# Test that interposing section is preserved by linker. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x31, 0xC0, 0x5D, 0xE9, + 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000008 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 2 + - segment: __DATA + section: __interpose + type: S_INTERPOSING + attributes: [ ] + alignment: 3 + address: 0x0000000000000010 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000008 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000000 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 0 +local-symbols: + - name: _my_open + type: N_SECT + sect: 1 + value: 0x0000000000000000 + - name: __interpose_open + type: N_SECT + sect: 2 + desc: [ N_NO_DEAD_STRIP ] + value: 0x0000000000000010 +undefined-symbols: + - name: _open + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +install-name: /usr/lib/libSystem.B.dylib +exports: + - name: _open + +... + + +# CHECK: sectname __interposing +# CHECK: segname __DATA +# CHECK: type S_INTERPOSING + diff --git a/test/mach-o/keep_private_externs.yaml b/test/mach-o/keep_private_externs.yaml new file mode 100644 index 000000000000..d67941a1c8eb --- /dev/null +++ b/test/mach-o/keep_private_externs.yaml @@ -0,0 +1,63 @@ +# RUN: lld -flavor darwin -arch x86_64 -r %s -o %t \ +# RUN: && llvm-nm -m %t | FileCheck %s +# +# RUN: lld -flavor darwin -arch x86_64 -r %s -o %t2 -keep_private_externs \ +# RUN: && llvm-nm -m %t2 | FileCheck -check-prefix=CHECK_KPE %s +# +# Test -keep_private_externs in -r mode. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x5D, 0xC3, 0x55, 0x48, + 0x89, 0xE5, 0x5D, 0xC3 ] + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x000000000000000C + content: [ 0x0A, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 ] + +global-symbols: + - name: _a + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x000000000000000C + - name: _b + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 2 + value: 0x0000000000000010 + - name: _bar + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000006 + - name: _foo + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 1 + value: 0x0000000000000000 + + +... + +# CHECK: (__DATA,__data) external _a +# CHECK: (__DATA,__data) non-external (was a private external) _b +# CHECK: (__TEXT,__text) external _bar +# CHECK: (__TEXT,__text) non-external (was a private external) _foo + +# CHECK_KPE: (__DATA,__data) external _a +# CHECK_KPE: (__DATA,__data) private external _b +# CHECK_KPE: (__TEXT,__text) external _bar +# CHECK_KPE: (__TEXT,__text) private external _foo diff --git a/test/mach-o/lazy-bind-x86_64.yaml b/test/mach-o/lazy-bind-x86_64.yaml new file mode 100644 index 000000000000..54d787ce91be --- /dev/null +++ b/test/mach-o/lazy-bind-x86_64.yaml @@ -0,0 +1,125 @@ +# REQUIRES: x86 + +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t \ +# RUN: %p/Inputs/libSystem.yaml +# RUN: llvm-objdump -lazy-bind %t | FileCheck %s +# RUN: llvm-nm -m %t | FileCheck --check-prefix=CHECK-NM %s +# RUN: llvm-objdump -disassemble %t | FileCheck --check-prefix=CHECK-HELPERS %s +# RUN: llvm-objdump -private-headers %t | FileCheck --check-prefix=CHECK-DYLIBS %s +# +# Test that correct two-level namespace ordinals are used for lazy bindings. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x31, 0xC0, 0xE8, 0x00, + 0x00, 0x00, 0x00, 0x31, 0xC0, 0xE8, 0x00, 0x00, + 0x00, 0x00, 0x31, 0xC0, 0xE8, 0x00, 0x00, 0x00, + 0x00, 0x31, 0xC0, 0x5D, 0xC3 ] + relocations: + - offset: 0x00000015 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 3 + - offset: 0x0000000E + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 2 + - offset: 0x00000007 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 1 +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _bar + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _baz + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _foo + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +install-name: /usr/lib/libbar.dylib +compat-version: 1.0 +current-version: 2.3 +exports: + - name: _bar + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +install-name: /usr/lib/libfoo.dylib +compat-version: 2.0 +current-version: 3.4 +exports: + - name: _foo + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +install-name: /usr/lib/libbaz.dylib +compat-version: 3.0 +current-version: 4.5 +exports: + - name: _baz + +... + + +# CHECK: libbar _bar +# CHECK: libbaz _baz +# CHECK: libfoo _foo + + +# CHECK-NM: (undefined) external _bar (from libbar) +# CHECK-NM: (undefined) external _baz (from libbaz) +# CHECK-NM: (undefined) external _foo (from libfoo) + + +# CHECK-HELPERS:Disassembly of section __TEXT,__stub_helper: +# CHECK-HELPERS: 68 00 00 00 00 pushq $0 +# CHECK-HELPERS: 68 10 00 00 00 pushq $16 +# CHECK-HELPERS: 68 20 00 00 00 pushq $32 + + +# CHECK-DYLIBS: cmd LC_LOAD_DYLIB +# CHECK-DYLIBS: name /usr/lib/libbar.dylib (offset 24) +# CHECK-DYLIBS: current version 2.3.0 +# CHECK-DYLIBS: compatibility version 1.0.0 +# CHECK-DYLIBS: cmd LC_LOAD_DYLIB +# CHECK-DYLIBS: name /usr/lib/libfoo.dylib (offset 24) +# CHECK-DYLIBS: current version 3.4.0 +# CHECK-DYLIBS: compatibility version 2.0.0 +# CHECK-DYLIBS: cmd LC_LOAD_DYLIB +# CHECK-DYLIBS: name /usr/lib/libbaz.dylib (offset 24) +# CHECK-DYLIBS: current version 4.5.0 +# CHECK-DYLIBS: compatibility version 3.0.0 + + diff --git a/test/mach-o/lib-search-paths.yaml b/test/mach-o/lib-search-paths.yaml new file mode 100644 index 000000000000..5005f016857f --- /dev/null +++ b/test/mach-o/lib-search-paths.yaml @@ -0,0 +1,16 @@ +# RUN: lld -flavor darwin -arch x86_64 %s -syslibroot %p/Inputs/lib-search-paths -lmyshared -lmystatic -lfile.o -r -print_atoms 2>&1 | FileCheck %s + +--- !native +undefined-atoms: + - name: _from_myshared + - name: _from_mystatic + - name: _from_fileo + +# CHECK: defined-atoms: +# CHECK: - name: _from_fileo +# CHECK: content: [ 2A, 00, 00, 00 ] +# CHECK: - name: _from_mystatic +# CHECK: content: [ 02, 00, 00, 00 ] +# CHECK: shared-library-atoms: +# CHECK: - name: _from_myshared +# CHECK: load-name: libmyshared.dylib diff --git a/test/mach-o/library-order.yaml b/test/mach-o/library-order.yaml new file mode 100644 index 000000000000..23e9f6873134 --- /dev/null +++ b/test/mach-o/library-order.yaml @@ -0,0 +1,45 @@ +# RUN: lld -flavor darwin -arch x86_64 %p/Inputs/libfoo.a %s -o %t \ +# RUN: %p/Inputs/libSystem.yaml +# RUN: llvm-nm -m -n %t | FileCheck %s +# +# Test that if library is before object file on command line, it still is used. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x48, 0x83, 0xEC, 0x10, + 0xC7, 0x45, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xB0, + 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x31, 0xC0, + 0x48, 0x83, 0xC4, 0x10, 0x5D, 0xC3 ] + relocations: + - offset: 0x00000012 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 1 +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _foo + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +... + +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _foo diff --git a/test/mach-o/library-rescan.yaml b/test/mach-o/library-rescan.yaml new file mode 100644 index 000000000000..a58d763fff00 --- /dev/null +++ b/test/mach-o/library-rescan.yaml @@ -0,0 +1,46 @@ +# RUN: lld -flavor darwin -arch x86_64 %p/Inputs/libfoo.a %p/Inputs/libbar.a \ +# RUN: %s -o %t %p/Inputs/libSystem.yaml +# RUN: llvm-nm -m -n %t | FileCheck %s +# +# Test that static libraries are automatically rescanned (bar needs foo). +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x48, 0x83, 0xEC, 0x10, + 0xC7, 0x45, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xB0, + 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x31, 0xC0, + 0x48, 0x83, 0xC4, 0x10, 0x5D, 0xC3 ] + relocations: + - offset: 0x00000012 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 1 +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _bar + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +... + +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _bar +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _foo diff --git a/test/mach-o/libresolve-bizarre-root-override.yaml b/test/mach-o/libresolve-bizarre-root-override.yaml new file mode 100644 index 000000000000..c65ca319432d --- /dev/null +++ b/test/mach-o/libresolve-bizarre-root-override.yaml @@ -0,0 +1,17 @@ +# RUN: not lld -flavor darwin -test_file_usage -v \ +# RUN: -path_exists /usr/lib \ +# RUN: -path_exists /Applications/MySDK/usr/local/lib \ +# RUN: -path_exists /Applications/MySDK/usr/lib \ +# RUN: -path_exists /Applications/MySDK/usr/lib/libSystem.dylib \ +# RUN: -syslibroot /Applications/MySDK \ +# RUN: -syslibroot / \ +# RUN: -lSystem \ +# RUN: 2>&1 | FileCheck %s + +# When the last -syslibroot is simply "/", all of them get discarded. So in this +# case, only /usr/lib should show up. + +# CHECK: Library search paths: +# CHECK: /usr/lib +# CHECK-NOT: /usr/local/lib +# CHECK: Unable to find library for -lSystem diff --git a/test/mach-o/libresolve-multiple-syslibroots.yaml b/test/mach-o/libresolve-multiple-syslibroots.yaml new file mode 100644 index 000000000000..0b63eb64e7a9 --- /dev/null +++ b/test/mach-o/libresolve-multiple-syslibroots.yaml @@ -0,0 +1,17 @@ +# RUN: lld -flavor darwin -test_file_usage -v \ +# RUN: -path_exists /usr/lib \ +# RUN: -path_exists /Applications/MyFirstSDK/usr/local/lib \ +# RUN: -path_exists /Applications/MySecondSDK/usr/local/lib \ +# RUN: -path_exists /Applications/MyFirstSDK/usr/local/lib/libSystem.a \ +# RUN: -path_exists /Applications/MySecondSDK/usr/local/lib/libSystem.a \ +# RUN: -syslibroot /Applications/MyFirstSDK \ +# RUN: -syslibroot /Applications/MySecondSDK \ +# RUN: -lSystem \ +# RUN: 2>&1 | FileCheck %s + + +# CHECK: Library search paths: +# CHECK: /usr/lib +# CHECK: /Applications/MyFirstSDK/usr/local/lib +# CHECK: /Applications/MySecondSDK/usr/local/lib +# CHECK: Found library /Applications/MyFirstSDK/usr/local/lib/libSystem.a diff --git a/test/mach-o/libresolve-one-syslibroot.yaml b/test/mach-o/libresolve-one-syslibroot.yaml new file mode 100644 index 000000000000..f9042fcfada2 --- /dev/null +++ b/test/mach-o/libresolve-one-syslibroot.yaml @@ -0,0 +1,25 @@ +# RUN: lld -flavor darwin -test_file_usage -v \ +# RUN: -path_exists /usr/lib \ +# RUN: -path_exists /Applications/MySDK/usr/local/lib \ +# RUN: -path_exists /Applications/MySDK/usr/local/lib/libSystem.a \ +# RUN: -path_exists /hasFoo \ +# RUN: -path_exists /hasFoo/foo.o \ +# RUN: -syslibroot /Applications/MySDK \ +# RUN: -L/hasFoo \ +# RUN: -lSystem -lfoo.o \ +# RUN: 2>&1 | FileCheck %s + +# When just one -syslibroot is specified, we apparently want to skip *system* +# paths that aren't found. User ones should still get added. In this case +# /usr/lib exists, but not the equivalent in the -syslibroot, so there should be +# no mention of /usr/lib. + +# CHECK: Library search paths: +# CHECK: /hasFoo +# CHECK-NOT: /usr/lib +# CHECK-NOT: /usr/local/lib +# CHECK: /Applications/MySDK/usr/local/lib +# CHECK-NOT: /usr/lib +# CHECK-NOT: /usr/local/lib +# CHECK: Found library /Applications/MySDK/usr/local/lib/libSystem.a +# CHECK: Found library /hasFoo/foo.o diff --git a/test/mach-o/libresolve-simple.yaml b/test/mach-o/libresolve-simple.yaml new file mode 100644 index 000000000000..ffb045fa3e3c --- /dev/null +++ b/test/mach-o/libresolve-simple.yaml @@ -0,0 +1,21 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -test_file_usage -v \ +# RUN: -path_exists /usr/lib \ +# RUN: -path_exists /usr/local/lib \ +# RUN: -path_exists /usr/lib/libSystem.dylib \ +# RUN: -path_exists hasFoo \ +# RUN: -path_exists hasFoo/libFoo.dylib \ +# RUN: -path_exists /hasBar \ +# RUN: -path_exists /hasBar/libBar.dylib \ +# RUN: -L hasFoo \ +# RUN: -L /hasBar \ +# RUN: -lSystem -lFoo -lBar \ +# RUN: 2>&1 | FileCheck %s + +# CHECK: Library search paths: +# CHECK: hasFoo +# CHECK: /hasBar +# CHECK: /usr/lib +# CHECK: /usr/local/lib +# CHECK: Found library /usr/lib/libSystem.dylib +# CHECK: Found library hasFoo/libFoo.dylib +# CHECK: Found library /hasBar/libBar.dylib diff --git a/test/mach-o/libresolve-user-paths.yaml b/test/mach-o/libresolve-user-paths.yaml new file mode 100644 index 000000000000..9fe885671686 --- /dev/null +++ b/test/mach-o/libresolve-user-paths.yaml @@ -0,0 +1,20 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -test_file_usage -v \ +# RUN: -path_exists hasFoo \ +# RUN: -path_exists hasFoo/libFoo.dylib \ +# RUN: -path_exists /hasBar \ +# RUN: -path_exists /hasBar/libBar.dylib \ +# RUN: -path_exists /SDK/hasFoo \ +# RUN: -path_exists /SDK/hasFoo/libFoo.dylib \ +# RUN: -path_exists /SDK/hasBar \ +# RUN: -path_exists /SDK/hasBar/libBar.dylib \ +# RUN: -syslibroot /SDK \ +# RUN: -L hasFoo \ +# RUN: -L /hasBar \ +# RUN: -lFoo -lBar \ +# RUN: 2>&1 | FileCheck %s + +# CHECK: Library search paths: +# CHECK: hasFoo +# CHECK: /SDK/hasBar +# CHECK: Found library hasFoo/libFoo.dylib +# CHECK: Found library /SDK/hasBar/libBar.dylib diff --git a/test/mach-o/libresolve-z.yaml b/test/mach-o/libresolve-z.yaml new file mode 100644 index 000000000000..1df7eceac1e4 --- /dev/null +++ b/test/mach-o/libresolve-z.yaml @@ -0,0 +1,21 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -test_file_usage -v \ +# RUN: -path_exists /usr/lib \ +# RUN: -path_exists /usr/local/lib \ +# RUN: -path_exists /usr/lib/libSystem.dylib \ +# RUN: -path_exists hasFoo \ +# RUN: -path_exists hasFoo/libFoo.dylib \ +# RUN: -path_exists /hasBar \ +# RUN: -path_exists /hasBar/libBar.dylib \ +# RUN: -L hasFoo \ +# RUN: -L /hasBar \ +# RUN: -Z \ +# RUN: -lFoo -lBar \ +# RUN: 2>&1 | FileCheck %s + +# CHECK: Library search paths: +# CHECK: hasFoo +# CHECK: /hasBar +# CHECK-NOT: /usr/lib +# CHECK-NOT: /usr/local/lib +# CHECK: Found library hasFoo/libFoo.dylib +# CHECK: Found library /hasBar/libBar.dylib diff --git a/test/mach-o/linker-as-ld.yaml b/test/mach-o/linker-as-ld.yaml new file mode 100644 index 000000000000..2dd1f79818e1 --- /dev/null +++ b/test/mach-o/linker-as-ld.yaml @@ -0,0 +1,39 @@ +# REQUIRES: system-linker-mach-o +# +# RUN: mkdir -p %t.dir && cp `which lld` %t.dir/ld \ +# RUN: && %t.dir/ld -arch x86_64 -macosx_version_min 10.8 %s -o %t \ +# RUN: && llvm-nm %t | FileCheck %s +# +# Test linker run as "ld" on darwin works as darwin linker. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xC3 ] +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +install-name: /usr/lib/libSystem.B.dylib +exports: + - name: dyld_stub_binder + +... + +# CHECK: T _main diff --git a/test/mach-o/lit.local.cfg b/test/mach-o/lit.local.cfg new file mode 100644 index 000000000000..739a0994fdda --- /dev/null +++ b/test/mach-o/lit.local.cfg @@ -0,0 +1,4 @@ + +# mach-o test cases encode input files in yaml and use .yaml extension +config.suffixes = ['.yaml'] +config.excludes = ['Inputs'] diff --git a/test/mach-o/mh_bundle_header.yaml b/test/mach-o/mh_bundle_header.yaml new file mode 100644 index 000000000000..558df2ca2e95 --- /dev/null +++ b/test/mach-o/mh_bundle_header.yaml @@ -0,0 +1,53 @@ +# RUN: lld -flavor darwin -arch x86_64 %s -bundle -o %t %p/Inputs/libSystem.yaml +# RUN: llvm-nm -m -n %t | FileCheck %s +# +# Test that __mh_bundle_header symbol is available for bundles +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x31, 0xC0, 0x5D, 0xC3 ] + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 3 + address: 0x0000000000000008 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000000 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 2 +global-symbols: + - name: _d + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x0000000000000008 + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: __mh_bundle_header + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + + +... + +# CHECK_NOT: __mh_bundle_header +# CHECK: _foo diff --git a/test/mach-o/mh_dylib_header.yaml b/test/mach-o/mh_dylib_header.yaml new file mode 100644 index 000000000000..07429b30c943 --- /dev/null +++ b/test/mach-o/mh_dylib_header.yaml @@ -0,0 +1,53 @@ +# RUN: lld -flavor darwin -arch x86_64 %s -dylib -o %t %p/Inputs/libSystem.yaml +# RUN: llvm-nm -m -n %t | FileCheck %s +# +# Test that __mh_dylib_header symbol is available for dylibs +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x31, 0xC0, 0x5D, 0xC3 ] + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 3 + address: 0x0000000000000008 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000000 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 2 +global-symbols: + - name: _d + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x0000000000000008 + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: __mh_dylib_header + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + + +... + +# CHECK_NOT: __mh_dylib_header +# CHECK: _foo diff --git a/test/mach-o/objc_export_list.yaml b/test/mach-o/objc_export_list.yaml new file mode 100644 index 000000000000..5844812295be --- /dev/null +++ b/test/mach-o/objc_export_list.yaml @@ -0,0 +1,63 @@ +# RUN: lld -flavor darwin -arch x86_64 -dylib %s -o %t \ +# RUN: -exported_symbol .objc_class_name_Foo %p/Inputs/libSystem.yaml +# RUN: llvm-nm -m %t | FileCheck %s +# +# Test that exported objc classes can be specificed using old naming +# (.e.g .objc_class_name_Foo instead of _OBJC_CLASS_$_Foo) +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __DATA + section: __objc_data + type: S_REGULAR + attributes: [ ] + alignment: 3 + address: 0x0000000000000000 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000030 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 0 + - offset: 0x00000028 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000000 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 1 +global-symbols: + - name: '_OBJC_CLASS_$_Foo' + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: '_OBJC_METACLASS_$_Foo' + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000028 +... + +# CHECK: (__DATA,__objc_data) external _OBJC_CLASS_$_Foo +# CHECK: (__DATA,__objc_data) external _OBJC_METACLASS_$_Foo diff --git a/test/mach-o/order_file-basic.yaml b/test/mach-o/order_file-basic.yaml new file mode 100644 index 000000000000..3fea9be15601 --- /dev/null +++ b/test/mach-o/order_file-basic.yaml @@ -0,0 +1,75 @@ +# RUN: lld -flavor darwin -arch x86_64 %s %p/Inputs/libSystem.yaml \ +# RUN: -order_file %p/Inputs/order_file-basic.order \ +# RUN: -force_load %p/Inputs/libfoo.a -o %t +# RUN: llvm-nm -m -n %t | FileCheck %s +# +# Test -order_file +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xC3, 0xC3, 0xC3, 0xC3 ] + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x0000000000000014 + content: [ 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00 ] +global-symbols: + - name: _data1 + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x0000000000000014 + - name: _data2 + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x0000000000000018 + - name: _data3 + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x000000000000001C + - name: _func1 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: _func2 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000001 + - name: _func3 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000002 + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000003 +... + + +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _func2 +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _foo +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _func1 +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _func3 +# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main +# CHECK: {{[0-9a-f]+}} (__DATA,__data) external _data3 +# CHECK: {{[0-9a-f]+}} (__DATA,__data) external _data1 +# CHECK: {{[0-9a-f]+}} (__DATA,__data) external _data2 + diff --git a/test/mach-o/parse-aliases.yaml b/test/mach-o/parse-aliases.yaml new file mode 100644 index 000000000000..457ea58133b9 --- /dev/null +++ b/test/mach-o/parse-aliases.yaml @@ -0,0 +1,90 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t | FileCheck %s +# +# Test multiple labels to same address parse into aliases. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0xCC, 0xC3 ] +local-symbols: + - name: _pad + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: _myStaticAlias1 + type: N_SECT + sect: 1 + value: 0x0000000000000001 + - name: _myStaticAlias3 + type: N_SECT + sect: 1 + value: 0x0000000000000001 + - name: _myStaticAlias2 + type: N_SECT + sect: 1 + value: 0x0000000000000001 +global-symbols: + - name: _myGlobalFunc1 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000001 + - name: _myGlobalFunc2 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000001 + - name: _myGlobalFunc3 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000001 + - name: _myHiddenAlias1 + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 1 + value: 0x0000000000000001 + - name: _myHiddenAlias2 + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 1 + value: 0x0000000000000001 + - name: _myHiddenAlias3 + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 1 + value: 0x0000000000000001 +... + +# CHECK: defined-atoms: +# CHECK: - name: _pad +# CHECK: scope: global +# CHECK: content: [ CC ] +# CHECK: - name: _myStaticAlias1 +# CHECK: - name: _myStaticAlias2 +# CHECK: - name: _myStaticAlias3 +# CHECK: - name: _myHiddenAlias1 +# CHECK: scope: hidden +# CHECK: - name: _myHiddenAlias2 +# CHECK: scope: hidden +# CHECK: - name: _myHiddenAlias3 +# CHECK: scope: hidden +# CHECK: - name: _myGlobalFunc1 +# CHECK: scope: global +# CHECK: - name: _myGlobalFunc2 +# CHECK: scope: global +# CHECK: - name: _myGlobalFunc3 +# CHECK: scope: global +# CHECK: content: [ C3 ] diff --git a/test/mach-o/parse-arm-relocs.yaml b/test/mach-o/parse-arm-relocs.yaml new file mode 100644 index 000000000000..c87c2a99b215 --- /dev/null +++ b/test/mach-o/parse-arm-relocs.yaml @@ -0,0 +1,818 @@ +# RUN: lld -flavor darwin -arch armv7 -r -print_atoms %s -o %t | FileCheck %s +# RUN: lld -flavor darwin -arch armv7 -r -print_atoms %t -o %t2 | FileCheck %s +# +# Test parsing of armv7 relocations. +# +# + +--- !mach-o +arch: armv7 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0x00, 0xF0, 0x4E, 0xF8, 0x00, 0xF0, 0x4E, 0xF8, + 0xFF, 0xF7, 0xFA, 0xFF, 0xFF, 0xF7, 0xFA, 0xFF, + 0xFF, 0xF7, 0xF6, 0xBF, 0x40, 0xF2, 0x72, 0x01, + 0xC0, 0xF2, 0x00, 0x01, 0x40, 0xF2, 0x7A, 0x02, + 0xC0, 0xF2, 0x00, 0x02, 0x40, 0xF2, 0x29, 0x01, + 0xC0, 0xF2, 0x00, 0x01, 0x79, 0x44, 0x40, 0xF2, + 0xA0, 0x03, 0xC0, 0xF2, 0x00, 0x03, 0x40, 0xF2, + 0xA8, 0x04, 0xC0, 0xF2, 0x00, 0x04, 0x40, 0xF2, + 0x57, 0x03, 0xC0, 0xF2, 0x00, 0x03, 0x40, 0xF2, + 0x00, 0x05, 0xC0, 0xF2, 0x00, 0x05, 0x40, 0xF2, + 0x08, 0x06, 0xC0, 0xF2, 0x00, 0x06, 0xC0, 0x46, + 0x10, 0x00, 0x00, 0xEB, 0x10, 0x00, 0x00, 0xEB, + 0xE6, 0xFF, 0xFF, 0xEB, 0xE6, 0xFF, 0xFF, 0xEB, + 0xE4, 0xFF, 0xFF, 0xEA, 0x20, 0x10, 0x00, 0xE3, + 0x00, 0x10, 0x40, 0xE3, 0x28, 0x20, 0x00, 0xE3, + 0x00, 0x20, 0x40, 0xE3, 0x0F, 0x10, 0x81, 0xE0, + 0xA0, 0x30, 0x00, 0xE3, 0x00, 0x30, 0x40, 0xE3, + 0xA8, 0x40, 0x00, 0xE3, 0x00, 0x40, 0x40, 0xE3, + 0x00, 0x50, 0x00, 0xE3, 0x00, 0x50, 0x40, 0xE3, + 0x08, 0x60, 0x00, 0xE3, 0x00, 0x60, 0x40, 0xE3 ] + relocations: + - offset: 0x0000009C + type: ARM_RELOC_HALF + length: 1 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x00000008 + type: ARM_RELOC_PAIR + length: 1 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000098 + type: ARM_RELOC_HALF + length: 0 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 0 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000094 + type: ARM_RELOC_HALF + length: 1 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 1 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000090 + type: ARM_RELOC_HALF + length: 0 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 0 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x0000008C + scattered: true + type: ARM_RELOC_HALF + length: 1 + pc-rel: false + value: 0x000000A0 + - offset: 0x000000A8 + type: ARM_RELOC_PAIR + length: 1 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000088 + scattered: true + type: ARM_RELOC_HALF + length: 0 + pc-rel: false + value: 0x000000A0 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 0 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000084 + type: ARM_RELOC_HALF + length: 1 + pc-rel: false + extern: false + symbol: 2 + - offset: 0x000000A0 + type: ARM_RELOC_PAIR + length: 1 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000080 + type: ARM_RELOC_HALF + length: 0 + pc-rel: false + extern: false + symbol: 2 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 0 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000078 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 1 + pc-rel: false + value: 0x000000A0 + - offset: 0x00000028 + scattered: true + type: ARM_RELOC_PAIR + length: 1 + pc-rel: false + value: 0x00000080 + - offset: 0x00000074 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 0 + pc-rel: false + value: 0x000000A0 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 0 + pc-rel: false + value: 0x00000080 + - offset: 0x00000070 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 1 + pc-rel: false + value: 0x000000A0 + - offset: 0x00000020 + scattered: true + type: ARM_RELOC_PAIR + length: 1 + pc-rel: false + value: 0x00000080 + - offset: 0x0000006C + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 0 + pc-rel: false + value: 0x000000A0 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 0 + pc-rel: false + value: 0x00000080 + - offset: 0x00000068 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: true + symbol: 4 + - offset: 0x00000064 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: true + symbol: 4 + - offset: 0x00000060 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: true + symbol: 4 + - offset: 0x0000005C + scattered: true + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + value: 0x000000A0 + - offset: 0x00000058 + type: ARM_RELOC_BR24 + length: 2 + pc-rel: true + extern: false + symbol: 2 + - offset: 0x00000052 + type: ARM_RELOC_HALF + length: 3 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x00000008 + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x0000004E + type: ARM_RELOC_HALF + length: 2 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x0000004A + type: ARM_RELOC_HALF + length: 3 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000046 + type: ARM_RELOC_HALF + length: 2 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000042 + type: ARM_RELOC_HALF + length: 3 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000057 + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x0000003E + type: ARM_RELOC_HALF + length: 2 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x0000003A + scattered: true + type: ARM_RELOC_HALF + length: 3 + pc-rel: false + value: 0x000000A0 + - offset: 0x000000A8 + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000036 + scattered: true + type: ARM_RELOC_HALF + length: 2 + pc-rel: false + value: 0x000000A0 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000032 + type: ARM_RELOC_HALF + length: 3 + pc-rel: false + extern: false + symbol: 2 + - offset: 0x000000A0 + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x0000002E + type: ARM_RELOC_HALF + length: 2 + pc-rel: false + extern: false + symbol: 2 + - offset: 0x00000000 + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + extern: false + symbol: 16777215 + - offset: 0x00000028 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 3 + pc-rel: false + value: 0x00000056 + - offset: 0x00000028 + scattered: true + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + value: 0x0000002E + - offset: 0x00000024 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000056 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x0000002E + - offset: 0x00000020 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 3 + pc-rel: false + value: 0x000000A0 + - offset: 0x0000007A + scattered: true + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + value: 0x0000002E + - offset: 0x0000001C + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 2 + pc-rel: false + value: 0x000000A0 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x0000002E + - offset: 0x00000018 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 3 + pc-rel: false + value: 0x000000A0 + - offset: 0x00000072 + scattered: true + type: ARM_RELOC_PAIR + length: 3 + pc-rel: false + value: 0x0000002E + - offset: 0x00000014 + scattered: true + type: ARM_RELOC_HALF_SECTDIFF + length: 2 + pc-rel: false + value: 0x000000A0 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x0000002E + - offset: 0x00000010 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: true + symbol: 4 + - offset: 0x0000000C + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: true + symbol: 4 + - offset: 0x00000008 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: true + symbol: 4 + - offset: 0x00000004 + scattered: true + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + value: 0x000000A0 + - offset: 0x00000000 + type: ARM_THUMB_RELOC_BR22 + length: 2 + pc-rel: true + extern: false + symbol: 2 + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + address: 0x00000000000000A0 + content: [ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xA4, 0xFF, 0xFF, 0xFF, + 0xA4, 0xFF, 0xFF, 0xFF, 0x45, 0xFF, 0xFF, 0xFF, + 0x45, 0xFF, 0xFF, 0xFF ] + relocations: + - offset: 0x00000020 + scattered: true + type: ARM_RELOC_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000000 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x000000C0 + - offset: 0x0000001C + scattered: true + type: ARM_RELOC_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000000 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x000000BC + - offset: 0x00000018 + scattered: true + type: ARM_RELOC_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000058 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x000000B8 + - offset: 0x00000014 + scattered: true + type: ARM_RELOC_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000058 + - offset: 0x00000000 + scattered: true + type: ARM_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x000000B4 + - offset: 0x00000010 + type: ARM_RELOC_VANILLA + length: 2 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x0000000C + type: ARM_RELOC_VANILLA + length: 2 + pc-rel: false + extern: true + symbol: 4 + - offset: 0x00000008 + scattered: true + type: ARM_RELOC_VANILLA + length: 2 + pc-rel: false + value: 0x00000000 + - offset: 0x00000004 + type: ARM_RELOC_VANILLA + length: 2 + pc-rel: false + extern: false + symbol: 1 +local-symbols: + - name: _foo_thumb + type: N_SECT + sect: 1 + desc: [ N_ARM_THUMB_DEF ] + value: 0x0000000000000000 + - name: _x + type: N_SECT + sect: 2 + value: 0x00000000000000A0 + - name: _t1 + type: N_SECT + sect: 1 + desc: [ N_ARM_THUMB_DEF ] + value: 0x0000000000000056 + - name: _foo_arm + type: N_SECT + sect: 1 + value: 0x0000000000000058 +undefined-symbols: + - name: _undef + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + +# CHECK: defined-atoms: +# CHECK: - name: _x +# CHECK: type: data +# CHECK: references: +# CHECK: - kind: pointer32 +# CHECK: offset: 4 +# CHECK: target: _foo_thumb +# CHECK-NOT: addend: +# CHECK: - kind: pointer32 +# CHECK: offset: 8 +# CHECK: target: _foo_thumb +# CHECK: addend: 4 +# CHECK: - kind: pointer32 +# CHECK: offset: 12 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: pointer32 +# CHECK: offset: 16 +# CHECK: target: _undef +# CHECK: addend: 4 +# CHECK: - kind: delta32 +# CHECK: offset: 20 +# CHECK: target: _foo_arm +# CHECK-NOT: addend: +# CHECK: - kind: delta32 +# CHECK: offset: 24 +# CHECK: target: _foo_arm +# CHECK: addend: 4 +# CHECK: - kind: delta32 +# CHECK: offset: 28 +# CHECK: target: _foo_thumb +# CHECK-NOT: addend: +# CHECK: - kind: delta32 +# CHECK: offset: 32 +# CHECK: target: _foo_thumb +# CHECK: addend: 4 +# CHECK: - name: _foo_thumb +# CHECK: references: +# CHECK: - kind: modeThumbCode +# CHECK: offset: 0 +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 0 +# CHECK: target: _x +# CHECK-NOT: addend: +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 4 +# CHECK: target: _x +# CHECK: addend: 4 +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 8 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: thumb_bl22 +# CHECK: offset: 12 +# CHECK: target: _undef +# CHECK: addend: 4 +# CHECK: - kind: thumb_b22 +# CHECK: offset: 16 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: thumb_movw_funcRel +# CHECK: offset: 20 +# CHECK: target: _x +# CHECK: addend: -46 +# CHECK: - kind: thumb_movt_funcRel +# CHECK: offset: 24 +# CHECK: target: _x +# CHECK: addend: -46 +# CHECK: - kind: thumb_movw_funcRel +# CHECK: offset: 28 +# CHECK: target: _x +# CHECK: addend: -38 +# CHECK: - kind: thumb_movt_funcRel +# CHECK: offset: 32 +# CHECK: target: _x +# CHECK: addend: -38 +# CHECK: - kind: thumb_movw_funcRel +# CHECK: offset: 36 +# CHECK: target: _t1 +# CHECK: addend: -46 +# CHECK: - kind: thumb_movt_funcRel +# CHECK: offset: 40 +# CHECK: target: _t1 +# CHECK: addend: -46 +# CHECK: - kind: thumb_movw +# CHECK: offset: 46 +# CHECK: target: _x +# CHECK-NOT: addend: +# CHECK: - kind: thumb_movt +# CHECK: offset: 50 +# CHECK: target: _x +# CHECK-NOT: addend: +# CHECK: - kind: thumb_movw +# CHECK: offset: 54 +# CHECK: target: _x +# CHECK: addend: 8 +# CHECK: - kind: thumb_movt +# CHECK: offset: 58 +# CHECK: target: _x +# CHECK: addend: 8 +# CHECK: - kind: thumb_movw +# CHECK: offset: 62 +# CHECK: target: _t1 +# CHECK-NOT: addend: +# CHECK: - kind: thumb_movt +# CHECK: offset: 66 +# CHECK: target: _t1 +# CHECK-NOT: addend: +# CHECK: - kind: thumb_movw +# CHECK: offset: 70 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: thumb_movt +# CHECK: offset: 74 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: thumb_movw +# CHECK: offset: 78 +# CHECK: target: _undef +# CHECK: addend: 8 +# CHECK: - kind: thumb_movt +# CHECK: offset: 82 +# CHECK: target: _undef +# CHECK: addend: 8 +# CHECK: - name: _t1 +# CHECK: content: [ C0, 46 ] +# CHECK: references: +# CHECK: - kind: modeThumbCode +# CHECK: offset: 0 +# CHECK: - name: _foo_arm +# CHECK: references: +# CHECK-NOT: - kind: modeThumbCode +# CHECK: - kind: arm_bl24 +# CHECK: offset: 0 +# CHECK: target: _x +# CHECK-NOT: addend: +# CHECK: - kind: arm_bl24 +# CHECK: offset: 4 +# CHECK: target: _x +# CHECK: addend: 4 +# CHECK: - kind: arm_bl24 +# CHECK: offset: 8 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: arm_bl24 +# CHECK: offset: 12 +# CHECK: target: _undef +# CHECK: addend: 4 +# CHECK: - kind: arm_b24 +# CHECK: offset: 16 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: arm_movw_funcRel +# CHECK: offset: 20 +# CHECK: target: _x +# CHECK: addend: -40 +# CHECK: - kind: arm_movt_funcRel +# CHECK: offset: 24 +# CHECK: target: _x +# CHECK: addend: -40 +# CHECK: - kind: arm_movw_funcRel +# CHECK: offset: 28 +# CHECK: target: _x +# CHECK: addend: -32 +# CHECK: - kind: arm_movt_funcRel +# CHECK: offset: 32 +# CHECK: target: _x +# CHECK: addend: -32 +# CHECK: - kind: arm_movw +# CHECK: offset: 40 +# CHECK: target: _x +# CHECK-NOT: addend: +# CHECK: - kind: arm_movt +# CHECK: offset: 44 +# CHECK: target: _x +# CHECK-NOT: addend: +# CHECK: - kind: arm_movw +# CHECK: offset: 48 +# CHECK: target: _x +# CHECK: addend: 8 +# CHECK: - kind: arm_movt +# CHECK: offset: 52 +# CHECK: target: _x +# CHECK: addend: 8 +# CHECK: - kind: arm_movw +# CHECK: offset: 56 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: arm_movt +# CHECK: offset: 60 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: arm_movw +# CHECK: offset: 64 +# CHECK: target: _undef +# CHECK: addend: 8 +# CHECK: - kind: arm_movt +# CHECK: offset: 68 +# CHECK: target: _undef +# CHECK: addend: 8 +# CHECK: undefined-atoms: +# CHECK: - name: _undef + + + + +# .align 2 +# .code 16 +# .thumb_func _foo_thumb +#_foo_thumb: +# bl _x +# bl _x+4 +# bl _undef +# bl _undef+4 +# b _undef +# movw r1, :lower16:(_x-L1) +# movt r1, :upper16:(_x-L1) +# movw r2, :lower16:(_x+8-L1) +# movt r2, :upper16:(_x+8-L1) +# movw r1, :lower16:(_t1-L1) +# movt r1, :upper16:(_t1-L1) +# add r1, pc +#L1: +# movw r3, :lower16:_x +# movt r3, :upper16:_x +# movw r4, :lower16:_x+8 +# movt r4, :upper16:_x+8 +# movw r3, :lower16:_t1 +# movt r3, :upper16:_t1 +# movw r5, :lower16:_undef +# movt r5, :upper16:_undef +# movw r6, :lower16:_undef+8 +# movt r6, :upper16:_undef+8 +# +# .thumb_func _t1 +#_t1: +# nop +# +# +# .code 32 +# .align 2 +#_foo_arm: +# bl _x +# bl _x+4 +# bl _undef +# bl _undef+4 +# b _undef +# movw r1, :lower16:(_x-L2) +# movt r1, :upper16:(_x-L2) +# movw r2, :lower16:(_x+8-L2) +# movt r2, :upper16:(_x+8-L2) +# add r1, pc +#L2: +# movw r3, :lower16:_x +# movt r3, :upper16:_x +# movw r4, :lower16:_x+8 +# movt r4, :upper16:_x+8 +# movw r5, :lower16:_undef +# movt r5, :upper16:_undef +# movw r6, :lower16:_undef+8 +# movt r6, :upper16:_undef+8 +# +# +# .data +#_x: .long 0 +# .long _foo_thumb +# .long _foo_thumb+4 +# .long _undef +# .long _undef+4 +# .long _foo_arm - . +# .long _foo_arm+4- . +# .long _foo_thumb - . +# .long _foo_thumb+4 - . +# diff --git a/test/mach-o/parse-cfstring32.yaml b/test/mach-o/parse-cfstring32.yaml new file mode 100644 index 000000000000..657e733a779b --- /dev/null +++ b/test/mach-o/parse-cfstring32.yaml @@ -0,0 +1,94 @@ +# RUN: lld -flavor darwin -arch i386 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of mach-o functions. +# + +--- !mach-o +arch: x86 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __cstring + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x0000000000000000 + content: [ 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x00, 0x74, 0x68, + 0x65, 0x72, 0x65, 0x00 ] + - segment: __DATA + section: __cfstring + type: S_REGULAR + attributes: [ ] + alignment: 3 + address: 0x0000000000000010 + content: [ 0x00, 0x00, 0x00, 0x00, 0xC8, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC8, 0x07, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000018 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000010 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: true + symbol: 0 + - offset: 0x00000008 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000000 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: true + symbol: 0 +undefined-symbols: + - name: ___CFConstantStringClassReference + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + +# CHECK: defined-atoms: +# CHECK: - ref-name: [[STR1:L[L0-9]+]] +# CHECK: scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 68, 65, 6C, 6C, 6F, 00 ] +# CHECK: merge: by-content +# CHECK: - ref-name: [[STR2:L[L0-9]+]] +# CHECK: scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 74, 68, 65, 72, 65, 00 ] +# CHECK: merge: by-content +# CHECK: - scope: hidden +# CHECK: type: cfstring +# CHECK: merge: by-content +# CHECK: references: +# CHECK: - kind: pointer32 +# CHECK: offset: 0 +# CHECK: target: ___CFConstantStringClassReference +# CHECK: - kind: pointer32 +# CHECK: offset: 8 +# CHECK: target: [[STR1]] +# CHECK: - scope: hidden +# CHECK: type: cfstring +# CHECK: merge: by-content +# CHECK: references: +# CHECK: - kind: pointer32 +# CHECK: offset: 0 +# CHECK: target: ___CFConstantStringClassReference +# CHECK: - kind: pointer32 +# CHECK: offset: 8 +# CHECK: target: [[STR2]] +# CHECK:undefined-atoms: +# CHECK: - name: ___CFConstantStringClassReference diff --git a/test/mach-o/parse-cfstring64.yaml b/test/mach-o/parse-cfstring64.yaml new file mode 100644 index 000000000000..fbd674d90d99 --- /dev/null +++ b/test/mach-o/parse-cfstring64.yaml @@ -0,0 +1,108 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of CFString constants. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __cstring + type: S_CSTRING_LITERALS + attributes: [ ] + address: 0x0000000000000000 + content: [ 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x00, 0x74, 0x68, + 0x65, 0x72, 0x65, 0x00 ] + - segment: __DATA + section: __cfstring + type: S_REGULAR + attributes: [ ] + alignment: 4 + address: 0x0000000000000010 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xC8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xC8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000030 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000020 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000010 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 0 + - offset: 0x00000000 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 2 +local-symbols: + - name: Lstr1 + type: N_SECT + sect: 1 + value: 0x0000000000000000 + - name: Lstr2 + type: N_SECT + sect: 1 + value: 0x0000000000000006 +undefined-symbols: + - name: ___CFConstantStringClassReference + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + +# CHECK:defined-atoms: +# CHECK: - ref-name: L000 +# CHECK: scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 68, 65, 6C, 6C, 6F, 00 ] +# CHECK: merge: by-content +# CHECK: - ref-name: L001 +# CHECK: scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 74, 68, 65, 72, 65, 00 ] +# CHECK: merge: by-content +# CHECK: - scope: hidden +# CHECK: type: cfstring +# CHECK: merge: by-content +# CHECK: references: +# CHECK: - kind: pointer64 +# CHECK: offset: 0 +# CHECK: target: ___CFConstantStringClassReference +# CHECK: - kind: pointer64 +# CHECK: offset: 16 +# CHECK: target: L000 +# CHECK: - scope: hidden +# CHECK: type: cfstring +# CHECK: merge: by-content +# CHECK: references: +# CHECK: - kind: pointer64 +# CHECK: offset: 0 +# CHECK: target: ___CFConstantStringClassReference +# CHECK: - kind: pointer64 +# CHECK: offset: 16 +# CHECK: target: L001 +# CHECK:undefined-atoms: +# CHECK: - name: ___CFConstantStringClassReference + diff --git a/test/mach-o/parse-compact-unwind32.yaml b/test/mach-o/parse-compact-unwind32.yaml new file mode 100644 index 000000000000..ff613f0809bb --- /dev/null +++ b/test/mach-o/parse-compact-unwind32.yaml @@ -0,0 +1,72 @@ +# RUN: lld -flavor darwin -arch i386 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of __LD/__compact_unwind (compact unwind) section. +# + +--- !mach-o +arch: x86 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0x55, 0x89, 0xE5, 0xB8, 0x0A, 0x00, 0x00, 0x00, + 0x5D, 0xC3, 0x55, 0x89, 0xE5, 0xB8, 0x0A, 0x00, + 0x00, 0x00, 0x5D, 0xC3 ] + - segment: __LD + section: __compact_unwind + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x000000000000001C + content: [ 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000014 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000000 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: false + symbol: 1 +global-symbols: + - name: __Z3barv + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x000000000000000A + - name: __Z3foov + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +... + +# CHECK: defined-atoms: +# CHECK: - type: compact-unwind +# CHECK: content: [ 00, 00, 00, 00, 0A, 00, 00, 00, 00, 00, 00, 01, +# CHECK: 00, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: - type: compact-unwind +# CHECK: content: [ 10, 00, 00, 00, 0A, 00, 00, 00, 00, 00, 00, 01, +# CHECK: 00, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: - name: __Z3foov +# CHECK: scope: global +# CHECK: content: [ 55, 89, E5, B8, 0A, 00, 00, 00, 5D, C3 ] +# CHECK: - name: __Z3barv +# CHECK: scope: global +# CHECK: content: [ 55, 89, E5, B8, 0A, 00, 00, 00, 5D, C3 ] + diff --git a/test/mach-o/parse-compact-unwind64.yaml b/test/mach-o/parse-compact-unwind64.yaml new file mode 100644 index 000000000000..b61961a3d0b0 --- /dev/null +++ b/test/mach-o/parse-compact-unwind64.yaml @@ -0,0 +1,76 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of __LD/__compact_unwind (compact unwind) section. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0xB8, 0x0A, 0x00, 0x00, + 0x00, 0x5D, 0xC3, 0x55, 0x48, 0x89, 0xE5, 0xB8, + 0x0A, 0x00, 0x00, 0x00, 0x5D, 0xC3 ] + - segment: __LD + section: __compact_unwind + type: S_REGULAR + attributes: [ ] + alignment: 3 + address: 0x0000000000000020 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000020 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000000 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: false + symbol: 1 +global-symbols: + - name: __Z3barv + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: __Z3foov + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x000000000000000B +... + +# CHECK: defined-atoms: +# CHECK: - type: compact-unwind +# CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00, 0B, 00, 00, 00, +# CHECK: 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, 00, +# CHECK: 00, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: - type: compact-unwind +# CHECK: content: [ 10, 00, 00, 00, 00, 00, 00, 00, 0B, 00, 00, 00, +# CHECK: 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, 00, +# CHECK: 00, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: - name: __Z3barv +# CHECK: scope: global +# CHECK: content: [ 55, 48, 89, E5, B8, 0A, 00, 00, 00, 5D, C3 ] +# CHECK: - name: __Z3foov +# CHECK: scope: global +# CHECK: content: [ 55, 48, 89, E5, B8, 0A, 00, 00, 00, 5D, C3 ] diff --git a/test/mach-o/parse-data-in-code-armv7.yaml b/test/mach-o/parse-data-in-code-armv7.yaml new file mode 100644 index 000000000000..29b483e7d723 --- /dev/null +++ b/test/mach-o/parse-data-in-code-armv7.yaml @@ -0,0 +1,157 @@ +# RUN: lld -flavor darwin -arch armv7 -r -print_atoms %s -o %t | FileCheck %s +# RUN: lld -flavor darwin -arch armv7 -r -print_atoms %t -o %t2 | FileCheck %s +# RUN: lld -flavor darwin -arch armv7 -dylib %s -o %t3.dylib %p/Inputs/libSystem.yaml \ +# RUN: && llvm-objdump -macho -private-headers %t3.dylib | FileCheck --check-prefix=CHECK2 %s +# +# Test parsing LC_DATA_IN_CODE +# +# + +--- !mach-o +arch: armv7 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0x00, 0xBF, 0x00, 0xBF, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x00, 0xBF, + 0x00, 0xF0, 0x20, 0xE3, 0x0A, 0x00, 0x00, 0x00, + 0x0B, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x20, 0xE3 ] +local-symbols: + - name: _foo_thumb + type: N_SECT + sect: 1 + desc: [ N_ARM_THUMB_DEF ] + value: 0x0000000000000000 + - name: _foo_arm + type: N_SECT + sect: 1 + value: 0x0000000000000018 +dataInCode: + - offset: 0x00000004 + length: 0x0004 + kind: DICE_KIND_DATA + - offset: 0x00000008 + length: 0x0004 + kind: DICE_KIND_JUMP_TABLE32 + - offset: 0x0000000C + length: 0x0004 + kind: DICE_KIND_JUMP_TABLE16 + - offset: 0x00000010 + length: 0x0004 + kind: DICE_KIND_JUMP_TABLE8 + - offset: 0x0000001C + length: 0x0004 + kind: DICE_KIND_DATA + - offset: 0x00000020 + length: 0x0004 + kind: DICE_KIND_JUMP_TABLE32 + - offset: 0x00000024 + length: 0x0004 + kind: DICE_KIND_JUMP_TABLE16 + - offset: 0x00000028 + length: 0x0004 + kind: DICE_KIND_JUMP_TABLE8 +... + + + +# CHECK: defined-atoms: +# CHECK: - name: _foo_thumb +# CHECK: references: +# CHECK: - kind: modeThumbCode +# CHECK: offset: 0 +# CHECK: - kind: modeData +# CHECK: offset: 4 +# CHECK: addend: 1 +# CHECK: - kind: modeData +# CHECK: offset: 8 +# CHECK: addend: 4 +# CHECK: - kind: modeData +# CHECK: offset: 12 +# CHECK: addend: 3 +# CHECK: - kind: modeData +# CHECK: offset: 16 +# CHECK: addend: 2 +# CHECK: - kind: modeThumbCode +# CHECK: offset: 20 +# CHECK: - name: _foo_arm +# CHECK: references: +# CHECK: - kind: modeData +# CHECK: offset: 4 +# CHECK: addend: 1 +# CHECK: - kind: modeData +# CHECK: offset: 8 +# CHECK: addend: 4 +# CHECK: - kind: modeData +# CHECK: offset: 12 +# CHECK: addend: 3 +# CHECK: - kind: modeData +# CHECK: offset: 16 +# CHECK: addend: 2 +# CHECK: - kind: modeArmCode +# CHECK: offset: 20 + + +# CHECK2: cmd LC_DATA_IN_CODE +# CHECK2: cmdsize 16 +# CHECK2: datasize 64 + + +# .code 16 +# .thumb_func _foo_thumb +#_foo_thumb: +# nop +# nop +# +# .data_region +# .long 0 +# .end_data_region +# +# .data_region jt32 +# .long 1 +# .end_data_region +# +# .data_region jt16 +# .long 2 +# .end_data_region +# +# .data_region jt8 +# .long 3 +# .end_data_region +# +# nop +# nop +# +# +# +# .code 32 +# .align 2 +#_foo_arm: +# nop +# +# .data_region +# .long 10 +# .end_data_region +# +# .data_region jt32 +# .long 11 +# .end_data_region +# +# .data_region jt16 +# .long 12 +# .end_data_region +# +# .data_region jt8 +# .long 13 +# .end_data_region +# +# nop +# diff --git a/test/mach-o/parse-data-in-code-x86.yaml b/test/mach-o/parse-data-in-code-x86.yaml new file mode 100644 index 000000000000..43934440f2a0 --- /dev/null +++ b/test/mach-o/parse-data-in-code-x86.yaml @@ -0,0 +1,77 @@ +# RUN: lld -flavor darwin -arch i386 -r -print_atoms %s -o %t | FileCheck %s \ +# RUN: && lld -flavor darwin -arch i386 -r -print_atoms %t -o %t2 | FileCheck %s +# +# Test parsing LC_DATA_IN_CODE +# +# + +--- !mach-o +arch: x86 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x90, 0x90, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x03, 0x00, + 0x00, 0x00 ] +local-symbols: + - name: _func1 + type: N_SECT + sect: 1 + value: 0x0000000000000000 + - name: _func2 + type: N_SECT + sect: 1 + value: 0x000000000000000B +dataInCode: + - offset: 0x00000002 + length: 0x0008 + kind: DICE_KIND_JUMP_TABLE32 + - offset: 0x0000000E + length: 0x0004 + kind: DICE_KIND_JUMP_TABLE32 +... + + + +# CHECK: defined-atoms: +# CHECK: - name: _func1 +# CHECK: references: +# CHECK: - kind: modeData +# CHECK: offset: 2 +# CHECK: addend: 4 +# CHECK: - kind: modeCode +# CHECK: offset: 10 +# CHECK: - name: _func2 +# CHECK: references: +# CHECK: - kind: modeData +# CHECK: offset: 3 +# CHECK: addend: 4 +# CHECK-NOT: - kind: modeData + + + + +# +#_func1: +# nop +# nop +# .data_region jt32 +# .long 1 +# .long 2 +# .end_data_region +# nop +# +# +# _func2: +# nop +# nop +# nop +# .data_region jt32 +# .long 3 +# .end_data_region +# diff --git a/test/mach-o/parse-data-relocs-arm64.yaml b/test/mach-o/parse-data-relocs-arm64.yaml new file mode 100644 index 000000000000..d02422f6a6f9 --- /dev/null +++ b/test/mach-o/parse-data-relocs-arm64.yaml @@ -0,0 +1,222 @@ +# RUN: lld -flavor darwin -arch arm64 -r -print_atoms %s -o %t | FileCheck %s +# RUN: lld -flavor darwin -arch arm64 -r -print_atoms %t -o %t2 | FileCheck %s +# +# Test parsing and writing of arm64 data relocations. +# +# The first step tests if the supplied mach-o file is parsed into the correct +# set of references. The second step verifies relocations can be round-tripped +# by writing to a new .o file, then parsing that file which should result in +# the same references. +# +#_test: + + +--- !mach-o +arch: arm64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + address: 0x0000000000000000 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xDC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xC0, 0xFF, 0xFF, 0xFF, 0xBE, 0xFF, 0xFF, 0xFF, + 0xB0, 0xFF, 0xFF, 0xFF ] + relocations: + - offset: 0x00000050 + type: ARM64_RELOC_POINTER_TO_GOT + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x0000004C + type: ARM64_RELOC_SUBTRACTOR + length: 2 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x0000004C + type: ARM64_RELOC_UNSIGNED + length: 2 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000048 + type: ARM64_RELOC_SUBTRACTOR + length: 2 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000048 + type: ARM64_RELOC_UNSIGNED + length: 2 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000040 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000038 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000030 + type: ARM64_RELOC_SUBTRACTOR + length: 3 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000030 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000028 + type: ARM64_RELOC_SUBTRACTOR + length: 3 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000028 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000020 + type: ARM64_RELOC_SUBTRACTOR + length: 3 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000020 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000018 + type: ARM64_RELOC_POINTER_TO_GOT + length: 3 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000010 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 1 + - offset: 0x00000008 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 1 +local-symbols: + - name: _v1 + type: N_SECT + sect: 1 + value: 0x0000000000000008 +undefined-symbols: + - name: _foo + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + +# CHECK: defined-atoms: +# CHECK: - ref-name: L000 +# CHECK: type: data +# CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: - name: _v1 +# CHECK: type: data +# CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00, 08, 00, 00, 00, +# CHECK: 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, +# CHECK: 00, 00, 00, 00, 00, 00, 00, 00, E0, FF, FF, FF, +# CHECK: FF, FF, FF, FF, DC, FF, FF, FF, FF, FF, FF, FF, +# CHECK: 00, 00, 00, 00, 00, 00, 00, 00, 04, 00, 00, 00, +# CHECK: 00, 00, 00, 00, C0, FF, FF, FF, BE, FF, FF, FF, +# CHECK: B0, FF, FF, FF ] +# CHECK: references: +# CHECK: - kind: pointer64 +# CHECK: offset: 0 +# CHECK: target: _foo +# CHECK-NOT: addend: +# CHECK: - kind: pointer64 +# CHECK: offset: 8 +# CHECK: target: _foo +# CHECK: addend: 8 +# CHECK: - kind: pointer64ToGOT +# CHECK: offset: 16 +# CHECK: target: _foo +# CHECK-NOT: addend: +# CHECK: - kind: delta64 +# CHECK: offset: 24 +# CHECK: target: _foo +# CHECK: addend: 24 +# CHECK: - kind: delta64 +# CHECK: offset: 32 +# CHECK: target: _foo +# CHECK-NOT: addend: +# CHECK: - kind: delta64 +# CHECK: offset: 40 +# CHECK: target: _foo +# CHECK: addend: 4 +# CHECK: - kind: pointer64 +# CHECK: offset: 48 +# CHECK: target: L000 +# CHECK-NOT: addend: +# CHECK: - kind: pointer64 +# CHECK: offset: 56 +# CHECK: target: _foo +# CHECK: addend: 4 +# CHECK: - kind: delta32 +# CHECK: offset: 64 +# CHECK: target: _foo +# CHECK-NOT: addend: +# CHECK: - kind: delta32 +# CHECK: offset: 68 +# CHECK: target: _foo +# CHECK: addend: 2 +# CHECK: - kind: delta32ToGOT +# CHECK: offset: 72 +# CHECK: target: _foo +# CHECK-NOT: addend: +# CHECK: undefined-atoms: +# CHECK: - name: _foo + + + +# .data +#Lanon: +# .quad 0 +#_v1: +# .quad _foo +# .quad _foo + 8 +# .quad _foo@GOT +# .quad _foo + 24 - . +# .quad _foo - . +# .quad _foo + 4 - . +# .quad Lanon +# .quad Lanon + 4 +# .long _foo - . +# .long _foo +2 - . +# .long _foo@GOT - . + diff --git a/test/mach-o/parse-data-relocs-x86_64.yaml b/test/mach-o/parse-data-relocs-x86_64.yaml new file mode 100644 index 000000000000..ae93c1bb75d9 --- /dev/null +++ b/test/mach-o/parse-data-relocs-x86_64.yaml @@ -0,0 +1,230 @@ + +# RUN: lld -flavor darwin -arch x86_64 -r %s -o %t -print_atoms | FileCheck %s \ +# RUN: && lld -flavor darwin -arch x86_64 %t -r -print_atoms -o %t2 | FileCheck %s +# +# Test parsing and writing of x86_64 text relocations. +# +# The first step tests if the supplied mach-o file is parsed into the correct +# set of references. The second step verifies relocations can be round-tripped +# by writing to a new .o file, then parsing that file which should result in +# the same references. +# +#_foo: +# ret +# +#_bar: +# ret +# +# .section __DATA,__custom +#L1: +# .quad 0 +# +# .data +#_d: +# .quad _foo +# .quad _foo+4 +# .quad _foo - . +# .quad L1 +# .quad L1 + 2 +# .quad _foo - . +# .quad _foo + 4 - . +# .quad L1 - . +# .long _foo - . +# .long _foo + 4 - . +# .long L1 - . +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xC3, 0xC3 ] + - segment: __DATA + section: __custom + type: S_REGULAR + attributes: [ ] + address: 0x0000000000000002 + content: [ 0x00, 0x00, 0x00, 0x00 ] + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 3 + address: 0x0000000000000008 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xDC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xD2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xC8, 0xFF, 0xFF, 0xFF, 0xC8, 0xFF, 0xFF, 0xFF, + 0xC2, 0xFF, 0xFF, 0xFF ] + relocations: + - offset: 0x00000040 + type: X86_64_RELOC_SUBTRACTOR + length: 2 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000040 + type: X86_64_RELOC_UNSIGNED + length: 2 + pc-rel: false + extern: false + symbol: 2 + - offset: 0x0000003C + type: X86_64_RELOC_SUBTRACTOR + length: 2 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x0000003C + type: X86_64_RELOC_UNSIGNED + length: 2 + pc-rel: false + extern: true + symbol: 0 + - offset: 0x00000038 + type: X86_64_RELOC_SUBTRACTOR + length: 2 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000038 + type: X86_64_RELOC_UNSIGNED + length: 2 + pc-rel: false + extern: true + symbol: 0 + - offset: 0x00000030 + type: X86_64_RELOC_SUBTRACTOR + length: 3 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000030 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: false + symbol: 2 + - offset: 0x00000028 + type: X86_64_RELOC_SUBTRACTOR + length: 3 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000028 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 0 + - offset: 0x00000020 + type: X86_64_RELOC_SUBTRACTOR + length: 3 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000020 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 0 + - offset: 0x00000018 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: false + symbol: 2 + - offset: 0x00000010 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: false + symbol: 2 + - offset: 0x00000008 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 0 + - offset: 0x00000000 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 0 +local-symbols: + - name: _foo + type: N_SECT + sect: 1 + value: 0x0000000000000000 + - name: _bar + type: N_SECT + sect: 1 + value: 0x0000000000000001 + - name: _d + type: N_SECT + sect: 3 + value: 0x0000000000000008 +... + + +# CHECK: defined-atoms: +# CHECK: - name: _d +# CHECK: type: data +# CHECK: references: +# CHECK: - kind: pointer64 +# CHECK: offset: 0 +# CHECK: target: _foo +# CHECK: - kind: pointer64 +# CHECK: offset: 8 +# CHECK: target: _foo +# CHECK: addend: 4 +# CHECK: - kind: pointer64Anon +# CHECK: offset: 16 +# CHECK: target: L003 +# CHECK: - kind: pointer64Anon +# CHECK: offset: 24 +# CHECK: target: L003 +# CHECK: addend: 2 +# CHECK: - kind: delta64 +# CHECK: offset: 32 +# CHECK: target: _foo +# CHECK: - kind: delta64 +# CHECK: offset: 40 +# CHECK: target: _foo +# CHECK: addend: 4 +# CHECK: - kind: delta64Anon +# CHECK: offset: 48 +# CHECK: target: L003 +# CHECK: - kind: delta32 +# CHECK: offset: 56 +# CHECK: target: _foo +# CHECK: - kind: delta32 +# CHECK: offset: 60 +# CHECK: target: _foo +# CHECK: addend: 4 +# CHECK: - kind: delta32Anon +# CHECK: offset: 64 +# CHECK: target: L003 +# CHECK: - name: _foo +# CHECK: content: [ C3 ] +# CHECK: - name: _bar +# CHECK: content: [ C3 ] +# CHECK: - ref-name: L003 +# CHECK: type: unknown +# CHECK: content: [ 00, 00, 00, 00 ] +# CHECK: section-choice: custom-required +# CHECK: section-name: __DATA/__custom diff --git a/test/mach-o/parse-data.yaml b/test/mach-o/parse-data.yaml new file mode 100644 index 000000000000..61d77290d108 --- /dev/null +++ b/test/mach-o/parse-data.yaml @@ -0,0 +1,119 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of mach-o data symbols. +# +# long a = 0x0807060504030201; +# int b = 0x14131211; +# int c = 0x24232221; +# static int s1; +# static int s2 = 0x34333231; +# +# + + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 3 + address: 0x0000000000000000 + content: [ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x11, 0x12, 0x13, 0x14, 0x21, 0x22, 0x23, 0x24, + 0x31, 0x32, 0x33, 0x34, 0x41, 0x42, 0x43, 0x44 ] + - segment: __CUST + section: __custom + type: S_REGULAR + attributes: [ ] + alignment: 3 + address: 0x0000000000000018 + content: [ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 ] + - segment: __DATA + section: __bss + type: S_ZEROFILL + attributes: [ ] + alignment: 2 + address: 0x0000000000000020 + size: 4 +local-symbols: + - name: _s1 + type: N_SECT + sect: 3 + value: 0x0000000000000020 + - name: _s2 + type: N_SECT + sect: 1 + value: 0x0000000000000010 +global-symbols: + - name: _a + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: _b + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000008 + - name: _c + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x000000000000000C + - name: _cWeak + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_WEAK_DEF ] + value: 0x0000000000000014 + - name: _kustom + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x0000000000000018 +... + +# CHECK: defined-atoms: + +# CHECK: - name: _a +# CHECK: scope: global +# CHECK: type: data +# CHECK: content: [ 01, 02, 03, 04, 05, 06, 07, 08 ] + +# CHECK: - name: _b +# CHECK: scope: global +# CHECK: type: data +# CHECK: content: [ 11, 12, 13, 14 ] + +# CHECK: - name: _c +# CHECK: scope: global +# CHECK: type: data +# CHECK: content: [ 21, 22, 23, 24 ] + +# CHECK: - name: _s2 +# CHECK: type: data +# CHECK: content: [ 31, 32, 33, 34 ] + +# CHECK: - name: _cWeak +# CHECK: scope: global +# CHECK: type: data +# CHECK: content: [ 41, 42, 43, 44 ] +# CHECK: merge: as-weak + +# CHECK: - name: _s1 +# CHECK: type: zero-fill +# CHECK: size: 4 + +# CHECK: - name: _kustom +# CHECK: scope: global +# CHECK: type: unknown +# CHECK: content: [ 01, 02, 03, 04, 05, 06, 07, 08 ] +# CHECK: section-choice: custom-required +# CHECK: section-name: __CUST/__custom + diff --git a/test/mach-o/parse-eh-frame-x86-anon.yaml b/test/mach-o/parse-eh-frame-x86-anon.yaml new file mode 100644 index 000000000000..9e3adaea1849 --- /dev/null +++ b/test/mach-o/parse-eh-frame-x86-anon.yaml @@ -0,0 +1,129 @@ +# RUN: lld -flavor darwin -arch i386 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of new __eh_frame (dwarf unwind) section that has no .eh labels +# and no relocations. +# + +--- !mach-o +arch: x86 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x89, 0xE5, 0x56, 0x83, 0xEC, 0x14, 0xE8, + 0x00, 0x00, 0x00, 0x00, 0x5E, 0xC7, 0x04, 0x24, + 0x04, 0x00, 0x00, 0x00, 0xE8, 0xE7, 0xFF, 0xFF, + 0xFF, 0xC7, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x8B, + 0x8E, 0x38, 0x00, 0x00, 0x00, 0x89, 0x4C, 0x24, + 0x04, 0x89, 0x04, 0x24, 0xC7, 0x44, 0x24, 0x08, + 0x00, 0x00, 0x00, 0x00, 0xE8, 0xC7, 0xFF, 0xFF, + 0xFF, 0x55, 0x89, 0xE5, 0x83, 0xEC, 0x08, 0xE8, + 0xBC, 0xFF, 0xFF, 0xFF ] + relocations: + - offset: 0x00000040 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: true + extern: false + symbol: 1 + - offset: 0x00000035 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: true + extern: true + symbol: 4 + - offset: 0x00000021 + scattered: true + type: GENERIC_RELOC_LOCAL_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000044 + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x0000000C + - offset: 0x00000015 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: true + extern: true + symbol: 3 + - segment: __IMPORT + section: __pointers + type: S_NON_LAZY_SYMBOL_POINTERS + attributes: [ ] + address: 0x0000000000000044 + content: [ 0x00, 0x00, 0x00, 0x00 ] + indirect-syms: [ 5 ] + - segment: __TEXT + section: __eh_frame + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x0000000000000048 + content: [ 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x7A, 0x52, 0x00, 0x01, 0x7C, 0x08, 0x01, + 0x10, 0x0C, 0x05, 0x04, 0x88, 0x01, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, + 0x98, 0xFF, 0xFF, 0xFF, 0x39, 0x00, 0x00, 0x00, + 0x00, 0x41, 0x0E, 0x08, 0x84, 0x02, 0x42, 0x0D, + 0x04, 0x44, 0x86, 0x03, 0x18, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0xB5, 0xFF, 0xFF, 0xFF, + 0x0B, 0x00, 0x00, 0x00, 0x00, 0x41, 0x0E, 0x08, + 0x84, 0x02, 0x42, 0x0D, 0x04, 0x00, 0x00, 0x00 ] +global-symbols: + - name: __Z3barv + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000039 + - name: __Z3foov + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: __ZTIi + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: ___cxa_allocate_exception + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: ___cxa_throw + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + +# CHECK: defined-atoms: +# CHECK: - ref-name: [[CIE:L[L0-9]+]] +# CHECK: type: unwind-cfi +# CHECK: content: +# CHECK: - type: unwind-cfi +# CHECK: content: +# CHECK: references: +# CHECK: - kind: negDelta32 +# CHECK: offset: 4 +# CHECK: target: [[CIE]] +# CHECK: - kind: delta32 +# CHECK: offset: 8 +# CHECK: target: __Z3foov +# CHECK: - type: unwind-cfi +# CHECK: content: +# CHECK: references: +# CHECK: - kind: negDelta32 +# CHECK: offset: 4 +# CHECK: target: [[CIE]] +# CHECK: - kind: delta32 +# CHECK: offset: 8 +# CHECK: target: __Z3barv + diff --git a/test/mach-o/parse-eh-frame-x86-labeled.yaml b/test/mach-o/parse-eh-frame-x86-labeled.yaml new file mode 100644 index 000000000000..b07a534e6493 --- /dev/null +++ b/test/mach-o/parse-eh-frame-x86-labeled.yaml @@ -0,0 +1,193 @@ +# RUN: lld -flavor darwin -arch i386 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of old __eh_frame (dwarf unwind) section that has .eh labels +# and relocations. +# + +--- !mach-o +arch: x86 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x89, 0xE5, 0x56, 0x83, 0xEC, 0x14, 0xE8, + 0x00, 0x00, 0x00, 0x00, 0x5E, 0xC7, 0x04, 0x24, + 0x04, 0x00, 0x00, 0x00, 0xE8, 0xE7, 0xFF, 0xFF, + 0xFF, 0xC7, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x8B, + 0x8E, 0x38, 0x00, 0x00, 0x00, 0x89, 0x4C, 0x24, + 0x04, 0x89, 0x04, 0x24, 0xC7, 0x44, 0x24, 0x08, + 0x00, 0x00, 0x00, 0x00, 0xE8, 0xC7, 0xFF, 0xFF, + 0xFF, 0x55, 0x89, 0xE5, 0x83, 0xEC, 0x08, 0xE8, + 0xBC, 0xFF, 0xFF, 0xFF ] + relocations: + - offset: 0x00000040 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: true + extern: false + symbol: 1 + - offset: 0x00000035 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: true + extern: true + symbol: 7 + - offset: 0x00000021 + scattered: true + type: GENERIC_RELOC_LOCAL_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000044 + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x0000000C + - offset: 0x00000015 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: true + extern: true + symbol: 6 + - segment: __IMPORT + section: __pointers + type: S_NON_LAZY_SYMBOL_POINTERS + attributes: [ ] + address: 0x0000000000000044 + content: [ 0x00, 0x00, 0x00, 0x00 ] + indirect-syms: [ 5 ] + - segment: __TEXT + section: __eh_frame + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x0000000000000048 + content: [ 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x7A, 0x52, 0x00, 0x01, 0x7C, 0x08, 0x01, + 0x10, 0x0C, 0x05, 0x04, 0x88, 0x01, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, + 0x98, 0xFF, 0xFF, 0xFF, 0x39, 0x00, 0x00, 0x00, + 0x00, 0x41, 0x0E, 0x08, 0x84, 0x02, 0x42, 0x0D, + 0x04, 0x44, 0x86, 0x03, 0x18, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0xB5, 0xFF, 0xFF, 0xFF, + 0x0B, 0x00, 0x00, 0x00, 0x00, 0x41, 0x0E, 0x08, + 0x84, 0x02, 0x42, 0x0D, 0x04, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x0000001C + scattered: true + type: GENERIC_RELOC_LOCAL_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000064 + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x00000048 + - offset: 0x00000020 + scattered: true + type: GENERIC_RELOC_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000000 + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x00000068 + - offset: 0x00000038 + scattered: true + type: GENERIC_RELOC_LOCAL_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000080 + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x00000048 + - offset: 0x0000003C + scattered: true + type: GENERIC_RELOC_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000039 + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x00000084 +local-symbols: + - name: EH_frame0 + type: N_SECT + sect: 3 + value: 0x0000000000000048 +global-symbols: + - name: __Z3barv + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000039 + - name: __Z3barv.eh + type: N_SECT + scope: [ N_EXT ] + sect: 3 + value: 0x000000000000007C + - name: __Z3foov + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: __Z3foov.eh + type: N_SECT + scope: [ N_EXT ] + sect: 3 + value: 0x0000000000000060 +undefined-symbols: + - name: __ZTIi + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: ___cxa_allocate_exception + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: ___cxa_throw + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + +# CHECK: defined-atoms: +# CHECK: - ref-name: [[CIE:L[L0-9]+]] +# CHECK: type: unwind-cfi +# CHECK: content: +# CHECK: - type: unwind-cfi +# CHECK: content: +# CHECK: references: +# CHECK: - kind: negDelta32 +# CHECK: offset: 4 +# CHECK: target: [[CIE]] +# CHECK: - kind: delta32 +# CHECK: offset: 8 +# CHECK: target: __Z3foov +# CHECK: - type: unwind-cfi +# CHECK: content: +# CHECK: references: +# CHECK: - kind: negDelta32 +# CHECK: offset: 4 +# CHECK: target: [[CIE]] +# CHECK: - kind: delta32 +# CHECK: offset: 8 +# CHECK: target: __Z3barv + diff --git a/test/mach-o/parse-eh-frame.yaml b/test/mach-o/parse-eh-frame.yaml new file mode 100644 index 000000000000..69324800e991 --- /dev/null +++ b/test/mach-o/parse-eh-frame.yaml @@ -0,0 +1,88 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of __eh_frame (dwarf unwind) section. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0xB8, 0x09, 0x00, 0x00, + 0x00, 0x5D, 0xC3, 0x55, 0x48, 0x89, 0xE5, 0xB8, + 0x0A, 0x00, 0x00, 0x00, 0x5D, 0xC3 ] + - segment: __TEXT + section: __eh_frame + type: S_COALESCED + attributes: [ ] + alignment: 3 + address: 0x0000000000000058 + content: [ 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x7A, 0x52, 0x00, 0x01, 0x78, 0x10, 0x01, + 0x10, 0x0C, 0x07, 0x08, 0x90, 0x01, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, + 0x88, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x41, 0x0E, 0x10, 0x86, 0x02, 0x43, 0x0D, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x6B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x41, 0x0E, 0x10, 0x86, 0x02, 0x43, 0x0D, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] +global-symbols: + - name: __Z3barv + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: __Z3foov + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x000000000000000B +... + +# CHECK: defined-atoms: +# CHECK: - ref-name: [[CIE:L[0-9]+]] +# CHECK: type: unwind-cfi +# CHECK: content: [ 14, 00, 00, 00, 00, 00, 00, 00, 01, 7A, 52, 00, +# CHECK: 01, 78, 10, 01, 10, 0C, 07, 08, 90, 01, 00, 00 ] +# CHECK: - type: unwind-cfi +# CHECK: content: [ 24, 00, 00, 00, 1C, 00, 00, 00, 88, FF, FF, FF, +# CHECK: FF, FF, FF, FF, 0B, 00, 00, 00, 00, 00, 00, 00, +# CHECK: 00, 41, 0E, 10, 86, 02, 43, 0D, 06, 00, 00, 00, +# CHECK: 00, 00, 00, 00 ] +# CHECK: references: +# CHECK: - kind: negDelta32 +# CHECK: offset: 4 +# CHECK: target: [[CIE]] +# CHECK: - kind: unwindFDEToFunction +# CHECK: offset: 8 +# CHECK: target: __Z3barv +# CHECK: - type: unwind-cfi +# CHECK: content: [ 24, 00, 00, 00, 44, 00, 00, 00, 6B, FF, FF, FF, +# CHECK: FF, FF, FF, FF, 0B, 00, 00, 00, 00, 00, 00, 00, +# CHECK: 00, 41, 0E, 10, 86, 02, 43, 0D, 06, 00, 00, 00, +# CHECK: 00, 00, 00, 00 ] +# CHECK: references: +# CHECK: - kind: negDelta32 +# CHECK: offset: 4 +# CHECK: target: [[CIE]] +# CHECK: - kind: unwindFDEToFunction +# CHECK: offset: 8 +# CHECK: target: __Z3foov +# CHECK: - name: __Z3barv +# CHECK: scope: global +# CHECK: content: [ 55, 48, 89, E5, B8, 09, 00, 00, 00, 5D, C3 ] +# CHECK: - name: __Z3foov +# CHECK: scope: global +# CHECK: content: [ 55, 48, 89, E5, B8, 0A, 00, 00, 00, 5D, C3 ] + diff --git a/test/mach-o/parse-function.yaml b/test/mach-o/parse-function.yaml new file mode 100644 index 000000000000..1bc9878c7087 --- /dev/null +++ b/test/mach-o/parse-function.yaml @@ -0,0 +1,100 @@ +# RUN: lld -flavor darwin -arch x86_64 -r %s -o %t +# RUN: lld -flavor darwin -arch x86_64 -r %t -print_atoms -o %t2 | FileCheck %s +# +# Test parsing of mach-o functions. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0xCC, 0xC3, 0x90, 0xC3, 0x90, 0x90, 0xC3, 0x90, + 0x90, 0x90, 0xC3, 0x90, 0x90, 0x90, 0x90, 0xC3, + 0xCC, 0x31, 0xC0, 0xC3 ] +local-symbols: + - name: _myStatic + type: N_SECT + sect: 1 + value: 0x000000000000000B +global-symbols: + - name: _myGlobal + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000001 + - name: _myGlobalWeak + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_WEAK_DEF ] + value: 0x0000000000000002 + - name: _myHidden + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 1 + value: 0x0000000000000004 + - name: _myHiddenWeak + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 1 + desc: [ N_WEAK_DEF ] + value: 0x0000000000000007 + - name: _myStripNot + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_NO_DEAD_STRIP ] + value: 0x0000000000000010 + - name: _myResolver + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_SYMBOL_RESOLVER ] + value: 0x0000000000000011 +... + +# CHECK-NOT: name: +# CHECK: content: [ CC ] + +# CHECK: name: _myGlobal +# CHECK: scope: global +# CHECK: content: [ C3 ] + +# CHECK: name: _myGlobalWeak +# CHECK: scope: global +# CHECK: content: [ 90, C3 ] +# CHECK: merge: as-weak + +# CHECK: name: _myHidden +# CHECK: scope: hidden +# CHECK: content: [ 90, 90, C3 ] + +# CHECK: name: _myHiddenWeak +# CHECK: scope: hidden +# CHECK: content: [ 90, 90, 90, C3 ] +# CHECK: merge: as-weak + +# CHECK: name: _myStatic +# CHECK-NOT: scope: global +# CHECK-NOT: scope: hidden +# CHECK: content: [ 90, 90, 90, 90, C3 ] + +# CHECK: name: _myStripNot +# CHECK: scope: global +# CHECK: content: [ CC ] +# CHECK: dead-strip: never + +# CHECK: name: _myResolver +# CHECK: scope: global +# CHECK: type: resolver +# CHECK: content: [ 31, C0, C3 ] + diff --git a/test/mach-o/parse-initializers32.yaml b/test/mach-o/parse-initializers32.yaml new file mode 100644 index 000000000000..ede7b90e2cb9 --- /dev/null +++ b/test/mach-o/parse-initializers32.yaml @@ -0,0 +1,84 @@ +# RUN: lld -flavor darwin -arch i386 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of literal sections. +# + +--- !mach-o +arch: x86 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x89, 0xE5, 0x5D, 0xC3, 0x55, 0x89, 0xE5, + 0x5D, 0xC3, 0x55, 0x89, 0xE5, 0x5D, 0xC3 ] + - segment: __DATA + section: __mod_init_func + type: S_MOD_INIT_FUNC_POINTERS + attributes: [ ] + alignment: 2 + address: 0x0000000000000044 + content: [ 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000000 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000004 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: false + symbol: 1 + - segment: __DATA + section: __mod_term_func + type: S_MOD_TERM_FUNC_POINTERS + attributes: [ ] + alignment: 2 + address: 0x0000000000000104 + content: [ 0x0A, 0x00, 0x00, 0x00 ] +global-symbols: + - name: _init + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: _init2 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000005 + - name: _term + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x000000000000000A +... + + +# CHECK:defined-atoms: +# CHECK: - type: initializer-pointer +# CHECK: content: [ 00, 00, 00, 00 ] +# CHECK: dead-strip: never +# CHECK: - type: initializer-pointer +# CHECK: content: [ 05, 00, 00, 00 ] +# CHECK: dead-strip: never +# CHECK: - type: terminator-pointer +# CHECK: content: [ 0A, 00, 00, 00 ] +# CHECK: dead-strip: never +# CHECK: - name: _init +# CHECK: scope: global +# CHECK: content: [ 55, 89, E5, 5D, C3 ] +# CHECK: - name: _init2 +# CHECK: scope: global +# CHECK: content: [ 55, 89, E5, 5D, C3 ] +# CHECK: - name: _term +# CHECK: scope: global +# CHECK: content: [ 55, 89, E5, 5D, C3 ] diff --git a/test/mach-o/parse-initializers64.yaml b/test/mach-o/parse-initializers64.yaml new file mode 100644 index 000000000000..5ebd8dafd7ce --- /dev/null +++ b/test/mach-o/parse-initializers64.yaml @@ -0,0 +1,105 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of literal sections. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x5D, 0xC3, 0x55, 0x48, + 0x89, 0xE5, 0x5D, 0xC3, 0x55, 0x48, 0x89, 0xE5, + 0x5D, 0xC3 ] + - segment: __DATA + section: __mod_init_func + type: S_MOD_INIT_FUNC_POINTERS + attributes: [ ] + alignment: 0 + address: 0x0000000000000100 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000000 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 0 + - offset: 0x00000008 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 1 + - segment: __DATA + section: __mod_term_func + type: S_MOD_TERM_FUNC_POINTERS + attributes: [ ] + alignment: 3 + address: 0x0000000000000108 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000000 + type: X86_64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 2 +global-symbols: + - name: _init + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: _init2 + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000006 + - name: _term + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x000000000000000C +... + + +# CHECK:defined-atoms: +# CHECK: - type: initializer-pointer +# CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: dead-strip: never +# CHECK: references: +# CHECK: - kind: pointer64 +# CHECK: offset: 0 +# CHECK: target: _init +# CHECK: - type: initializer-pointer +# CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: dead-strip: never +# CHECK: references: +# CHECK: - kind: pointer64 +# CHECK: offset: 0 +# CHECK: target: _init2 +# CHECK: - type: terminator-pointer +# CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: dead-strip: never +# CHECK: references: +# CHECK: - kind: pointer64 +# CHECK: offset: 0 +# CHECK: target: _term +# CHECK: - name: _init +# CHECK: scope: global +# CHECK: content: [ 55, 48, 89, E5, 5D, C3 ] +# CHECK: - name: _init2 +# CHECK: scope: global +# CHECK: content: [ 55, 48, 89, E5, 5D, C3 ] +# CHECK: - name: _term +# CHECK: scope: global +# CHECK: content: [ 55, 48, 89, E5, 5D, C3 ] diff --git a/test/mach-o/parse-literals-error.yaml b/test/mach-o/parse-literals-error.yaml new file mode 100644 index 000000000000..be21d6efffa3 --- /dev/null +++ b/test/mach-o/parse-literals-error.yaml @@ -0,0 +1,25 @@ +# RUN: not lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t 2> %t.err +# RUN: FileCheck %s < %t.err +# +# Test for error if literal section is not correct size mulitple. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __literal8 + type: S_8BYTE_LITERALS + attributes: [ ] + alignment: 0 + address: 0x0000000000000120 + content: [ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D ] +... + +# CHECK: error: + diff --git a/test/mach-o/parse-literals.yaml b/test/mach-o/parse-literals.yaml new file mode 100644 index 000000000000..24568ea0fd4f --- /dev/null +++ b/test/mach-o/parse-literals.yaml @@ -0,0 +1,93 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of literal sections. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __cstring + type: S_CSTRING_LITERALS + attributes: [ ] + alignment: 0 + address: 0x0000000000000100 + content: [ 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x00, 0x74, 0x68, + 0x65, 0x72, 0x65, 0x00, 0x77, 0x6F, 0x72, 0x6C, + 0x00 ] + - segment: __TEXT + section: __literal4 + type: S_4BYTE_LITERALS + attributes: [ ] + alignment: 0 + address: 0x0000000000000114 + content: [ 0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14, + 0x28, 0x29, 0x2A, 0x2B ] + - segment: __TEXT + section: __literal8 + type: S_8BYTE_LITERALS + attributes: [ ] + alignment: 0 + address: 0x0000000000000120 + content: [ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F ] + - segment: __TEXT + section: __literal16 + type: S_16BYTE_LITERALS + attributes: [ ] + alignment: 0 + address: 0x0000000000000130 + content: [ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00 ] + - segment: __TEXT + section: __ustring + type: S_REGULAR + attributes: [ ] + alignment: 0 + address: 0x0000000000000100 + content: [ 0x68, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, + 0x6F, 0x00, 0x00, 0x00, 0x74, 0x00, 0x68, 0x00, + 0x65, 0x00, 0x72, 0x00, 0x00, 0x00 ] +... + + +# CHECK:defined-atoms: +# CHECK: - scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 68, 65, 6C, 6C, 6F, 00 ] +# CHECK: - scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 74, 68, 65, 72, 65, 00 ] +# CHECK: - scope: hidden +# CHECK: type: c-string +# CHECK: content: [ 77, 6F, 72, 6C, 00 ] +# CHECK: - scope: hidden +# CHECK: type: utf16-string +# CHECK: content: [ 68, 00, 65, 00, 6C, 00, 6C, 00, 6F, 00, 00, 00 ] +# CHECK: - scope: hidden +# CHECK: type: utf16-string +# CHECK: content: [ 74, 00, 68, 00, 65, 00, 72, 00, 00, 00 ] +# CHECK: - scope: hidden +# CHECK: type: const-4-byte +# CHECK: content: [ 01, 02, 03, 04 ] +# CHECK: - scope: hidden +# CHECK: type: const-4-byte +# CHECK: content: [ 11, 12, 13, 14 ] +# CHECK: - scope: hidden +# CHECK: type: const-4-byte +# CHECK: content: [ 28, 29, 2A, 2B ] +# CHECK: - scope: hidden +# CHECK: type: const-8-byte +# CHECK: content: [ 01, 02, 03, 04, 05, 06, 07, 08 ] +# CHECK: - scope: hidden +# CHECK: type: const-8-byte +# CHECK: content: [ 28, 29, 2A, 2B, 2C, 2D, 2E, 2F ] +# CHECK: - scope: hidden +# CHECK: type: const-16-byte +# CHECK: content: [ 01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, +# CHECK: 0D, 0E, 0F, 00 ] + diff --git a/test/mach-o/parse-non-lazy-pointers.yaml b/test/mach-o/parse-non-lazy-pointers.yaml new file mode 100644 index 000000000000..0b0ec5cf36ef --- /dev/null +++ b/test/mach-o/parse-non-lazy-pointers.yaml @@ -0,0 +1,98 @@ +# RUN: lld -flavor darwin -arch i386 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of non-lazy-pointer sections. +# + +--- !mach-o +arch: x86 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x89, 0xE5, 0xE8, 0x00, 0x00, 0x00, 0x00, + 0x59, 0x8D, 0x81, 0x14, 0x00, 0x00, 0x00, 0x8D, + 0x81, 0x18, 0x00, 0x00, 0x00, 0x5D, 0xC3, 0x55, + 0x89, 0xE5, 0x5D, 0xC3 ] + relocations: + - offset: 0x00000011 + scattered: true + type: GENERIC_RELOC_LOCAL_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000020 + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x00000008 + - offset: 0x0000000B + scattered: true + type: GENERIC_RELOC_LOCAL_SECTDIFF + length: 2 + pc-rel: false + value: 0x0000001C + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x00000008 + - segment: __IMPORT + section: __pointers + type: S_NON_LAZY_SYMBOL_POINTERS + attributes: [ ] + address: 0x000000000000001C + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + indirect-syms: [ 2, 2147483648 ] +local-symbols: + - name: _foo + type: N_SECT + sect: 1 + value: 0x0000000000000017 +global-symbols: + - name: _get + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _bar + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + + +# CHECK:defined-atoms: +# CHECK: - ref-name: [[GOT1:L[L0-9]+]] +# CHECK: scope: hidden +# CHECK: type: got +# CHECK: content: [ 00, 00, 00, 00 ] +# CHECK: merge: by-content +# CHECK: - ref-name: [[GOT2:L[L0-9]+]] +# CHECK: scope: hidden +# CHECK: type: got +# CHECK: content: [ 00, 00, 00, 00 ] +# CHECK: merge: by-content +# CHECK: - name: _get +# CHECK: scope: global +# CHECK: content: [ 55, 89, E5, E8, 00, 00, 00, 00, 59, 8D, 81, 14, +# CHECK: 00, 00, 00, 8D, 81, 18, 00, 00, 00, 5D, C3 ] +# CHECK: references: +# CHECK: - kind: funcRel32 +# CHECK: offset: 11 +# CHECK: target: [[GOT1]] +# CHECK: - kind: funcRel32 +# CHECK: offset: 17 +# CHECK: target: [[GOT2]] +# CHECK: - name: _foo +# CHECK: content: [ 55, 89, E5, 5D, C3 ] + + diff --git a/test/mach-o/parse-relocs-x86.yaml b/test/mach-o/parse-relocs-x86.yaml new file mode 100644 index 000000000000..3fc22ae71bfc --- /dev/null +++ b/test/mach-o/parse-relocs-x86.yaml @@ -0,0 +1,296 @@ +# RUN: lld -flavor darwin -arch i386 -r -print_atoms %s -o %t | FileCheck %s \ +# RUN: && lld -flavor darwin -arch i386 -r -print_atoms %t -o %t2 | FileCheck %s +# +# Test parsing and writing of x86 relocations. +# +# The first step tests if the supplied mach-o file is parsed into the correct +# set of references. The second step verifies relocations can be round-tripped +# by writing to a new .o file, then parsing that file which should result in +# the same references. +# +# .text +#_test: +# call _undef +# call _undef+2 +# call _foo +# call _foo+2 +# callw _undef +# callw _foo +# callw _foo+2 +#L1: +# movl _undef, %eax +# movl _x, %eax +# movl _x+4, %eax +# movl _x-L1(%eax), %eax +# movl _x+4-L1(%eax), %eax +# +#_foo: +# ret +# +# .data +#_x: +# .long _undef +# .long _undef+7 +# .long _foo +# .long _foo+3 +# .long _test - . +# .long _test+3 - . +# + +--- !mach-o +arch: x86 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xE8, 0xFB, 0xFF, 0xFF, 0xFF, 0xE8, 0xF8, 0xFF, + 0xFF, 0xFF, 0xE8, 0x2C, 0x00, 0x00, 0x00, 0xE8, + 0x29, 0x00, 0x00, 0x00, 0x66, 0xE8, 0xE8, 0xFF, + 0x66, 0xE8, 0x1F, 0x00, 0x66, 0xE8, 0x1D, 0x00, + 0xA1, 0x00, 0x00, 0x00, 0x00, 0xA1, 0x3C, 0x00, + 0x00, 0x00, 0xA1, 0x40, 0x00, 0x00, 0x00, 0x8B, + 0x80, 0x1C, 0x00, 0x00, 0x00, 0x8B, 0x80, 0x20, + 0x00, 0x00, 0x00, 0xC3 ] + relocations: + - offset: 0x00000037 + scattered: true + type: GENERIC_RELOC_LOCAL_SECTDIFF + length: 2 + pc-rel: false + value: 0x0000003C + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x00000020 + - offset: 0x00000031 + scattered: true + type: GENERIC_RELOC_LOCAL_SECTDIFF + length: 2 + pc-rel: false + value: 0x0000003C + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x00000020 + - offset: 0x0000002B + scattered: true + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + value: 0x0000003C + - offset: 0x00000026 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: false + symbol: 2 + - offset: 0x00000021 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: true + symbol: 3 + - offset: 0x0000001E + scattered: true + type: GENERIC_RELOC_VANILLA + length: 1 + pc-rel: true + value: 0x0000003B + - offset: 0x0000001A + type: GENERIC_RELOC_VANILLA + length: 1 + pc-rel: true + extern: false + symbol: 1 + - offset: 0x00000016 + type: GENERIC_RELOC_VANILLA + length: 1 + pc-rel: true + extern: true + symbol: 3 + - offset: 0x00000010 + scattered: true + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: true + value: 0x0000003B + - offset: 0x0000000B + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: true + extern: false + symbol: 1 + - offset: 0x00000006 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: true + extern: true + symbol: 3 + - offset: 0x00000001 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: true + extern: true + symbol: 3 + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + address: 0x000000000000003C + content: [ 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x3B, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, + 0xB4, 0xFF, 0xFF, 0xFF, 0xB3, 0xFF, 0xFF, 0xFF ] + relocations: + - offset: 0x00000014 + scattered: true + type: GENERIC_RELOC_LOCAL_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000000 + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x00000050 + - offset: 0x00000010 + scattered: true + type: GENERIC_RELOC_LOCAL_SECTDIFF + length: 2 + pc-rel: false + value: 0x00000000 + - offset: 0x00000000 + scattered: true + type: GENERIC_RELOC_PAIR + length: 2 + pc-rel: false + value: 0x0000004C + - offset: 0x0000000C + scattered: true + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + value: 0x0000003B + - offset: 0x00000008 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000004 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: true + symbol: 3 + - offset: 0x00000000 + type: GENERIC_RELOC_VANILLA + length: 2 + pc-rel: false + extern: true + symbol: 3 +local-symbols: + - name: _test + type: N_SECT + sect: 1 + value: 0x0000000000000000 + - name: _foo + type: N_SECT + sect: 1 + value: 0x000000000000003B + - name: _x + type: N_SECT + sect: 2 + value: 0x000000000000003C +undefined-symbols: + - name: _undef + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + +# CHECK: defined-atoms: +# CHECK: - name: _x +# CHECK: type: data +# CHECK: references: +# CHECK: - kind: pointer32 +# CHECK: offset: 0 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: pointer32 +# CHECK: offset: 4 +# CHECK: target: _undef +# CHECK: addend: 7 +# CHECK: - kind: pointer32 +# CHECK: offset: 8 +# CHECK: target: _foo +# CHECK-NOT: addend: +# CHECK: - kind: pointer32 +# CHECK: offset: 12 +# CHECK: target: _foo +# CHECK: addend: 3 +# CHECK: - kind: delta32 +# CHECK: offset: 16 +# CHECK: target: _test +# CHECK: - kind: delta32 +# CHECK: offset: 20 +# CHECK: target: _test +# CHECK: addend: 3 +# CHECK: - name: _test +# CHECK: references: +# CHECK: - kind: branch32 +# CHECK: offset: 1 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: branch32 +# CHECK: offset: 6 +# CHECK: target: _undef +# CHECK: addend: 2 +# CHECK: - kind: branch32 +# CHECK: offset: 11 +# CHECK: target: _foo +# CHECK-NOT: addend: +# CHECK: - kind: branch32 +# CHECK: offset: 16 +# CHECK: target: _foo +# CHECK: addend: 2 +# CHECK: - kind: branch16 +# CHECK: offset: 22 +# CHECK: target: _undef +# CHECK-NOT: addend: +# CHECK: - kind: branch16 +# CHECK: offset: 26 +# CHECK: target: _foo +# CHECK-NOT: addend: +# CHECK: - kind: branch16 +# CHECK: offset: 30 +# CHECK: target: _foo +# CHECK: addend: 2 +# CHECK: - kind: abs32 +# CHECK: offset: 33 +# CHECK: target: _undef +# CHECK: - kind: abs32 +# CHECK: offset: 38 +# CHECK: target: _x +# CHECK: - kind: abs32 +# CHECK: offset: 43 +# CHECK: target: _x +# CHECK: addend: 4 +# CHECK: - kind: funcRel32 +# CHECK: offset: 49 +# CHECK: target: _x +# CHECK: addend: -32 +# CHECK: - kind: funcRel32 +# CHECK: offset: 55 +# CHECK: target: _x +# CHECK: addend: -28 + diff --git a/test/mach-o/parse-section-no-symbol.yaml b/test/mach-o/parse-section-no-symbol.yaml new file mode 100644 index 000000000000..46d005a1cd18 --- /dev/null +++ b/test/mach-o/parse-section-no-symbol.yaml @@ -0,0 +1,23 @@ +# RUN: lld -flavor darwin -arch x86_64 -r %s -print_atoms -o %t2 | FileCheck %s +# +# Test parsing of mach-o functions with no symbols at all. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0xCC ] +... + +# CHECK-NOT: name: +# CHECK: content: [ CC ] diff --git a/test/mach-o/parse-tentative-defs.yaml b/test/mach-o/parse-tentative-defs.yaml new file mode 100644 index 000000000000..fc75167bd895 --- /dev/null +++ b/test/mach-o/parse-tentative-defs.yaml @@ -0,0 +1,88 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t | FileCheck %s +# +# Test parsing of tentative definitions, including size, scope, and alignment. +# +# +# int tent4; +# long tent8; +# __attribute__((visibility("hidden"))) int tentHidden; +# __attribute__((aligned(16))) int tent4_16; +# __attribute__((aligned(32))) long tent64_32[8]; +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __tex + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS ] + address: 0x0000000000000000 +undefined-symbols: + - name: _tent4 + type: N_UNDF + scope: [ N_EXT ] + desc: 0x0200 + value: 0x0000000000000004 + - name: _tent4_16 + type: N_UNDF + scope: [ N_EXT ] + desc: 0x0400 + value: 0x0000000000000004 + - name: _tent64_32 + type: N_UNDF + scope: [ N_EXT ] + desc: 0x0500 + value: 0x0000000000000040 + - name: _tent8 + type: N_UNDF + scope: [ N_EXT ] + desc: 0x0300 + value: 0x0000000000000008 + - name: _tentHidden + type: N_UNDF + scope: [ N_EXT, N_PEXT ] + desc: 0x0200 + value: 0x0000000000000004 +... + + +# CHECK: defined-atoms: +# CHECK: name: _tent4 +# CHECK: scope: global +# CHECK: type: zero-fill +# CHECK: size: 4 +# CHECK: merge: as-tentative +# CHECK: alignment: 2^2 + +# CHECK: name: _tent4_16 +# CHECK: scope: global +# CHECK: type: zero-fill +# CHECK: size: 4 +# CHECK: merge: as-tentative +# CHECK: alignment: 2^4 + +# CHECK: name: _tent64_32 +# CHECK: scope: global +# CHECK: type: zero-fill +# CHECK: size: 64 +# CHECK: merge: as-tentative +# CHECK: alignment: 2^5 + +# CHECK: name: _tent8 +# CHECK: scope: global +# CHECK: type: zero-fill +# CHECK: size: 8 +# CHECK: merge: as-tentative +# CHECK: alignment: 2^3 + +# CHECK: name: _tentHidden +# CHECK: scope: hidden +# CHECK: type: zero-fill +# CHECK: size: 4 +# CHECK: merge: as-tentative +# CHECK: alignment: 2^2 diff --git a/test/mach-o/parse-text-relocs-arm64.yaml b/test/mach-o/parse-text-relocs-arm64.yaml new file mode 100644 index 000000000000..38a52e7f6f28 --- /dev/null +++ b/test/mach-o/parse-text-relocs-arm64.yaml @@ -0,0 +1,237 @@ +# RUN: lld -flavor darwin -arch arm64 -r -print_atoms %s -o %t | FileCheck %s \ +# RUN: && lld -flavor darwin -arch arm64 -r -print_atoms %t -o %t2 | FileCheck %s +# +# Test parsing and writing of arm64 text relocations. +# +# The first step tests if the supplied mach-o file is parsed into the correct +# set of references. The second step verifies relocations can be round-tripped +# by writing to a new .o file, then parsing that file which should result in +# the same references. +# +#_test: + + +--- !mach-o +arch: arm64 +file-type: MH_OBJECT +flags: [ ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x94, + 0x01, 0x00, 0x00, 0x90, 0x20, 0x00, 0x40, 0x39, + 0x20, 0x00, 0x40, 0x79, 0x20, 0x00, 0x40, 0xB9, + 0x20, 0x00, 0x40, 0xF9, 0x20, 0x00, 0xC0, 0x3D, + 0x01, 0x00, 0x00, 0x90, 0x20, 0x00, 0x40, 0xB9, + 0x01, 0x00, 0x00, 0x90, 0x20, 0x00, 0x40, 0xF9, + 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x40, 0xF9 ] + relocations: + - offset: 0x00000034 + type: ARM64_RELOC_TLVP_LOAD_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 5 + - offset: 0x00000030 + type: ARM64_RELOC_TLVP_LOAD_PAGE21 + length: 2 + pc-rel: true + extern: true + symbol: 5 + - offset: 0x0000002C + type: ARM64_RELOC_GOT_LOAD_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 6 + - offset: 0x00000028 + type: ARM64_RELOC_GOT_LOAD_PAGE21 + length: 2 + pc-rel: true + extern: true + symbol: 6 + - offset: 0x00000024 + type: ARM64_RELOC_ADDEND + length: 2 + pc-rel: false + extern: false + symbol: 16 + - offset: 0x00000024 + type: ARM64_RELOC_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000020 + type: ARM64_RELOC_ADDEND + length: 2 + pc-rel: false + extern: false + symbol: 16 + - offset: 0x00000020 + type: ARM64_RELOC_PAGE21 + length: 2 + pc-rel: true + extern: true + symbol: 2 + - offset: 0x0000001C + type: ARM64_RELOC_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000018 + type: ARM64_RELOC_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000014 + type: ARM64_RELOC_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000010 + type: ARM64_RELOC_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x0000000C + type: ARM64_RELOC_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 2 + - offset: 0x00000008 + type: ARM64_RELOC_PAGE21 + length: 2 + pc-rel: true + extern: true + symbol: 2 + - offset: 0x00000004 + type: ARM64_RELOC_ADDEND + length: 2 + pc-rel: false + extern: false + symbol: 8 + - offset: 0x00000004 + type: ARM64_RELOC_BRANCH26 + length: 2 + pc-rel: true + extern: true + symbol: 4 + - offset: 0x00000000 + type: ARM64_RELOC_BRANCH26 + length: 2 + pc-rel: true + extern: true + symbol: 4 + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x0000000000000038 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] +local-symbols: + - name: ltmp0 + type: N_SECT + sect: 1 + value: 0x0000000000000000 + - name: _func + type: N_SECT + sect: 1 + value: 0x0000000000000000 + - name: _v1 + type: N_SECT + sect: 2 + value: 0x0000000000000038 + - name: ltmp1 + type: N_SECT + sect: 2 + value: 0x0000000000000038 +undefined-symbols: + - name: _foo + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _tlv + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _v2 + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + +# CHECK: defined-atoms: +# CHECK: - name: _v1 +# CHECK: type: data +# CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, +# CHECK: 00, 00, 00, 00 ] +# CHECK: - name: _func +# CHECK: content: [ 00, 00, 00, 94, 00, 00, 00, 94, 01, 00, 00, 90, +# CHECK: 20, 00, 40, 39, 20, 00, 40, 79, 20, 00, 40, B9, +# CHECK: 20, 00, 40, F9, 20, 00, C0, 3D, 01, 00, 00, 90, +# CHECK: 20, 00, 40, B9, 01, 00, 00, 90, 20, 00, 40, F9, +# CHECK: 00, 00, 00, 90, 00, 00, 40, F9 ] +# CHECK: references: +# CHECK: - kind: branch26 +# CHECK: offset: 0 +# CHECK: target: _foo +# CHECK: - kind: branch26 +# CHECK: offset: 4 +# CHECK: target: _foo +# CHECK: addend: 8 +# CHECK: - kind: page21 +# CHECK: offset: 8 +# CHECK: target: _v1 +# CHECK: - kind: offset12 +# CHECK: offset: 12 +# CHECK: target: _v1 +# CHECK: - kind: offset12scale2 +# CHECK: offset: 16 +# CHECK: target: _v1 +# CHECK: - kind: offset12scale4 +# CHECK: offset: 20 +# CHECK: target: _v1 +# CHECK: - kind: offset12scale8 +# CHECK: offset: 24 +# CHECK: target: _v1 +# CHECK: - kind: offset12scale16 +# CHECK: offset: 28 +# CHECK: target: _v1 +# CHECK: - kind: page21 +# CHECK: offset: 32 +# CHECK: target: _v1 +# CHECK: addend: 16 +# CHECK: - kind: offset12scale4 +# CHECK: offset: 36 +# CHECK: target: _v1 +# CHECK: addend: 16 +# CHECK: - kind: gotPage21 +# CHECK: offset: 40 +# CHECK: target: _v2 +# CHECK: - kind: gotOffset12 +# CHECK: offset: 44 +# CHECK: target: _v2 +# CHECK: - kind: tlvPage21 +# CHECK: offset: 48 +# CHECK: target: _tlv +# CHECK: - kind: tlvOffset12 +# CHECK: offset: 52 +# CHECK: target: _tlv +# CHECK: undefined-atoms: +# CHECK: - name: _foo +# CHECK: - name: _tlv +# CHECK: - name: _v2 + diff --git a/test/mach-o/parse-text-relocs-x86_64.yaml b/test/mach-o/parse-text-relocs-x86_64.yaml new file mode 100644 index 000000000000..9e58e02e3771 --- /dev/null +++ b/test/mach-o/parse-text-relocs-x86_64.yaml @@ -0,0 +1,168 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t | FileCheck %s \ +# RUN: && lld -flavor darwin -arch x86_64 -r -print_atoms %t -o %t2 | FileCheck %s +# +# Test parsing and writing of x86_64 text relocations. +# +# The first step tests if the supplied mach-o file is parsed into the correct +# set of references. The second step verifies relocations can be round-tripped +# by writing to a new .o file, then parsing that file which should result in +# the same references. +# +#_test: +# call _foo +# call _foo+4 +# movq _foo@GOTPCREL(%rip), %rax +# pushq _foo@GOTPCREL(%rip) +# movl _foo(%rip), %eax +# movl _foo+4(%rip), %eax +# movb $0x12, _foo(%rip) +# movw $0x1234, _foo(%rip) +# movl $0x12345678, _foo(%rip) +# movl L2(%rip), %eax +# +# .data +#L2: .long 0 + + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xE8, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x04, 0x00, + 0x00, 0x00, 0x48, 0x8B, 0x05, 0x04, 0x00, 0x00, + 0x00, 0xFF, 0x35, 0x04, 0x00, 0x00, 0x00, 0x8B, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x05, 0x04, + 0x00, 0x00, 0x00, 0xC6, 0x05, 0xFF, 0xFF, 0xFF, + 0xFF, 0x12, 0x66, 0xC7, 0x05, 0xFE, 0xFF, 0xFF, + 0xFF, 0x34, 0x12, 0xC7, 0x05, 0xFC, 0xFF, 0xFF, + 0xFF, 0x78, 0x56, 0x34, 0x12, 0x8B, 0x05, 0x00, + 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x0000003F + type: X86_64_RELOC_SIGNED + length: 2 + pc-rel: true + extern: false + symbol: 2 + - offset: 0x00000035 + type: X86_64_RELOC_SIGNED_4 + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x0000002D + type: X86_64_RELOC_SIGNED_2 + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x00000025 + type: X86_64_RELOC_SIGNED_1 + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x0000001F + type: X86_64_RELOC_SIGNED + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x00000019 + type: X86_64_RELOC_SIGNED + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x00000013 + type: X86_64_RELOC_GOT + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x0000000D + type: X86_64_RELOC_GOT_LOAD + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x00000006 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x00000001 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 1 + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + address: 0x0000000000000043 + content: [ 0x00, 0x00, 0x00, 0x00 ] +local-symbols: + - name: _test + type: N_SECT + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _foo + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 +... + +# CHECK: defined-atoms: +# CHECK: - ref-name: [[LABEL:L[0-9]+]] +# CHECK: type: data +# CHECK: content: [ 00, 00, 00, 00 ] +# CHECK: - name: _test +# CHECK: references: +# CHECK: - kind: branch32 +# CHECK: offset: 1 +# CHECK: target: _foo +# CHECK: - kind: branch32 +# CHECK: offset: 6 +# CHECK: target: _foo +# CHECK: addend: 4 +# CHECK: - kind: ripRel32GotLoad +# CHECK: offset: 13 +# CHECK: target: _foo +# CHECK: addend: 4 +# CHECK: - kind: ripRel32Got +# CHECK: offset: 19 +# CHECK: target: _foo +# CHECK: addend: 4 +# CHECK: - kind: ripRel32 +# CHECK: offset: 25 +# CHECK: target: _foo +# CHECK: - kind: ripRel32 +# CHECK: offset: 31 +# CHECK: target: _foo +# CHECK: addend: 4 +# CHECK: - kind: ripRel32Minus1 +# CHECK: offset: 37 +# CHECK: target: _foo +# CHECK-NOT: addend: +# CHECK: - kind: ripRel32Minus2 +# CHECK: offset: 45 +# CHECK: target: _foo +# CHECK-NOT: addend: +# CHECK: - kind: ripRel32Minus4 +# CHECK: offset: 53 +# CHECK: target: _foo +# CHECK-NOT: addend: +# CHECK: - kind: ripRel32Anon +# CHECK: offset: 63 +# CHECK: target: [[LABEL]] +# CHECK-NOT: addend: diff --git a/test/mach-o/re-exported-dylib-ordinal.yaml b/test/mach-o/re-exported-dylib-ordinal.yaml new file mode 100644 index 000000000000..9d628e9af151 --- /dev/null +++ b/test/mach-o/re-exported-dylib-ordinal.yaml @@ -0,0 +1,105 @@ +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -dylib -o %t \ +# RUN: && llvm-nm -m %t | FileCheck %s +# +# Test that when one dylib A re-exports dylib B that using a symbol from B +# gets recorded as coming from A. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x31, 0xC0, 0x5D, 0xE9, + 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000008 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 1 +global-symbols: + - name: _test + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _bar + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +flags: [ MH_TWOLEVEL ] +install-name: /junk/libfoo.dylib +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000F9A + content: [ 0x55, 0x48, 0x89, 0xE5, 0x5D, 0xC3 ] +global-symbols: + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000F9A +dependents: + - path: /junk/libbar.dylib + kind: LC_REEXPORT_DYLIB + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +flags: [ MH_TWOLEVEL ] +install-name: /junk/libbar.dylib +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000F9A + content: [ 0x55, 0x48, 0x89, 0xE5, 0x5D, 0xC3 ] +global-symbols: + - name: _bar + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000F9A + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +flags: [ MH_TWOLEVEL ] +install-name: /usr/lib/libSystem.B.dylib +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55 ] + +global-symbols: + - name: dyld_stub_binder + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + +... + +# CHECK: (undefined) external _bar (from libfoo) +# CHECK: (undefined) external dyld_stub_binder (from libSystem) diff --git a/test/mach-o/rpath.yaml b/test/mach-o/rpath.yaml new file mode 100644 index 000000000000..f0b5f718c15a --- /dev/null +++ b/test/mach-o/rpath.yaml @@ -0,0 +1,38 @@ +# Check we handle -rpath correctly: +# RUN: lld -flavor darwin -arch x86_64 -rpath @loader_path/../Frameworks \ +# RUN: %p/Inputs/libSystem.yaml %s -o %t +# RUN: llvm-objdump -private-headers %t | FileCheck %s --check-prefix=CHECK-BINARY-WRITE + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0xCC, 0xC3, 0x90, 0xC3, 0x90, 0x90, 0xC3, 0x90, + 0x90, 0x90, 0xC3, 0x90, 0x90, 0x90, 0x90, 0xC3, + 0x31, 0xC0, 0xC3 ] +local-symbols: + - name: _myStatic + type: N_SECT + sect: 1 + value: 0x000000000000000B +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000001 +... + + +# CHECK-BINARY-WRITE: cmd LC_RPATH +# CHECK-BINARY-WRITE-NEXT: cmdsize 44 +# CHECK-BINARY-WRITE-NEXT: path @loader_path/../Frameworks (offset 12) diff --git a/test/mach-o/sectalign.yaml b/test/mach-o/sectalign.yaml new file mode 100644 index 000000000000..3556a5ecbcfc --- /dev/null +++ b/test/mach-o/sectalign.yaml @@ -0,0 +1,80 @@ +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -dylib \ +# RUN: -sectalign __DATA __custom 0x800 -sectalign __TEXT __text 0x400 \ +# RUN: %p/Inputs/libSystem.yaml -o %t \ +# RUN: && llvm-readobj -sections %t | FileCheck %s +# +# Test -sectalign option on __text and a custom section. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x8B, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x03, 0x05, 0x00, 0x00, 0x00, 0x00, + 0x5D, 0xC3 ] + relocations: + - offset: 0x0000000C + type: X86_64_RELOC_SIGNED + length: 2 + pc-rel: true + extern: true + symbol: 1 + - offset: 0x00000006 + type: X86_64_RELOC_SIGNED + length: 2 + pc-rel: true + extern: true + symbol: 2 + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x0000000000000014 + content: [ 0x0A, 0x00, 0x00, 0x00 ] + - segment: __DATA + section: __custom + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x0000000000000018 + content: [ 0x0A, 0x00, 0x00, 0x00 ] +global-symbols: + - name: _a + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x0000000000000014 + - name: _b + type: N_SECT + scope: [ N_EXT ] + sect: 3 + value: 0x0000000000000018 + - name: _get + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + +... + + +# CHECK: Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00) +# CHECK: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00) +# CHECK: Address: 0xC00 + +# CHECK: Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00) +# CHECK: Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00) +# CHECK: Address: 0x1000 + +# CHECK: Name: __custom (5F 5F 63 75 73 74 6F 6D 00 00 00 00 00 00 00 00) +# CHECK: Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00) +# CHECK: Address: 0x1800 + diff --git a/test/mach-o/unwind-info-simple-arm64.yaml b/test/mach-o/unwind-info-simple-arm64.yaml new file mode 100644 index 000000000000..d46b43ff712d --- /dev/null +++ b/test/mach-o/unwind-info-simple-arm64.yaml @@ -0,0 +1,280 @@ +# RUN: lld -flavor darwin -arch arm64 %s -o %t -e _main %p/Inputs/libSystem.yaml +# RUN: llvm-objdump -unwind-info %t | FileCheck %s + +--- !mach-o +arch: arm64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 2 + address: 0x0000000000000000 + content: [ 0xFD, 0x7B, 0xBF, 0xA9, 0xFD, 0x03, 0x00, 0x91, + 0xE0, 0x03, 0x1E, 0x32, 0x00, 0x00, 0x00, 0x94, + 0x48, 0x01, 0x80, 0x52, 0x08, 0x00, 0x00, 0xB9, + 0x02, 0x00, 0x80, 0xD2, 0x01, 0x00, 0x00, 0x90, + 0x21, 0x00, 0x40, 0xF9, 0x00, 0x00, 0x00, 0x94, + 0xFD, 0x7B, 0xBF, 0xA9, 0xFD, 0x03, 0x00, 0x91, + 0xE0, 0x03, 0x1E, 0x32, 0x00, 0x00, 0x00, 0x94, + 0x48, 0x01, 0x80, 0x52, 0x08, 0x00, 0x00, 0xB9, + 0x02, 0x00, 0x80, 0xD2, 0x01, 0x00, 0x00, 0x90, + 0x21, 0x00, 0x40, 0xF9, 0x00, 0x00, 0x00, 0x94, + 0x3F, 0x04, 0x00, 0x71, 0x81, 0x00, 0x00, 0x54, + 0x00, 0x00, 0x00, 0x94, 0xFD, 0x7B, 0xC1, 0xA8, + 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x94, + 0xFD, 0x7B, 0xBF, 0xA9, 0xFD, 0x03, 0x00, 0x91, + 0x00, 0x00, 0x00, 0x94 ] + relocations: + - offset: 0x00000070 + type: ARM64_RELOC_BRANCH26 + length: 2 + pc-rel: true + extern: true + symbol: 5 + - offset: 0x00000064 + type: ARM64_RELOC_BRANCH26 + length: 2 + pc-rel: true + extern: true + symbol: 7 + - offset: 0x00000060 + type: ARM64_RELOC_BRANCH26 + length: 2 + pc-rel: true + extern: true + symbol: 12 + - offset: 0x00000058 + type: ARM64_RELOC_BRANCH26 + length: 2 + pc-rel: true + extern: true + symbol: 11 + - offset: 0x0000004C + type: ARM64_RELOC_BRANCH26 + length: 2 + pc-rel: true + extern: true + symbol: 13 + - offset: 0x00000048 + type: ARM64_RELOC_GOT_LOAD_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 8 + - offset: 0x00000044 + type: ARM64_RELOC_GOT_LOAD_PAGE21 + length: 2 + pc-rel: true + extern: true + symbol: 8 + - offset: 0x00000034 + type: ARM64_RELOC_BRANCH26 + length: 2 + pc-rel: true + extern: true + symbol: 10 + - offset: 0x00000024 + type: ARM64_RELOC_BRANCH26 + length: 2 + pc-rel: true + extern: true + symbol: 13 + - offset: 0x00000020 + type: ARM64_RELOC_GOT_LOAD_PAGEOFF12 + length: 2 + pc-rel: false + extern: true + symbol: 8 + - offset: 0x0000001C + type: ARM64_RELOC_GOT_LOAD_PAGE21 + length: 2 + pc-rel: true + extern: true + symbol: 8 + - offset: 0x0000000C + type: ARM64_RELOC_BRANCH26 + length: 2 + pc-rel: true + extern: true + symbol: 10 + - segment: __TEXT + section: __gcc_except_tab + type: S_REGULAR + attributes: [ ] + alignment: 2 + address: 0x0000000000000074 + content: [ 0xFF, 0x9B, 0xAF, 0x80, 0x00, 0x03, 0x27, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x01, 0x28, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0xD0, 0xFF, 0xFF, 0xFF ] + relocations: + - offset: 0x00000030 + type: ARM64_RELOC_POINTER_TO_GOT + length: 2 + pc-rel: true + extern: true + symbol: 9 + - segment: __LD + section: __compact_unwind + type: S_REGULAR + attributes: [ ] + alignment: 3 + address: 0x00000000000000A8 + content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000040 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000038 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: false + symbol: 2 + - offset: 0x00000030 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: true + symbol: 14 + - offset: 0x00000020 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: false + symbol: 1 + - offset: 0x00000000 + type: ARM64_RELOC_UNSIGNED + length: 3 + pc-rel: false + extern: false + symbol: 1 +local-symbols: + - name: ltmp0 + type: N_SECT + sect: 1 + value: 0x0000000000000000 + - name: ltmp14 + type: N_SECT + sect: 2 + value: 0x0000000000000074 + - name: GCC_except_table1 + type: N_SECT + sect: 2 + value: 0x0000000000000074 + - name: ltmp21 + type: N_SECT + sect: 3 + value: 0x00000000000000A8 +global-symbols: + - name: __Z3barv + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000028 + - name: __Z3foov + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000068 +undefined-symbols: + - name: __Unwind_Resume + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: __ZTIi + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: __ZTIl + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: ___cxa_allocate_exception + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: ___cxa_begin_catch + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: ___cxa_end_catch + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: ___cxa_throw + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: ___gxx_personality_v0 + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +--- !mach-o +arch: arm64 +file-type: MH_DYLIB +install-name: /usr/lib/libc++.dylib +exports: + - name: __Unwind_Resume + - name: __ZTIl + - name: __ZTIi + - name: ___cxa_end_catch + - name: ___cxa_begin_catch + - name: ___cxa_allocate_exception + - name: ___cxa_throw + - name: ___gxx_personality_v0 + +... + + +# CHECK: Contents of __unwind_info section: +# CHECK: Version: 0x1 +# CHECK: Common encodings array section offset: 0x1c +# CHECK: Number of common encodings in array: 0x0 +# CHECK: Personality function array section offset: 0x1c +# CHECK: Number of personality functions in array: 0x1 +# CHECK: Index array section offset: 0x20 +# CHECK: Number of indices in array: 0x2 +# CHECK: Common encodings: (count = 0) +# CHECK: Personality functions: (count = 1) +# CHECK: personality[1]: 0x00004018 +# CHECK: Top level indices: (count = 2) +# CHECK: [0]: function offset=0x00003e68, 2nd level page offset=0x00000040, LSDA offset=0x00000038 +# CHECK: [1]: function offset=0x00003edc, 2nd level page offset=0x00000000, LSDA offset=0x00000040 +# CHECK: LSDA descriptors: +# CHECK: [0]: function offset=0x00003e90, LSDA offset=0x00003f6c +# CHECK: Second level indices: +# CHECK: Second level index[0]: offset in section=0x00000040, base function offset=0x00003e68 +# CHECK: [0]: function offset=0x00003e68, encoding=0x04000000 +# CHECK: [1]: function offset=0x00003e90, encoding=0x54000000 +# CHECK: [2]: function offset=0x00003ed0, encoding=0x04000000 +# CHECK-NOT: Contents of __compact_unwind section + + + diff --git a/test/mach-o/unwind-info-simple-x86_64.yaml b/test/mach-o/unwind-info-simple-x86_64.yaml new file mode 100644 index 000000000000..8886e5271661 --- /dev/null +++ b/test/mach-o/unwind-info-simple-x86_64.yaml @@ -0,0 +1,118 @@ +# RUN: lld -flavor darwin -arch x86_64 %s -o %t -e _main %p/Inputs/libSystem.yaml +# RUN: llvm-objdump -unwind-info %t | FileCheck %s + +# CHECK: Contents of __unwind_info section: +# CHECK: Version: 0x1 +# CHECK: Common encodings array section offset: 0x1c +# CHECK: Number of common encodings in array: 0x0 +# CHECK: Personality function array section offset: 0x1c +# CHECK: Number of personality functions in array: 0x1 +# CHECK: Index array section offset: 0x20 +# CHECK: Number of indices in array: 0x2 +# CHECK: Common encodings: (count = 0) +# CHECK: Personality functions: (count = 1) +# CHECK: personality[1]: 0x00001000 +# CHECK: Top level indices: (count = 2) +# CHECK: [0]: function offset=0x00000efb, 2nd level page offset=0x00000040, LSDA offset=0x00000038 +# CHECK: [1]: function offset=0x00000f00, 2nd level page offset=0x00000000, LSDA offset=0x00000040 +# CHECK: LSDA descriptors: +# CHECK: [0]: function offset=0x00000efb, LSDA offset=0x00000f00 +# CHECK: Second level indices: +# CHECK: Second level index[0]: offset in section=0x00000040, base function offset=0x00000efb +# CHECK: [0]: function offset=0x00000efb, encoding=0x51000000 +# CHECK: [1]: function offset=0x00000efc, encoding=0x01000000 +# CHECK: [2]: function offset=0x00000efd, encoding=0x04000018 +# CHECK: [3]: function offset=0x00000efe, encoding=0x04000040 +# CHECK: [4]: function offset=0x00000eff, encoding=0x00000000 +# CHECK-NOT: Contents of __compact_unwind section + +--- !native +path: '<linker-internal>' +defined-atoms: + - name: GCC_except_table1 + type: unwind-lsda + content: [ FF, 9B, A2, 80, 80, 00, 03, 1A, 08, 00, 00, 00, + 05, 00, 00, 00, 1A, 00, 00, 00, 01, 0D, 00, 00, + 00, 64, 00, 00, 00, 00, 00, 00, 00, 00, 01, 00, + 04, 00, 00, 00 ] + - type: compact-unwind + content: [ 40, 00, 00, 00, 00, 00, 00, 00, 01, 00, 00, 00, + 00, 00, 00, 41, 00, 00, 00, 00, 00, 00, 00, 00, + E0, 00, 00, 00, 00, 00, 00, 00 ] + references: + - kind: pointer64Anon + offset: 0 + target: __Z3barv + - kind: pointer64 + offset: 16 + target: ___gxx_personality_v0 + - kind: pointer64Anon + offset: 24 + target: GCC_except_table1 + - type: compact-unwind + content: [ C0, 00, 00, 00, 00, 00, 00, 00, 01, 00, 00, 00, + 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, 00, + 00, 00, 00, 00, 00, 00, 00, 00 ] + references: + - kind: pointer64Anon + offset: 0 + target: _main + - type: compact-unwind + content: [ C1, 00, 00, 00, 00, 00, 00, 00, 01, 00, 00, 00, + 00, 00, 00, 04, 00, 00, 00, 00, 00, 00, 00, 00, + 00, 00, 00, 00, 00, 00, 00, 00 ] + references: + - kind: pointer64Anon + offset: 0 + target: _needsDwarfButNoCompactUnwind + +# Generic x86_64 CIE: + - type: unwind-cfi + content: [ 14, 00, 00, 00, 00, 00, 00, 00, 01, 7A, 52, 00, + 01, 78, 10, 01, 10, 0C, 07, 08, 90, 01, 00, 00 ] + + - type: unwind-cfi + content: [ 24, 00, 00, 00, 1C, 00, 00, 00, C8, FE, FF, FF, + FF, FF, FF, FF, 01, 00, 00, 00, 00, 00, 00, 00, + 00, 41, 0E, 10, 86, 02, 43, 0D, 06, 00, 00, 00, + 00, 00, 00, 00 ] + references: + - kind: unwindFDEToFunction + offset: 8 + target: _needsDwarfButNoCompactUnwind + + - type: unwind-cfi + content: [ 24, 00, 00, 00, 44, 00, 00, 00, C8, FE, FF, FF, + FF, FF, FF, FF, 01, 00, 00, 00, 00, 00, 00, 00, + 00, 41, 0E, 10, 86, 02, 43, 0D, 06, 00, 00, 00, + 00, 00, 00, 00 ] + references: + - kind: unwindFDEToFunction + offset: 8 + target: _needsDwarfSaysCompactUnwind + + + - name: __Z3barv + scope: global + content: [ C3 ] + - name: _main + scope: global + content: [ C3 ] + references: + - kind: branch32 + offset: 9 + target: __Z3barv + - name: _needsDwarfButNoCompactUnwind + scope: global + content: [ C3 ] + - name: _needsDwarfSaysCompactUnwind + scope: global + content: [ C3 ] + - name: _noUnwindData + scope: global + content: [ C3 ] + +shared-library-atoms: + - name: ___gxx_personality_v0 + load-name: '/usr/lib/libc++abi.dylib' + type: unknown diff --git a/test/mach-o/upward-dylib-load-command.yaml b/test/mach-o/upward-dylib-load-command.yaml new file mode 100644 index 000000000000..fee3e41d5bd5 --- /dev/null +++ b/test/mach-o/upward-dylib-load-command.yaml @@ -0,0 +1,48 @@ +# RUN: lld -flavor darwin -arch x86_64 -dylib %p/Inputs/bar.yaml \ +# RUN: -install_name /usr/lib/libbar.dylib %p/Inputs/libSystem.yaml -o %t1.dylib +# RUN: lld -flavor darwin -arch x86_64 -dylib %s -upward_library %t1.dylib \ +# RUN: -install_name /usr/lib/libfoo.dylib %p/Inputs/libSystem.yaml -o %t +# RUN: llvm-objdump -private-headers %t | FileCheck %s +# +# +# Test upward linking: 1) build libbar.dylib, 2) build libfoo.dylib and upward +# like with libbar.dylib, 3) dump load commands of libfoo and verify upward link. +# + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0x31, 0xC0, 0x5D, 0xE9, + 0x00, 0x00, 0x00, 0x00 ] + relocations: + - offset: 0x00000008 + type: X86_64_RELOC_BRANCH + length: 2 + pc-rel: true + extern: true + symbol: 1 +global-symbols: + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _bar + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +... + + +# CHECK: cmd LC_LOAD_UPWARD_DYLIB +# CHECK-NEXT: cmdsize 48 +# CHECK-NEXT: name /usr/lib/libbar.dylib (offset 24) diff --git a/test/mach-o/upward-dylib-paths.yaml b/test/mach-o/upward-dylib-paths.yaml new file mode 100644 index 000000000000..53ff9fa2298c --- /dev/null +++ b/test/mach-o/upward-dylib-paths.yaml @@ -0,0 +1,18 @@ +# +# +# RUN: lld -flavor darwin -arch x86_64 -r -test_file_usage -v \ +# RUN: -path_exists /Custom/Frameworks \ +# RUN: -path_exists /Custom/Frameworks/Bar.framework/Bar \ +# RUN: -path_exists /usr/lib \ +# RUN: -path_exists /usr/lib/libfoo.dylib \ +# RUN: -path_exists /opt/stuff/libstuff.dylib \ +# RUN: -F/Custom/Frameworks \ +# RUN: -upward_framework Bar \ +# RUN: -upward-lfoo \ +# RUN: -upward_library /opt/stuff/libstuff.dylib \ +# RUN: 2>&1 | FileCheck %s + +# CHECK: Found upward framework /Custom/Frameworks/Bar.framework/Bar +# CHECK: Found upward library /usr/lib/libfoo.dylib + + diff --git a/test/mach-o/usage.yaml b/test/mach-o/usage.yaml new file mode 100644 index 000000000000..20a506284c96 --- /dev/null +++ b/test/mach-o/usage.yaml @@ -0,0 +1,8 @@ +# RUN: not lld -flavor darwin | FileCheck %s +# +# Test that running darwin linker with no option prints out usage message. +# + + +# CHECK: USAGE: +# CHECK: -arch diff --git a/test/mach-o/use-simple-dylib.yaml b/test/mach-o/use-simple-dylib.yaml new file mode 100644 index 000000000000..0da7d1b0bd05 --- /dev/null +++ b/test/mach-o/use-simple-dylib.yaml @@ -0,0 +1,131 @@ +# RUN: lld -flavor darwin -arch x86_64 -print_atoms -r %s -o %t | FileCheck %s + + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55, 0x48, 0x89, 0xE5, 0xE8, 0x00, 0x00, 0x00, + 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x00, + 0x00, 0x00, 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00, + 0xE8, 0x00, 0x00, 0x00, 0x00, 0x5D, 0xE9, 0x00, + 0x00, 0x00, 0x00 ] +global-symbols: + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +undefined-symbols: + - name: _myGlobal + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _myGlobalWeak + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _myHidden + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _myHiddenWeak + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _myResolver + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _myStatic + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + - name: _myVariablePreviouslyKnownAsPrivateExtern + type: N_UNDF + scope: [ N_EXT ] + value: 0x0000000000000000 + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0xCC, 0xC3, 0x90, 0xC3, 0x90, 0x90, 0xC3, 0x90, + 0x90, 0x90, 0xC3, 0x90, 0x90, 0x90, 0x90, 0xC3, + 0x31, 0xC0, 0xC3 ] +local-symbols: + - name: _myStatic + type: N_SECT + sect: 1 + value: 0x000000000000000B + - name: _myVariablePreviouslyKnownAsPrivateExtern + type: N_SECT + scope: [ N_PEXT ] + sect: 1 + desc: [ N_SYMBOL_RESOLVER ] + value: 0x0000000000000011 +global-symbols: + - name: _myGlobal + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000001 + - name: _myGlobalWeak + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_WEAK_DEF ] + value: 0x0000000000000002 + - name: _myHidden + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 1 + value: 0x0000000000000004 + - name: _myHiddenWeak + type: N_SECT + scope: [ N_EXT, N_PEXT ] + sect: 1 + desc: [ N_WEAK_DEF ] + value: 0x0000000000000007 + - name: _myResolver + type: N_SECT + scope: [ N_EXT ] + sect: 1 + desc: [ N_SYMBOL_RESOLVER ] + value: 0x0000000000000010 + +install-name: libspecial.dylib +... + + +# CHECK: undefined-atoms: +# CHECK: - name: _myStatic +# CHECK: - name: _myVariablePreviouslyKnownAsPrivateExtern +# CHECK: shared-library-atoms: +# CHECK: - name: _myGlobal +# CHECK: load-name: libspecial.dylib +# CHECK: - name: _myGlobalWeak +# CHECK: load-name: libspecial.dylib +# CHECK: - name: _myHidden +# CHECK: load-name: libspecial.dylib +# CHECK: - name: _myHiddenWeak +# CHECK: load-name: libspecial.dylib +# CHECK: - name: _myResolver +# CHECK: load-name: libspecial.dylib diff --git a/test/mach-o/write-final-sections.yaml b/test/mach-o/write-final-sections.yaml new file mode 100644 index 000000000000..7d4afb31900a --- /dev/null +++ b/test/mach-o/write-final-sections.yaml @@ -0,0 +1,167 @@ +# RUN: lld -flavor darwin -arch x86_64 %s -o %t -e _foo +# RUN: llvm-readobj -sections -section-data %t | FileCheck %s + +--- !native +defined-atoms: +# For __TEXT, __text (with typeCode) + - name: _foo + scope: global + content: [ 55 ] +# CHECK: Name: __text +# CHECK: Segment: __TEXT +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 55 +# CHECK-NEXT: ) + +# For __TEXT, __const (with typeConstant), + - type: constant + content: [ 01, 00, 00, 00 ] +# From __TEXT, __literal4, (with typeLiteral4) + - scope: hidden + type: const-4-byte + content: [ 02, 00, 00, 00 ] +# From __TEXT, __literal8, (with typeLiteral8) + - scope: hidden + type: const-8-byte + content: [ 03, 00, 00, 00, 00, 00, 00, 00 ] +# From __TEXT, __literal16, (with typeLiteral16) + - scope: hidden + type: const-16-byte + content: [ 04, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: Name: __const +# CHECK: Segment: __TEXT +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 01000000 02000000 03000000 00000000 +# CHECK-NEXT: 0010: 04000000 00000000 00000000 00000000 +# CHECK-NEXT: ) + +# For __TEXT, __cstring (with typeCString) + - scope: hidden + type: c-string + content: [ 57, 69, 62, 62, 6C, 65, 00 ] + merge: by-content +# CHECK: Name: __cstring +# CHECK: Segment: __TEXT +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 57696262 6C6500 +# CHECK-NEXT: ) + +# For __TEXT, __ustring (with typeUTF16String) + - scope: hidden + type: utf16-string + content: [ 05, 00 ] + merge: by-content +# CHECK: Name: __ustring +# CHECK: Segment: __TEXT +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 0500 +# CHECK-NEXT: ) + +# For __TEXT, __gcc_except_tab, (with typeLSDA) + - name: GCC_except_table0 + type: unwind-lsda + content: [ 06, 00 ] +# CHECK: Name: __gcc_except_tab +# CHECK: Segment: __TEXT +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 0600 +# CHECK-NEXT: ) + +# For __TEXT, __eh_frame, (with typeCFI) + - type: unwind-cfi + content: [ 07 ] +# CHECK: Name: __eh_frame +# CHECK: Segment: __TEXT +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 07 +# CHECK-NEXT: ) + +# For __DATA, __data, (with typeData) + - name: var + type: data + content: [ 08 ] +# CHECK: Name: __data +# CHECK: Segment: __DATA +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 08 +# CHECK-NEXT: ) + +# For __DATA, __bss (with typeZeroFill) +# FIXME: Attributes & tags of __bss are mostly broken. Should be at end of +# __DATA, should have size, should have S_ZEROFILL flag. + - type: zero-fill + size: 8 +# CHECK: Name: __bss +# CHECK: Segment: __DATA + +# For __DATA, __const, (with typeConstData) + - type: const-data + content: [ 09, 00, 00, 00 ] +# CHECK: Name: __const +# CHECK: Segment: __DATA +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 09000000 +# CHECK-NEXT: ) + +# For __DATA, __cfstring, (with typeCFString) + - type: cfstring + content: [ 0A, 00 ] +# CHECK: Name: __cfstring +# CHECK: Segment: __DATA +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 0A00 +# CHECK-NEXT: ) + +# For __DATA, __got (with typeGOT) + - type: got + content: [ 0B, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: Name: __got +# CHECK: Segment: __DATA +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 0B000000 00000000 +# CHECK-NEXT: ) + + +# For __DATA, __mod_init_func (with typeInitializerPtr) + - type: initializer-pointer + content: [ 0C, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: Name: __mod_init_func +# CHECK: Segment: __DATA +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 0C000000 00000000 +# CHECK-NEXT: ) + +# For __DATA, __mod_term_func (with typeTerminatorPointer) + - type: terminator-pointer + content: [ 0D, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK: Name: __mod_term_func +# CHECK: Segment: __DATA +# CHECK: SectionData ( +# CHECK-NEXT: 0000: 0D000000 00000000 +# CHECK-NEXT: ) + + - type: compact-unwind + content: [ 0E, 00, 00, 00, 00, 00, 00, 00 ] +# CHECK-NOT: Name: __compact_unwind + + +--- !mach-o +arch: x86_64 +file-type: MH_DYLIB +flags: [ ] +install-name: /usr/lib/libSystem.B.dylib +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0x55 ] + +global-symbols: + - name: dyld_stub_binder + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + diff --git a/test/mach-o/wrong-arch-error.yaml b/test/mach-o/wrong-arch-error.yaml new file mode 100644 index 000000000000..6d233798a7b6 --- /dev/null +++ b/test/mach-o/wrong-arch-error.yaml @@ -0,0 +1,49 @@ +# RUN: not lld -flavor darwin -arch x86_64 -r %s 2> %t.err +# RUN: FileCheck %s < %t.err + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xCC ] + +global-symbols: + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 + +--- !mach-o +arch: x86 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + alignment: 4 + address: 0x0000000000000000 + content: [ 0xC3 ] + +global-symbols: + - name: _bar + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +... + + +# CHECK: wrong architecture diff --git a/test/pecoff/Inputs/abs.obj.yaml b/test/pecoff/Inputs/abs.obj.yaml new file mode 100644 index 000000000000..65c3901ad8e7 --- /dev/null +++ b/test/pecoff/Inputs/abs.obj.yaml @@ -0,0 +1,11 @@ +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [] +sections: +symbols: + - Name: _abs_value + Value: 0xDEADBEEF + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL diff --git a/test/pecoff/Inputs/alignment.obj.yaml b/test/pecoff/Inputs/alignment.obj.yaml new file mode 100644 index 000000000000..1b12da0e6bad --- /dev/null +++ b/test/pecoff/Inputs/alignment.obj.yaml @@ -0,0 +1,103 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 256 + SectionData: CC + - Name: .text$1 + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4096 + SectionData: 00 + - Name: .data$1 + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 00 + - Name: .data$2 + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 11 + - Name: .data$3 + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 0 + SectionData: 22 + - Name: .bss$1 + Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 16 + SectionData: 0000 + - Name: .bss$2 + Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 16 + SectionData: 0000 + - Name: .yyy + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4096 + SectionData: 0000 + - Name: .zzz + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 16384 + SectionData: 0000 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .text$1 + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .data$1 + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .data$2 + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .data$3 + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: _start + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .bss$1 + Value: 0 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .bss$2 + Value: 0 + SectionNumber: 7 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .foo + Value: 0 + SectionNumber: 8 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .bar + Value: 0 + SectionNumber: 9 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC +... diff --git a/test/pecoff/Inputs/alternatename1.obj.yaml b/test/pecoff/Inputs/alternatename1.obj.yaml new file mode 100644 index 000000000000..dac18a8ef595 --- /dev/null +++ b/test/pecoff/Inputs/alternatename1.obj.yaml @@ -0,0 +1,23 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 90909090 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: _foo + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/alternatename2.obj.yaml b/test/pecoff/Inputs/alternatename2.obj.yaml new file mode 100644 index 000000000000..5b70bfced6a1 --- /dev/null +++ b/test/pecoff/Inputs/alternatename2.obj.yaml @@ -0,0 +1,23 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: CCCCCCCC +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/alternatename3.obj.yaml b/test/pecoff/Inputs/alternatename3.obj.yaml new file mode 100644 index 000000000000..1865653ea668 --- /dev/null +++ b/test/pecoff/Inputs/alternatename3.obj.yaml @@ -0,0 +1,39 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 90909090 + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 2147483648 + SectionData: 2F616C7465726E6174656E616D653A5F6D61696E3D5F666F6F00 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: _foo + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .drectve + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 13 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 +... diff --git a/test/pecoff/Inputs/armnt-ImageBase.obj.yaml b/test/pecoff/Inputs/armnt-ImageBase.obj.yaml new file mode 100644 index 000000000000..69cd530253b0 --- /dev/null +++ b/test/pecoff/Inputs/armnt-ImageBase.obj.yaml @@ -0,0 +1,39 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 7047FEDE00000000 + Relocations: + - VirtualAddress: 4 + SymbolName: __ImageBase + Type: 1 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 8 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: mainCRTStartup + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __ImageBase + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/armnt-ImageBase.s b/test/pecoff/Inputs/armnt-ImageBase.s new file mode 100644 index 000000000000..a17458eddb15 --- /dev/null +++ b/test/pecoff/Inputs/armnt-ImageBase.s @@ -0,0 +1,16 @@ + + .syntax unified + .thumb + .text + + .def mainCRTStartup + .type 32 + .scl 2 + .endef + .align 2 + .thumb_func +mainCRTStartup: + bx lr + trap + .long __ImageBase + diff --git a/test/pecoff/Inputs/armnt-addr32-exec.obj.yaml b/test/pecoff/Inputs/armnt-addr32-exec.obj.yaml new file mode 100644 index 000000000000..b550f58c03e6 --- /dev/null +++ b/test/pecoff/Inputs/armnt-addr32-exec.obj.yaml @@ -0,0 +1,55 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: '7047' + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: '00000000' + Relocations: + - VirtualAddress: 0 + SymbolName: function + Type: 1 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 2 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: .rdata + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 2 + - Name: function + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: fps + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/armnt-addr32-exec.s b/test/pecoff/Inputs/armnt-addr32-exec.s new file mode 100644 index 000000000000..6a0776de7dd3 --- /dev/null +++ b/test/pecoff/Inputs/armnt-addr32-exec.s @@ -0,0 +1,24 @@ + +# __declspec(dllexport) void function(void) { } +# const void * const fps[] = { &function, }; + + .syntax unified + .thumb + .text + + .def function + .scl 2 + .type 32 + .endef + .global function + .align 2 + .thumb_func +function: + bx lr + + .section .rdata,"rd" + .global fps + .align 2 +fps: + .long function + diff --git a/test/pecoff/Inputs/armnt-addr32.obj.yaml b/test/pecoff/Inputs/armnt-addr32.obj.yaml new file mode 100644 index 000000000000..62ae2c6ea992 --- /dev/null +++ b/test/pecoff/Inputs/armnt-addr32.obj.yaml @@ -0,0 +1,39 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [ ] +sections: + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: '0000000000000000' + Relocations: + - VirtualAddress: 0 + SymbolName: i + Type: 1 +symbols: + - Name: .rdata + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 8 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: i + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: is + Value: 4 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/armnt-addr32.s b/test/pecoff/Inputs/armnt-addr32.s new file mode 100644 index 000000000000..c718e9518af9 --- /dev/null +++ b/test/pecoff/Inputs/armnt-addr32.s @@ -0,0 +1,18 @@ + +@ static const int i = 0; +@ const int * const is[] = { &i, }; + + .syntax unified + .thumb + .text + + .section .rdata,"rd" + .align 2 # @i +i: + .long 0 # 0x0 + + .global is # @is + .align 2 +is: + .long i + diff --git a/test/pecoff/Inputs/armnt-blx23t.obj.yaml b/test/pecoff/Inputs/armnt-blx23t.obj.yaml new file mode 100644 index 000000000000..03f82609f4e6 --- /dev/null +++ b/test/pecoff/Inputs/armnt-blx23t.obj.yaml @@ -0,0 +1,39 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 704700BF2DE90048EB46202000F000F80130BDE80088 + Relocations: + - VirtualAddress: 12 + SymbolName: identity + Type: 21 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 22 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: identity + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: function + Value: 4 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/armnt-blx23t.s b/test/pecoff/Inputs/armnt-blx23t.s new file mode 100644 index 000000000000..89aa4194faae --- /dev/null +++ b/test/pecoff/Inputs/armnt-blx23t.s @@ -0,0 +1,33 @@ + +# __declspec(noinline) int identity(int i) { return i; } +# int function() { return identity(32) + 1; } + + .syntax unified + .thumb + .text + + .def identity + .scl 2 + .type 32 + .endef + .global identity + .align 2 + .thumb_func +identity: + bx lr + + .def function + .scl 2 + .type 32 + .endef + .global function + .align 2 + .thumb_func +function: + push.w {r11, lr} + mov r11, sp + movs r0, 32 + bl identity + adds r0, 1 + pop.w {r11, pc} + diff --git a/test/pecoff/Inputs/armnt-branch24t.obj.yaml b/test/pecoff/Inputs/armnt-branch24t.obj.yaml new file mode 100644 index 000000000000..02815a4957dd --- /dev/null +++ b/test/pecoff/Inputs/armnt-branch24t.obj.yaml @@ -0,0 +1,39 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 704700BF202000F000B8 + Relocations: + - VirtualAddress: 6 + SymbolName: identity + Type: 20 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 10 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: identity + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: function + Value: 4 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/armnt-branch24t.s b/test/pecoff/Inputs/armnt-branch24t.s new file mode 100644 index 000000000000..8d85cbe0cab2 --- /dev/null +++ b/test/pecoff/Inputs/armnt-branch24t.s @@ -0,0 +1,26 @@ + +# int ___declspec(noinline) identity(int i) { return i; } +# int function(void) { return identity(32); } + + .syntax unified + .thumb + .text + + .def identity + .scl 2 + .type 32 + .endef + .global identity + .align 2 + .thumb_func +identity: + bx lr + + .def function + .scl 2 + .type 32 + .endef +function: + movs r0, 32 + b identity + diff --git a/test/pecoff/Inputs/armnt-exports.def b/test/pecoff/Inputs/armnt-exports.def new file mode 100644 index 000000000000..afb8258f95bc --- /dev/null +++ b/test/pecoff/Inputs/armnt-exports.def @@ -0,0 +1,4 @@ +LIBRARY "armnt-exports" +EXPORTS + function + diff --git a/test/pecoff/Inputs/armnt-exports.obj.yaml b/test/pecoff/Inputs/armnt-exports.obj.yaml new file mode 100644 index 000000000000..2a971db2fdaa --- /dev/null +++ b/test/pecoff/Inputs/armnt-exports.obj.yaml @@ -0,0 +1,35 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 704700BF7047 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 6 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: function + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _DllMainCRTStartup + Value: 4 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/armnt-import.obj.yaml b/test/pecoff/Inputs/armnt-import.obj.yaml new file mode 100644 index 000000000000..08876eeb0d4c --- /dev/null +++ b/test/pecoff/Inputs/armnt-import.obj.yaml @@ -0,0 +1,39 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 40F20000C0F2000000680047 + Relocations: + - VirtualAddress: 0 + SymbolName: __imp_function + Type: 17 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 12 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: mainCRTStartup + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp_function + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/armnt-import.s b/test/pecoff/Inputs/armnt-import.s new file mode 100644 index 000000000000..2790d0edc8d9 --- /dev/null +++ b/test/pecoff/Inputs/armnt-import.s @@ -0,0 +1,21 @@ + +# void __declspec(dllimport) function(void); +# int mainCRTStartup(void) { return function(); } + + .syntax unified + .thumb + .text + + .def mainCRTStartup + .scl 2 + .type 32 + .endef + .global mainCRTStartup + .align 2 + .thumb_func +mainCRTStartup: + movw r0, :lower16:__imp_function + movt r0, :upper16:__imp_function + ldr r0, [r0] + bx r0 + diff --git a/test/pecoff/Inputs/armnt-mov32t-exec.obj.yaml b/test/pecoff/Inputs/armnt-mov32t-exec.obj.yaml new file mode 100644 index 000000000000..a4630bcb9e0e --- /dev/null +++ b/test/pecoff/Inputs/armnt-mov32t-exec.obj.yaml @@ -0,0 +1,39 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 704700BF40F20000C0F200007047 + Relocations: + - VirtualAddress: 4 + SymbolName: function + Type: 17 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 14 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: function + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: get_function + Value: 4 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/armnt-mov32t-exec.s b/test/pecoff/Inputs/armnt-mov32t-exec.s new file mode 100644 index 000000000000..10a20f468c34 --- /dev/null +++ b/test/pecoff/Inputs/armnt-mov32t-exec.s @@ -0,0 +1,30 @@ + +# void function(void) { } +# void *get_function() { return &function; } + + .syntax unified + .thumb + .text + + .def function + .scl 2 + .type 32 + .endef + .global function + .align 2 + .thumb_func +function: + bx lr + + .def get_function + .scl 2 + .type 32 + .endef + .global get_function + .align 2 + .thumb_func +get_function: + movw r0, :lower16:function + movt r0, :upper16:function + bx lr + diff --git a/test/pecoff/Inputs/armnt-mov32t.obj.yaml b/test/pecoff/Inputs/armnt-mov32t.obj.yaml new file mode 100644 index 000000000000..21e890ace28f --- /dev/null +++ b/test/pecoff/Inputs/armnt-mov32t.obj.yaml @@ -0,0 +1,55 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 40F20000C0F200007047 + Relocations: + - VirtualAddress: 0 + SymbolName: buffer + Type: 17 + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: '62756666657200' +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 10 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: .rdata + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 7 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 2 + - Name: get_buffer + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: buffer + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC +... diff --git a/test/pecoff/Inputs/armnt-mov32t.s b/test/pecoff/Inputs/armnt-mov32t.s new file mode 100644 index 000000000000..289f917597d6 --- /dev/null +++ b/test/pecoff/Inputs/armnt-mov32t.s @@ -0,0 +1,24 @@ + +# static const char buffer[] = "buffer"; +# const char *get_buffer() { return buffer; } + + .syntax unified + .thumb + .text + + .def get_buffer + .scl 2 + .type 32 + .endef + .global get_buffer + .align 2 + .thumb_func +get_buffer: + movw r0, :lower16:buffer + movt r0, :upper16:buffer + bx lr + + .section .rdata,"rd" +buffer: + .asciz "buffer" + diff --git a/test/pecoff/Inputs/armnt-obj.s b/test/pecoff/Inputs/armnt-obj.s new file mode 100644 index 000000000000..20eeab0e1dda --- /dev/null +++ b/test/pecoff/Inputs/armnt-obj.s @@ -0,0 +1,12 @@ + + .syntax unified + .thumb + .text + + .def main + .scl 2 + .type 32 + .endef +main: + bx lr + diff --git a/test/pecoff/Inputs/armnt-obj.yaml b/test/pecoff/Inputs/armnt-obj.yaml new file mode 100644 index 000000000000..7c53c6f00693 --- /dev/null +++ b/test/pecoff/Inputs/armnt-obj.yaml @@ -0,0 +1,29 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: '7047' +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 2 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/associative1.obj.yaml b/test/pecoff/Inputs/associative1.obj.yaml new file mode 100644 index 000000000000..51a7be0b34d7 --- /dev/null +++ b/test/pecoff/Inputs/associative1.obj.yaml @@ -0,0 +1,53 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [] +sections: + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 00000000 + - Name: '.CRT$XCU' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 77777777 +symbols: + - Name: .data + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: _var + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '.CRT$XCU' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + Selection: IMAGE_COMDAT_SELECT_ASSOCIATIVE + - Name: _init + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/associative3.obj.yaml b/test/pecoff/Inputs/associative3.obj.yaml new file mode 100644 index 000000000000..ffea761a357c --- /dev/null +++ b/test/pecoff/Inputs/associative3.obj.yaml @@ -0,0 +1,33 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 0000000000000000 + Relocations: + - VirtualAddress: 4 + SymbolName: _var + Type: IMAGE_REL_I386_DIR32 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _var + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/basereloc.obj.yaml b/test/pecoff/Inputs/basereloc.obj.yaml new file mode 100644 index 000000000000..5e5ca16a0ac7 --- /dev/null +++ b/test/pecoff/Inputs/basereloc.obj.yaml @@ -0,0 +1,164 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4096 + SectionData: B800000000506800000000680000000050E80000000050E80000000050E800000000 + Relocations: + - VirtualAddress: 0 + SymbolName: abs_symbol + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 7 + SymbolName: caption + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 12 + SymbolName: message + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 18 + SymbolName: _MessageBoxA@16 + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 24 + SymbolName: _ExitProcess@4 + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 30 + SymbolName: ___ImageBase + Type: IMAGE_REL_I386_DIR32 + - Name: .text2 + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4096 + SectionData: B800000000506800000000680000000050E80000000050E80000000050E800000000 + Relocations: + - VirtualAddress: 0 + SymbolName: abs_symbol + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 7 + SymbolName: caption + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 12 + SymbolName: message + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 18 + SymbolName: _MessageBoxA@16 + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 24 + SymbolName: _ExitProcess@4 + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 30 + SymbolName: ___ImageBase + Type: IMAGE_REL_I386_DIR32 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 48656C6C6F0048656C6C6F20576F726C6400 + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 2147483648 + SectionData: 2F454E5452593A6D61696E20 +symbols: + - Name: "@comp.id" + Value: 10394907 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 28 + NumberOfRelocations: 6 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .text2 + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 28 + NumberOfRelocations: 6 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 18 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _MessageBoxA@16 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _ExitProcess@4 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: message + Value: 6 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: caption + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .drectve + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 12 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .file + Value: 0 + SectionNumber: 65534 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + File: "hello.c" + - Name: abs_symbol + Value: 0xDEADBEEF + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: ___ImageBase + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/bss.asm b/test/pecoff/Inputs/bss.asm new file mode 100644 index 000000000000..802edee8591d --- /dev/null +++ b/test/pecoff/Inputs/bss.asm @@ -0,0 +1,20 @@ +.586 +.model flat, c + +extern ExitProcess@4 : PROC + +_BSS SEGMENT + _x DD 064H DUP (?) + _y DD 064H DUP (?) +_BSS ENDS + +.code +start: + mov eax, 42 + mov _x, eax + mov eax, _x + push eax + call ExitProcess@4 +end start + +end diff --git a/test/pecoff/Inputs/bss.obj b/test/pecoff/Inputs/bss.obj Binary files differnew file mode 100644 index 000000000000..3c00dfeb830b --- /dev/null +++ b/test/pecoff/Inputs/bss.obj diff --git a/test/pecoff/Inputs/comdat.obj.yaml b/test/pecoff/Inputs/comdat.obj.yaml new file mode 100644 index 000000000000..5537499873a3 --- /dev/null +++ b/test/pecoff/Inputs/comdat.obj.yaml @@ -0,0 +1,53 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 558BEC33C05DC3 + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 558BEC33C05DC3 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 7 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 2532800969 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: .text + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 7 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 2532800969 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: "?inlinefn1@@YAHXZ" + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: "?inlinefn2@@YAHXZ" + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/common-symbol.obj.yaml b/test/pecoff/Inputs/common-symbol.obj.yaml new file mode 100644 index 000000000000..05ddd022f286 --- /dev/null +++ b/test/pecoff/Inputs/common-symbol.obj.yaml @@ -0,0 +1,85 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: b800000000b800000000b800000000b800000000b800000000 + Relocations: + - VirtualAddress: 1 + SymbolName: _bssdata4 + Type: IMAGE_REL_AMD64_ADDR32 + - VirtualAddress: 6 + SymbolName: _bsspad1 + Type: IMAGE_REL_AMD64_ADDR32 + - VirtualAddress: 11 + SymbolName: _bssdata64 + Type: IMAGE_REL_AMD64_ADDR32 + - VirtualAddress: 16 + SymbolName: _bsspad2 + Type: IMAGE_REL_AMD64_ADDR32 + - VirtualAddress: 21 + SymbolName: _bssdata16 + Type: IMAGE_REL_AMD64_ADDR32 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 03000000 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 5 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _bssdata4 + Value: 4 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _bsspad1 + Value: 1 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _bssdata64 + Value: 64 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _bsspad2 + Value: 1 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _bssdata16 + Value: 16 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/drectve.obj.yaml b/test/pecoff/Inputs/drectve.obj.yaml new file mode 100644 index 000000000000..22ec63f96e3e --- /dev/null +++ b/test/pecoff/Inputs/drectve.obj.yaml @@ -0,0 +1,79 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 558BEC56FF15000000008B0D000000008B3103F0FF150000000003C65E5DC3 + Relocations: + - VirtualAddress: 6 + SymbolName: __imp__fn + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 12 + SymbolName: __imp__var + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 22 + SymbolName: __imp___name_with_underscore + Type: IMAGE_REL_I386_DIR32 + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 2147483648 + SectionData: 2f64656661756c746c69623a766172732e6c6962202f73756273797374656d3a636f6e736f6c652c34322e313935202d3f666f6f00 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 31 + NumberOfRelocations: 3 + NumberOfLinenumbers: 0 + CheckSum: 3595596940 + Number: 0 + - Name: __imp__fn + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp___name_with_underscore + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp__var + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _fn + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .drectve + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 13 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 +... diff --git a/test/pecoff/Inputs/drectve2.obj.yaml b/test/pecoff/Inputs/drectve2.obj.yaml new file mode 100644 index 000000000000..836cbc3e743d --- /dev/null +++ b/test/pecoff/Inputs/drectve2.obj.yaml @@ -0,0 +1,45 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 558BEC56FF15000000008B0D000000008B3103F0FF150000000003C65E5DC3 + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 2147483648 + SectionData: 2f696e636c7564653a666f6f00 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 31 + NumberOfRelocations: 3 + NumberOfLinenumbers: 0 + CheckSum: 3595596940 + Number: 0 + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .drectve + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 13 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 +... diff --git a/test/pecoff/Inputs/drectve3.lib b/test/pecoff/Inputs/drectve3.lib Binary files differnew file mode 100644 index 000000000000..c295d1ff6d04 --- /dev/null +++ b/test/pecoff/Inputs/drectve3.lib diff --git a/test/pecoff/Inputs/entry.obj.yaml b/test/pecoff/Inputs/entry.obj.yaml new file mode 100644 index 000000000000..35eae143c430 --- /dev/null +++ b/test/pecoff/Inputs/entry.obj.yaml @@ -0,0 +1,40 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] + +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: A100000000030500000000C3 + +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + + - Name: _foo + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + + - Name: _bar + Value: 4 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + + - Name: "?baz@@YAXXZ" + Value: 4 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/executable.obj.yaml b/test/pecoff/Inputs/executable.obj.yaml new file mode 100644 index 000000000000..73ba0fe71914 --- /dev/null +++ b/test/pecoff/Inputs/executable.obj.yaml @@ -0,0 +1,29 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: '7047' +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 2 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: mainCRTStartup + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/executable.s b/test/pecoff/Inputs/executable.s new file mode 100644 index 000000000000..1c58f7331b26 --- /dev/null +++ b/test/pecoff/Inputs/executable.s @@ -0,0 +1,17 @@ + +# void mainCRTStartup(){} + + .syntax unified + .thumb + .text + + .def mainCRTStartup + .scl 2 + .type 32 + .endef + .global mainCRTStartup + .align 2 + .thumb_func +mainCRTStartup: + bx lr + diff --git a/test/pecoff/Inputs/export.obj.yaml b/test/pecoff/Inputs/export.obj.yaml new file mode 100644 index 000000000000..fa92cd09bee4 --- /dev/null +++ b/test/pecoff/Inputs/export.obj.yaml @@ -0,0 +1,69 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: B800000000506800000000680000000050E80000000050E800000000 + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 2147483648 + SectionData: 2f6578706f72743a5f6578706f7274666e334032353600 # /export:_exportfn3@256 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 28 + NumberOfRelocations: 4 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _init + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _exportfn1 + Value: 8 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _exportfn2 + Value: 16 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _exportfn3@256 + Value: 16 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _exportfn6 + Value: 16 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _exportfn7@8 + Value: 16 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: "?exportfn8@@YAXXZ" + Value: 16 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/exports.def b/test/pecoff/Inputs/exports.def new file mode 100644 index 000000000000..7b444f9719d1 --- /dev/null +++ b/test/pecoff/Inputs/exports.def @@ -0,0 +1,6 @@ +; This is a comment line + +EXPORTS + exportfn1 @5 ; foo + exportfn2 + exportfn5=exportfn6 PRIVATE diff --git a/test/pecoff/Inputs/exports2.def b/test/pecoff/Inputs/exports2.def new file mode 100644 index 000000000000..1c95f42ceb60 --- /dev/null +++ b/test/pecoff/Inputs/exports2.def @@ -0,0 +1,6 @@ +; This is a comment line + +EXPORTS + exportfn1 @5 ; foo + exportfn7 + exportfn5=exportfn6 PRIVATE diff --git a/test/pecoff/Inputs/grouped-sections.asm b/test/pecoff/Inputs/grouped-sections.asm new file mode 100644 index 000000000000..af69363efefb --- /dev/null +++ b/test/pecoff/Inputs/grouped-sections.asm @@ -0,0 +1,18 @@ +.386 +.model flat, c + +_data$2 SEGMENT BYTE alias(".data$2") + db "orld", 0 +_data$2 ends + +_data$1 SEGMENT BYTE alias(".data$1") + db "o, w" +_data$1 ends + +.data + db "Hell" + +.code +main: + nop +end main diff --git a/test/pecoff/Inputs/grouped-sections.obj.yaml b/test/pecoff/Inputs/grouped-sections.obj.yaml new file mode 100644 index 000000000000..2180312acf92 --- /dev/null +++ b/test/pecoff/Inputs/grouped-sections.obj.yaml @@ -0,0 +1,83 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 90 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 48656C6C + - Name: ".data$2" + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 1 + SectionData: 6F726C6400 + - Name: ".data$1" + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 1 + SectionData: 6F2C2077 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 1 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: ".data$2" + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 5 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: ".data$1" + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: foo + Value: 2 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/hello.asm b/test/pecoff/Inputs/hello.asm new file mode 100644 index 000000000000..e360bbf65706 --- /dev/null +++ b/test/pecoff/Inputs/hello.asm @@ -0,0 +1,24 @@ +;;; ml hello.asm /link /subsystem:windows /defaultlib:kernel32.lib \ +;;; /defaultlib:user32.lib /out:hello.exe /entry:main + +.386 +.model flat, c + +extern MessageBoxA@16 : PROC +extern ExitProcess@4 : PROC + +.data + caption db "Hello", 0 + message db "Hello World", 0 + +.code +main: + mov eax, 0 + push eax + push offset caption + push offset message + push eax + call MessageBoxA@16 + push eax + call ExitProcess@4 +end main diff --git a/test/pecoff/Inputs/hello.obj.yaml b/test/pecoff/Inputs/hello.obj.yaml new file mode 100644 index 000000000000..6268a74057bd --- /dev/null +++ b/test/pecoff/Inputs/hello.obj.yaml @@ -0,0 +1,111 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: B800000000506800000000680000000050E80000000050E800000000 + Relocations: + - VirtualAddress: 7 + SymbolName: caption + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 12 + SymbolName: message + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 18 + SymbolName: _MessageBoxA@16 + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 24 + SymbolName: _ExitProcess@4 + Type: IMAGE_REL_I386_REL32 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 48656C6C6F0048656C6C6F20576F726C6400 + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 2147483648 + SectionData: 2F454E5452593A6D61696E20 +symbols: + - Name: "@comp.id" + Value: 10394907 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 28 + NumberOfRelocations: 4 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 18 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _MessageBoxA@16 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _ExitProcess@4 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: message + Value: 6 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: caption + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .drectve + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 12 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .file + Value: 0 + SectionNumber: 65534 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + File: "hello.c" +... diff --git a/test/pecoff/Inputs/hello64.asm b/test/pecoff/Inputs/hello64.asm new file mode 100644 index 000000000000..bc1a41b500d0 --- /dev/null +++ b/test/pecoff/Inputs/hello64.asm @@ -0,0 +1,22 @@ +;; ml hello64.asm /link /subsystem:windows /defaultlib:kernel32 \ +;; /defaultlib:user32 /out:hello64.exe /entry:main + +extern ExitProcess : PROC +extern MessageBoxA : PROC + +.data + caption db 'Hello', 0 + message db 'Hello World', 0 + +.code +main PROC + sub rsp,28h + mov rcx, 0 + lea rdx, message + lea r8, caption + mov r9d, 0 + call MessageBoxA + mov ecx, 0 + call ExitProcess +main ENDP +END diff --git a/test/pecoff/Inputs/hello64.obj.yaml b/test/pecoff/Inputs/hello64.obj.yaml new file mode 100644 index 000000000000..36b699623101 --- /dev/null +++ b/test/pecoff/Inputs/hello64.obj.yaml @@ -0,0 +1,110 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 4883EC2848C7C100000000488D15000000004C8D050000000041B900000000E800000000B900000000E800000000 + Relocations: + - VirtualAddress: 14 + SymbolName: message + Type: IMAGE_REL_AMD64_REL32 + - VirtualAddress: 21 + SymbolName: caption + Type: IMAGE_REL_AMD64_REL32 + - VirtualAddress: 32 + SymbolName: MessageBoxA + Type: IMAGE_REL_AMD64_REL32 + - VirtualAddress: 42 + SymbolName: ExitProcess + Type: IMAGE_REL_AMD64_REL32 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 16 + SectionData: 48656C6C6F0048656C6C6F20576F726C6400 + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F1000000830000004800011100000000433A5C63796777696E5C686F6D655C727569755C6C6C766D5C746F6F6C735C6C6C645C746573745C7065636F66665C496E707574735C68656C6C6F36342E6F626A0037003C1103020000D00000000000000000000C0000000D5201004D6963726F736F667420285229204D6163726F20417373656D626C6572000000 +symbols: + - Name: '@comp.id' + Value: 14635533 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '@feat.00' + Value: 16 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '.text$mn' + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 46 + NumberOfRelocations: 4 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 18 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.debug$S' + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 144 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: ExitProcess + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: MessageBoxA + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: message + Value: 6 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: caption + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/hello64lib.asm b/test/pecoff/Inputs/hello64lib.asm new file mode 100644 index 000000000000..89f95cd49af1 --- /dev/null +++ b/test/pecoff/Inputs/hello64lib.asm @@ -0,0 +1,14 @@ +.code +ExitProcess PROC + RET +ExitProcess ENDP + +MessageBoxA PROC + RET +MessageBoxA ENDP + +_DllMainCRTStartup PROC + RET +_DllMainCRTStartup ENDP + +END diff --git a/test/pecoff/Inputs/hello64lib.lib b/test/pecoff/Inputs/hello64lib.lib Binary files differnew file mode 100644 index 000000000000..3109c32593ca --- /dev/null +++ b/test/pecoff/Inputs/hello64lib.lib diff --git a/test/pecoff/Inputs/imagebase.obj.yaml b/test/pecoff/Inputs/imagebase.obj.yaml new file mode 100644 index 000000000000..e31e744fa058 --- /dev/null +++ b/test/pecoff/Inputs/imagebase.obj.yaml @@ -0,0 +1,55 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: A100000000C3 + Relocations: + - VirtualAddress: 1 + SymbolName: ___ImageBase + Type: IMAGE_REL_I386_DIR32 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 16 + SectionData: "" +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 6 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: ___ImageBase + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __start + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/library.lib b/test/pecoff/Inputs/library.lib Binary files differnew file mode 100755 index 000000000000..2f4207d7983d --- /dev/null +++ b/test/pecoff/Inputs/library.lib diff --git a/test/pecoff/Inputs/machine-type-unknown.obj.yaml b/test/pecoff/Inputs/machine-type-unknown.obj.yaml new file mode 100644 index 000000000000..f0da1ea7ac34 --- /dev/null +++ b/test/pecoff/Inputs/machine-type-unknown.obj.yaml @@ -0,0 +1,38 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_UNKNOWN + Characteristics: [] +sections: + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 2147483648 + SectionData: '' +symbols: + - Name: '@comp.id' + Value: 1 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '@feat.00' + Value: 1 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: __imp___close + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp__close + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_WEAK_EXTERNAL + WeakExternal: + TagIndex: 2 + Characteristics: IMAGE_WEAK_EXTERN_SEARCH_ALIAS +... diff --git a/test/pecoff/Inputs/main.obj.yaml b/test/pecoff/Inputs/main.obj.yaml new file mode 100644 index 000000000000..73a788049063 --- /dev/null +++ b/test/pecoff/Inputs/main.obj.yaml @@ -0,0 +1,70 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: A100000000030500000000C3 + Relocations: + - VirtualAddress: 1 + SymbolName: _val1 + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 7 + SymbolName: _val2 + Type: IMAGE_REL_I386_DIR32 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: "" +symbols: + - Name: "@comp.id" + Value: 10394907 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 12 + NumberOfRelocations: 2 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _val1 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _val2 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/merge-largest1.obj.yaml b/test/pecoff/Inputs/merge-largest1.obj.yaml new file mode 100644 index 000000000000..e372f9030603 --- /dev/null +++ b/test/pecoff/Inputs/merge-largest1.obj.yaml @@ -0,0 +1,30 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 00112233 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 7 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 2532800969 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_LARGEST + - Name: "_foo" + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/merge-largest2.obj.yaml b/test/pecoff/Inputs/merge-largest2.obj.yaml new file mode 100644 index 000000000000..f232cd3fd870 --- /dev/null +++ b/test/pecoff/Inputs/merge-largest2.obj.yaml @@ -0,0 +1,30 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 0011223344556677 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 7 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 2532800969 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_LARGEST + - Name: "_foo" + Value: 6 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/merge-same-size1.obj.yaml b/test/pecoff/Inputs/merge-same-size1.obj.yaml new file mode 100644 index 000000000000..02516f37220e --- /dev/null +++ b/test/pecoff/Inputs/merge-same-size1.obj.yaml @@ -0,0 +1,30 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: FFFFFFFFFFFFFF +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 7 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 2532800969 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_SAME_SIZE + - Name: "_foo" + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/merge-same-size2.obj.yaml b/test/pecoff/Inputs/merge-same-size2.obj.yaml new file mode 100644 index 000000000000..6b5b593bbab1 --- /dev/null +++ b/test/pecoff/Inputs/merge-same-size2.obj.yaml @@ -0,0 +1,30 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: AAAAAAAAAAAAAA +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 7 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 2532800969 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_SAME_SIZE + - Name: "_foo" + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/merge-same-size3.obj.yaml b/test/pecoff/Inputs/merge-same-size3.obj.yaml new file mode 100644 index 000000000000..47ad417f2f0c --- /dev/null +++ b/test/pecoff/Inputs/merge-same-size3.obj.yaml @@ -0,0 +1,30 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: FFFF +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 2 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 2532800969 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_SAME_SIZE + - Name: "_foo" + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/nonstandard-sections.obj.yaml b/test/pecoff/Inputs/nonstandard-sections.obj.yaml new file mode 100644 index 000000000000..b80d8862ec61 --- /dev/null +++ b/test/pecoff/Inputs/nonstandard-sections.obj.yaml @@ -0,0 +1,53 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 01234678 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 01234678 + - Name: .foo + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE, IMAGE_SCN_MEM_EXECUTE ] + Alignment: 4 + SectionData: 01234678 + - Name: .bar + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 01234678 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .foo + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .bar + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/nop.asm b/test/pecoff/Inputs/nop.asm new file mode 100644 index 000000000000..8e53070e7f5c --- /dev/null +++ b/test/pecoff/Inputs/nop.asm @@ -0,0 +1,9 @@ +.386 +.model flat, stdcall +option casemap :none + +.code +start: + mov eax, 42 + ret +end start diff --git a/test/pecoff/Inputs/nop.obj.yaml b/test/pecoff/Inputs/nop.obj.yaml new file mode 100644 index 000000000000..ccc097e7c926 --- /dev/null +++ b/test/pecoff/Inputs/nop.obj.yaml @@ -0,0 +1,51 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: B82A000000C3 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: "" +symbols: + - Name: "@comp.id" + Value: 10394907 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 6 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _start + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/nop64.obj.yaml b/test/pecoff/Inputs/nop64.obj.yaml new file mode 100644 index 000000000000..66edc376a90e --- /dev/null +++ b/test/pecoff/Inputs/nop64.obj.yaml @@ -0,0 +1,67 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: C3C3C3C3 + Relocations: + - VirtualAddress: 0 + SymbolName: __imp__fn + Type: IMAGE_REL_AMD64_REL32 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 16 + SectionData: '' +symbols: + - Name: '@comp.id' + Value: 13485607 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '@feat.00' + Value: 16 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 1 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: __imp__fn + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: start + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/reloc.obj.yaml b/test/pecoff/Inputs/reloc.obj.yaml new file mode 100644 index 000000000000..4c83258c623c --- /dev/null +++ b/test/pecoff/Inputs/reloc.obj.yaml @@ -0,0 +1,82 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 680000000068000000006800000000680000000068000000006800000000 + Relocations: + - VirtualAddress: 1 + SymbolName: _message + Type: IMAGE_REL_I386_SECTION + - VirtualAddress: 6 + SymbolName: _message + Type: IMAGE_REL_I386_SECREL + - VirtualAddress: 11 + SymbolName: .data + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 16 + SymbolName: .data + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 21 + SymbolName: __imp__MessageBoxA@16 + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 26 + SymbolName: _abs_value + Type: IMAGE_REL_I386_DIR32 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 576F726C64210048656C6C6F2C00 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 60 + NumberOfRelocations: 3 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 14 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 2 + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _message + Value: 5 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: __imp__MessageBoxA@16 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _abs_value + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/reloc64.obj.yaml b/test/pecoff/Inputs/reloc64.obj.yaml new file mode 100644 index 000000000000..3230ca51c6cc --- /dev/null +++ b/test/pecoff/Inputs/reloc64.obj.yaml @@ -0,0 +1,63 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 48B800000000000000ffE8000000ffE8000000ffE8000000ffE8000000ffE8000000ffE8000000ffE8000000ffE8000000ffC3 + Relocations: + - VirtualAddress: 2 + SymbolName: end + Type: IMAGE_REL_AMD64_ADDR64 + - VirtualAddress: 11 + SymbolName: end + Type: IMAGE_REL_AMD64_REL32 + - VirtualAddress: 16 + SymbolName: end + Type: IMAGE_REL_AMD64_REL32_1 + - VirtualAddress: 21 + SymbolName: end + Type: IMAGE_REL_AMD64_REL32_2 + - VirtualAddress: 26 + SymbolName: end + Type: IMAGE_REL_AMD64_REL32_3 + - VirtualAddress: 31 + SymbolName: end + Type: IMAGE_REL_AMD64_REL32_4 + - VirtualAddress: 36 + SymbolName: end + Type: IMAGE_REL_AMD64_REL32_5 + - VirtualAddress: 41 + SymbolName: end + Type: IMAGE_REL_AMD64_SECTION + - VirtualAddress: 46 + SymbolName: end + Type: IMAGE_REL_AMD64_SECREL +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 41 + NumberOfRelocations: 7 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: entry + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: end + Value: 40 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/resource.rc b/test/pecoff/Inputs/resource.rc new file mode 100644 index 000000000000..df933e83b77a --- /dev/null +++ b/test/pecoff/Inputs/resource.rc @@ -0,0 +1,4 @@ +STRINGTABLE +{ + 1, "Hello" +} diff --git a/test/pecoff/Inputs/resource.res b/test/pecoff/Inputs/resource.res Binary files differnew file mode 100755 index 000000000000..f1c799fbbb08 --- /dev/null +++ b/test/pecoff/Inputs/resource.res diff --git a/test/pecoff/Inputs/responsefile.txt b/test/pecoff/Inputs/responsefile.txt new file mode 100644 index 000000000000..08286119d4ed --- /dev/null +++ b/test/pecoff/Inputs/responsefile.txt @@ -0,0 +1 @@ +-foo -bar\baz diff --git a/test/pecoff/Inputs/secrel1.obj.yaml b/test/pecoff/Inputs/secrel1.obj.yaml new file mode 100644 index 000000000000..1c49261bbc43 --- /dev/null +++ b/test/pecoff/Inputs/secrel1.obj.yaml @@ -0,0 +1,69 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: C3 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 00000000000000000000000000000000 + Relocations: + - VirtualAddress: 0 + SymbolName: .data + Type: IMAGE_REL_I386_SECREL + - Name: .data2 + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 00000000000000000000000000000000 + Relocations: + - VirtualAddress: 0 + SymbolName: .data2 + Type: IMAGE_REL_I386_SECREL +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 60 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 2 + - Name: .data2 + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 3 + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/secrel2.obj.yaml b/test/pecoff/Inputs/secrel2.obj.yaml new file mode 100644 index 000000000000..2885fd07bb3a --- /dev/null +++ b/test/pecoff/Inputs/secrel2.obj.yaml @@ -0,0 +1,47 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 00000000000000000000000000000000 + Relocations: + - VirtualAddress: 0 + SymbolName: .data + Type: IMAGE_REL_I386_SECREL + - Name: .data2 + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 00000000000000000000000000000000 + Relocations: + - VirtualAddress: 0 + SymbolName: .data2 + Type: IMAGE_REL_I386_SECREL +symbols: + - Name: .data + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: .data2 + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 2 +... diff --git a/test/pecoff/Inputs/seh.c b/test/pecoff/Inputs/seh.c new file mode 100644 index 000000000000..b1c139a58f22 --- /dev/null +++ b/test/pecoff/Inputs/seh.c @@ -0,0 +1,13 @@ +__declspec(noinline) void triggerSEH() { + volatile int *p = 0; + *p = 1; +} + +int main() { + __try { + triggerSEH(); + } __except(1) { + return 42; + } + return 0; +} diff --git a/test/pecoff/Inputs/seh.obj.yaml b/test/pecoff/Inputs/seh.obj.yaml new file mode 100644 index 000000000000..6767671cdafe --- /dev/null +++ b/test/pecoff/Inputs/seh.obj.yaml @@ -0,0 +1,387 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 1 + SectionData: 2020202F44454641554C544C49423A22757569642E6C696222202F44454641554C544C49423A22757569642E6C696222202F4641494C49464D49534D415443483A225F4D53435F5645523D3138303022202F4641494C49464D49534D415443483A225F4954455241544F525F44454255475F4C4556454C3D3022202F4641494C49464D49534D415443483A2252756E74696D654C6962726172793D4D445F44796E616D696352656C6561736522202F44454641554C544C49423A226D73766370727422202F44454641554C544C49423A224D535643525422202F44454641554C544C49423A224F4C444E414D45532220 + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F1000000600000002200011100000000433A5C63796777696E5C686F6D655C727569755C7365682E6F626A003A003C11012200000700120000000D520100120000000D5201004D6963726F736F667420285229204F7074696D697A696E6720436F6D70696C657200 + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 00 + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 01 + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 54726967676572696E672053454820657863657074696F6E0D0A0000457865637574696E6720534548205F5F65786365707420626C6F636B20696E20666F6F0D0A000000457865637574696E6720534548205F5F65786365707420626C6F636B0D0A00 + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 558BEC516800000000FF150000000083C404C745FC000000008B45FCC700140000008BE55DC3CCCCCCCCCCCCCCCCCCCC558BEC51E8000000008D4DFFE8000000008BE55DC3CCCCCCCCCCCCCCCCCCCCCC558BEC6AFE6800000000680000000064A1000000005083EC08535657A1000000003145F833C5508D45F064A3000000008965E8C745FC00000000E800000000C745FCFEFFFFFFEB1EB801000000C38B65E86800000000FF150000000083C404C745FCFEFFFFFF8B4DF064890D00000000595F5E5B8BE55DC3CCCCCCCCCCCCCCCC558BEC6AFE6800000000680000000064A1000000005083EC08535657A1000000003145F833C5508D45F064A3000000008965E8C745FC00000000E800000000E800000000C745FCFEFFFFFFEB1EB801000000C38B65E86800000000FF150000000083C404C745FCFEFFFFFF33C08B4DF064890D00000000595F5E5B8BE55DC3 + Relocations: + - VirtualAddress: 5 + SymbolName: '$SG73531' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 11 + SymbolName: __imp__printf + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 53 + SymbolName: '?TestCPPEX@@YAXXZ' + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 61 + SymbolName: '??1TestClass@@QAE@XZ' + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 86 + SymbolName: '__sehtable$?foo@@YAXXZ' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 91 + SymbolName: __except_handler4 + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 109 + SymbolName: ___security_cookie + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 139 + SymbolName: '?TestExceptions@@YAXXZ' + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 162 + SymbolName: '$SG73539' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 168 + SymbolName: __imp__printf + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 214 + SymbolName: '__sehtable$_main' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 219 + SymbolName: __except_handler4 + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 237 + SymbolName: ___security_cookie + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 267 + SymbolName: '?foo@@YAXXZ' + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 272 + SymbolName: '?TestExceptions@@YAXXZ' + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 295 + SymbolName: '$SG73543' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 301 + SymbolName: __imp__printf + Type: IMAGE_REL_I386_DIR32 + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 558BEC51894DFC6800000000FF150000000083C4048BE55DC3 + Relocations: + - VirtualAddress: 8 + SymbolName: '??_C@_0BI@BBHGNMOG@Destroying?5TestClass?$CB?$AN?6?$AA@' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 14 + SymbolName: __imp__printf + Type: IMAGE_REL_I386_DIR32 + - Name: '.xdata$x' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 8 + SectionData: FEFFFFFF00000000D8FFFFFF00000000FEFFFFFF000000000000000000000000FEFFFFFF00000000D8FFFFFF00000000FEFFFFFF0000000000000000 + Relocations: + - VirtualAddress: 20 + SymbolName: '$LN5' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 24 + SymbolName: '$LN6' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 52 + SymbolName: '$LN5' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 56 + SymbolName: '$LN6' + Type: IMAGE_REL_I386_DIR32 + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 44657374726F79696E672054657374436C617373210D0A00 + - Name: .sxdata + Characteristics: [ IMAGE_SCN_LNK_INFO ] + Alignment: 4 + SectionData: 1B0000001A000000 +symbols: + - Name: '@comp.id' + Value: 14766605 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '@feat.00' + Value: 2147484049 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .drectve + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 240 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.debug$S' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 108 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .rdata + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 1 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: '?value@?$integral_constant@_N$0A@@std@@2_NB' + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .rdata + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 1 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 1996959894 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: '?value@?$integral_constant@_N$00@std@@2_NB' + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .rdata + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 99 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 2801625422 + Number: 0 + - Name: '$SG73531' + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '$SG73539' + Value: 28 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '$SG73543' + Value: 68 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '.text$mn' + Value: 0 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 335 + NumberOfRelocations: 17 + NumberOfLinenumbers: 0 + CheckSum: 2488225337 + Number: 0 + - Name: '.text$mn' + Value: 0 + SectionNumber: 7 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 25 + NumberOfRelocations: 2 + NumberOfLinenumbers: 0 + CheckSum: 210566957 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: __imp__printf + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '??1TestClass@@QAE@XZ' + Value: 0 + SectionNumber: 7 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '?TestCPPEX@@YAXXZ' + Value: 0 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '?TestExceptions@@YAXXZ' + Value: 48 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '?foo@@YAXXZ' + Value: 80 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _main + Value: 208 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __except_handler4 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '$LN5' + Value: 152 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '$LN7' + Value: 157 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '$LN6' + Value: 158 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '$LN5' + Value: 285 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '$LN7' + Value: 290 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '$LN6' + Value: 291 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '.xdata$x' + Value: 0 + SectionNumber: 8 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 60 + NumberOfRelocations: 4 + NumberOfLinenumbers: 0 + CheckSum: 2900129504 + Number: 0 + - Name: '__sehtable$?foo@@YAXXZ' + Value: 32 + SectionNumber: 8 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '__sehtable$_main' + Value: 0 + SectionNumber: 8 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .rdata + Value: 0 + SectionNumber: 9 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 24 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 1296623929 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: '??_C@_0BI@BBHGNMOG@Destroying?5TestClass?$CB?$AN?6?$AA@' + Value: 0 + SectionNumber: 9 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: ___security_cookie + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .sxdata + Value: 0 + SectionNumber: 10 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 +... diff --git a/test/pecoff/Inputs/static-data1.obj.yaml b/test/pecoff/Inputs/static-data1.obj.yaml new file mode 100644 index 000000000000..8dbe3e97eb51 --- /dev/null +++ b/test/pecoff/Inputs/static-data1.obj.yaml @@ -0,0 +1,67 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: "" + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 03000000 + - Name: ".debug$S" + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F1000000660000002B00011100000000433A5C63796777696E5C686F6D655C727569755C7374617469635C64617461312E6F626A0037003C1103020000030000000000000000000A0000001B9D01004D6963726F736F667420285229204D6163726F20417373656D626C657200000000 +symbols: + - Name: "@comp.id" + Value: 10394907 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: ".debug$S" + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 116 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _val1 + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/static-data2.obj.yaml b/test/pecoff/Inputs/static-data2.obj.yaml new file mode 100644 index 000000000000..9b368c033887 --- /dev/null +++ b/test/pecoff/Inputs/static-data2.obj.yaml @@ -0,0 +1,67 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: "" + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 04000000 + - Name: ".debug$S" + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F1000000660000002B00011100000000433A5C63796777696E5C686F6D655C727569755C7374617469635C64617461322E6F626A0037003C1103020000030000000000000000000A0000001B9D01004D6963726F736F667420285229204D6163726F20417373656D626C657200000000 +symbols: + - Name: "@comp.id" + Value: 10394907 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: ".debug$S" + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 116 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _val2 + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/static.lib b/test/pecoff/Inputs/static.lib Binary files differnew file mode 100644 index 000000000000..5a631010e1d3 --- /dev/null +++ b/test/pecoff/Inputs/static.lib diff --git a/test/pecoff/Inputs/subsystem.main.yaml b/test/pecoff/Inputs/subsystem.main.yaml new file mode 100644 index 000000000000..25fbe1be0143 --- /dev/null +++ b/test/pecoff/Inputs/subsystem.main.yaml @@ -0,0 +1,35 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: B82A000000C3 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 6 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _mainCRTStartup + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/subsystem.winmain.yaml b/test/pecoff/Inputs/subsystem.winmain.yaml new file mode 100644 index 000000000000..7f0381e2dc69 --- /dev/null +++ b/test/pecoff/Inputs/subsystem.winmain.yaml @@ -0,0 +1,35 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: B82A000000C3 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 6 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _WinMain + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _WinMainCRTStartup + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/tlsused.obj.yaml b/test/pecoff/Inputs/tlsused.obj.yaml new file mode 100644 index 000000000000..6a7880fa7878 --- /dev/null +++ b/test/pecoff/Inputs/tlsused.obj.yaml @@ -0,0 +1,29 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [] +sections: + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: "0000000000000000" +symbols: + - Name: .data + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 8 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: __tls_used + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/unknown-drectve.obj.yaml b/test/pecoff/Inputs/unknown-drectve.obj.yaml new file mode 100644 index 000000000000..79a12fe7bfa2 --- /dev/null +++ b/test/pecoff/Inputs/unknown-drectve.obj.yaml @@ -0,0 +1,42 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 558BEC56FF15000000008B0D000000008B3103F0FF150000000003C65E5DC3 + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 2147483648 + + # /nosuchoption:foobar + SectionData: 2f6e6f737563686f7074696f6e3a666f6f62617200 + +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 31 + NumberOfRelocations: 3 + NumberOfLinenumbers: 0 + CheckSum: 3595596940 + Number: 0 + - Name: .drectve + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 13 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 +... diff --git a/test/pecoff/Inputs/unwind.obj.yaml b/test/pecoff/Inputs/unwind.obj.yaml new file mode 100644 index 000000000000..2328cd565601 --- /dev/null +++ b/test/pecoff/Inputs/unwind.obj.yaml @@ -0,0 +1,129 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 4883EC184889742410440F110424534889E3488D235B4883C418C3C34881ECF0FF00004881ECF0FF80004881C4F0FF80004881C4F0FF0000C3 + - Name: .xdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 0912080312030F300E880000096402000422001A000000000000000021000000000000001B000000000000000100000000000000010E06000E11F0FF80000701FE1F001A + Relocations: + - VirtualAddress: 20 + SymbolName: __C_specific_handler + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 32 + SymbolName: func + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 36 + SymbolName: func + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 40 + SymbolName: .xdata + Type: IMAGE_REL_AMD64_ADDR32NB + - Name: .pdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 000000001B0000000000000012000000120000001C00000000000000010000002C000000000000001D00000034000000 + Relocations: + - VirtualAddress: 0 + SymbolName: func + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 4 + SymbolName: func + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 8 + SymbolName: .xdata + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 12 + SymbolName: func + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 16 + SymbolName: func + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 20 + SymbolName: .xdata + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 24 + SymbolName: smallFunc + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 28 + SymbolName: smallFunc + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 32 + SymbolName: .xdata + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 36 + SymbolName: allocFunc + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 40 + SymbolName: allocFunc + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 44 + SymbolName: .xdata + Type: IMAGE_REL_AMD64_ADDR32NB +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 57 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + - Name: .xdata + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 68 + NumberOfRelocations: 4 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 2 + - Name: .pdata + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 48 + NumberOfRelocations: 12 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 3 + - Name: func + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __C_specific_handler + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: smallFunc + Value: 27 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: allocFunc + Value: 28 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/vars-main-x64.obj.yaml b/test/pecoff/Inputs/vars-main-x64.obj.yaml new file mode 100644 index 000000000000..c888c28e4a67 --- /dev/null +++ b/test/pecoff/Inputs/vars-main-x64.obj.yaml @@ -0,0 +1,63 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 558BEC56FF15000000008B0D000000008B3103F0FF150000000003C65E5DC3 + Relocations: + - VirtualAddress: 6 + SymbolName: __imp_fn + Type: IMAGE_REL_AMD64_ADDR32 + - VirtualAddress: 12 + SymbolName: __imp_var + Type: IMAGE_REL_AMD64_ADDR32 + - VirtualAddress: 22 + SymbolName: __imp__name_with_underscore + Type: IMAGE_REL_AMD64_ADDR32 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 31 + NumberOfRelocations: 3 + NumberOfLinenumbers: 0 + CheckSum: 3595596940 + Number: 0 + - Name: __imp_fn + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp__name_with_underscore + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: "__delayLoadHelper2" + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp_var + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/vars-main-x86.obj.yaml b/test/pecoff/Inputs/vars-main-x86.obj.yaml new file mode 100644 index 000000000000..fb016828df94 --- /dev/null +++ b/test/pecoff/Inputs/vars-main-x86.obj.yaml @@ -0,0 +1,69 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 558BEC56FF15000000008B0D000000008B3103F0FF150000000003C65E5DC3 + Relocations: + - VirtualAddress: 6 + SymbolName: __imp__fn + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 12 + SymbolName: __imp__var + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 22 + SymbolName: __imp___name_with_underscore + Type: IMAGE_REL_I386_DIR32 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 31 + NumberOfRelocations: 3 + NumberOfLinenumbers: 0 + CheckSum: 3595596940 + Number: 0 + - Name: __imp__fn + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp___name_with_underscore + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: "___delayLoadHelper2@8" + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp__var + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: ___ImageBase + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/Inputs/vars-main.c b/test/pecoff/Inputs/vars-main.c new file mode 100644 index 000000000000..d588ca54b88e --- /dev/null +++ b/test/pecoff/Inputs/vars-main.c @@ -0,0 +1,7 @@ +__declspec(dllimport) int var; +__declspec(dllimport) int fn(void); +__declspec(dllimport) int _name_with_underscore(void); + +int main() { + return var + fn() + _name_with_underscore(); +} diff --git a/test/pecoff/Inputs/vars.c b/test/pecoff/Inputs/vars.c new file mode 100644 index 000000000000..ae2ec46d1f47 --- /dev/null +++ b/test/pecoff/Inputs/vars.c @@ -0,0 +1,20 @@ +// cl.exe /c vars.c +// link /dll /nodefaultlib /entry:dllmain /export:var,@1,NONAME,DATA \ +// /export:fn /export:_name_with_underscore vars.obj + +// will be exported by ordinal +int var = 3; + +// will be exported by name +int fn(void) { + return 4; +} + +// will be exported by name +int _name_with_underscore(void) { + return 5; +} + +int dllmain() { + return 1; +} diff --git a/test/pecoff/Inputs/vars.dll.yaml b/test/pecoff/Inputs/vars.dll.yaml new file mode 100644 index 000000000000..06f65ced6933 --- /dev/null +++ b/test/pecoff/Inputs/vars.dll.yaml @@ -0,0 +1,19 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_32BIT_MACHINE, IMAGE_FILE_DLL ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 2147483648 + SectionData: 558BECB8040000005DC3CCCCCCCCCCCC558BECB8050000005DC3CCCCCCCCCCCC558BECB8010000005DC30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 2147483648 + SectionData: 0000000050570852000000004020000001000000030000000200000028200000342000003C200000003000001010000000100000492000005F20000001000200766172732E646C6C005F6E616D655F776974685F756E64657273636F726500666E00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 2147483648 + SectionData: 0300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +symbols: +... diff --git a/test/pecoff/Inputs/vars.lib b/test/pecoff/Inputs/vars.lib Binary files differnew file mode 100644 index 000000000000..2d3aa2af678e --- /dev/null +++ b/test/pecoff/Inputs/vars.lib diff --git a/test/pecoff/Inputs/vars64.lib b/test/pecoff/Inputs/vars64.lib Binary files differnew file mode 100644 index 000000000000..fb48c9ab141e --- /dev/null +++ b/test/pecoff/Inputs/vars64.lib diff --git a/test/pecoff/Inputs/weak-externals.asm b/test/pecoff/Inputs/weak-externals.asm new file mode 100644 index 000000000000..7a5e918b92e7 --- /dev/null +++ b/test/pecoff/Inputs/weak-externals.asm @@ -0,0 +1,25 @@ +.386 +.model flat + +;; val1 should be linked normally. no_such_symbol1 should be ignored. +extern _no_such_symbol1 : PROC +extern _val1 (_no_such_symbol1): PROC + +;; no_such_symbol2 should be linked as val2. +extern _val2 : PROC +extern _no_such_symbol2 (_val2) : PROC + +;; no_such_symbol3 should fail to link. +extern _no_such_symbol3 : PROC + +public _fn1 +.code +_fn1: + push ebp + mov ebp, esp + call _val1 + call _no_such_symbol2 + call _no_such_symbol3 + pop ebp + ret 0 +end _fn1 diff --git a/test/pecoff/Inputs/weak-externals.obj.yaml b/test/pecoff/Inputs/weak-externals.obj.yaml new file mode 100644 index 000000000000..ee76936c5326 --- /dev/null +++ b/test/pecoff/Inputs/weak-externals.obj.yaml @@ -0,0 +1,91 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 558BECE800000000E800000000E8000000005DC3 + Relocations: + - VirtualAddress: 4 + SymbolName: _val1 + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 9 + SymbolName: _no_such_symbol2 + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 14 + SymbolName: _no_such_symbol3 + Type: IMAGE_REL_I386_REL32 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: "" +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 20 + NumberOfRelocations: 3 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _no_such_symbol1 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _val2 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _no_such_symbol3 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _val1 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_WEAK_EXTERNAL + WeakExternal: + TagIndex: 4 + Characteristics: IMAGE_WEAK_EXTERN_SEARCH_LIBRARY + - Name: _no_such_symbol2 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_WEAK_EXTERNAL + WeakExternal: + TagIndex: 5 + Characteristics: IMAGE_WEAK_EXTERN_SEARCH_LIBRARY + - Name: _fn1 + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/pecoff/alignment.test b/test/pecoff/alignment.test new file mode 100644 index 000000000000..bdf8bbaa2a3e --- /dev/null +++ b/test/pecoff/alignment.test @@ -0,0 +1,22 @@ +# RUN: yaml2obj %p/Inputs/alignment.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force \ +# RUN: /entry:start /opt:noref -- %t.obj +# RUN: llvm-readobj -sections %t.exe | FileCheck %s + +CHECK: Name: .bss (2E 62 73 73 00 00 00 00) +CHECK: RawDataSize: 0 + +CHECK: Name: .data (2E 64 61 74 61 00 00 00) +CHECK-NEXT: VirtualSize: 0x6 + +CHECK: Name: .text (2E 74 65 78 74 00 00 00) +CHECK-NEXT: VirtualSize: 0x1001 + +CHECK: Name: .yyy +CHECK-NEXT: VirtualSize: 0x2 +CHECK-NEXT: VirtualAddress: 0x5000 + +CHECK: Name: .zzz +CHECK-NEXT: VirtualSize: 0x2 +CHECK-NEXT: VirtualAddress: 0x8000 diff --git a/test/pecoff/alternatename.test b/test/pecoff/alternatename.test new file mode 100644 index 000000000000..926a8eae2876 --- /dev/null +++ b/test/pecoff/alternatename.test @@ -0,0 +1,44 @@ +# REQUIRES: x86 + +# RUN: yaml2obj %p/Inputs/alternatename1.obj.yaml > %t1.obj +# RUN: yaml2obj %p/Inputs/alternatename2.obj.yaml > %t2.obj +# RUN: yaml2obj %p/Inputs/alternatename3.obj.yaml > %t3.obj +# +# RUN: lld -flavor link /force /out:%t1.exe /alternatename:_main=_foo \ +# RUN: /subsystem:console -- %t1.obj +# RUN: llvm-objdump -d %t1.exe | FileCheck -check-prefix=CHECK1 %s +# +# RUN: lld -flavor link /force /out:%t2.exe /alternatename:_main=_foo \ +# RUN: /subsystem:console -- %t1.obj %t2.obj +# RUN: llvm-objdump -d %t2.exe | FileCheck -check-prefix=CHECK2 %s +# +# RUN: lld -flavor link /force /out:%t3.exe /subsystem:console -- %t3.obj +# RUN: llvm-objdump -d %t3.exe | FileCheck -check-prefix=CHECK3 %s +# +# RUN: lld -flavor link /force /out:%t4.exe /alternatename:_main=_foo \ +# RUN: /alternatename:_xyz=_foo /subsystem:console -- %t1.obj +# RUN: llvm-objdump -d %t4.exe | FileCheck -check-prefix=CHECK4 %s + +CHECK1: nop +CHECK1-NEXT: nop +CHECK1-NEXT: nop +CHECK1-NEXT: nop +CHECK1-NOT: int3 + +CHECK2: int3 +CHECK2-NEXT: int3 +CHECK2-NEXT: int3 +CHECK2-NEXT: int3 +CHECK2-NOT: nop + +CHECK3: nop +CHECK3-NEXT: nop +CHECK3-NEXT: nop +CHECK3-NEXT: nop +CHECK3-NOT: int3 + +CHECK4: nop +CHECK4-NEXT: nop +CHECK4-NEXT: nop +CHECK4-NEXT: nop +CHECK4-NOT: int3 diff --git a/test/pecoff/armnt-ImageBase.test b/test/pecoff/armnt-ImageBase.test new file mode 100644 index 000000000000..b4bf28c5eb81 --- /dev/null +++ b/test/pecoff/armnt-ImageBase.test @@ -0,0 +1,14 @@ +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-ImageBase.obj.yaml +# RUN: llvm-readobj -r %t.obj | FileCheck %s -check-prefix BEFORE +# RUN: lld -flavor link /out:%t.exe %t.obj /subsystem:console +# RUN: llvm-readobj -r %t.exe | FileCheck %s -check-prefix AFTER + +BEFORE: Relocations [ +BEFORE: Section {{.*}} .text { +BEFORE: 0x4 IMAGE_REL_ARM_ADDR32 __ImageBase +BEFORE: } +BEFORE: ] + +AFTER: Relocations [ +AFTER-NEXT: ] + diff --git a/test/pecoff/armnt-addr32-exec.test b/test/pecoff/armnt-addr32-exec.test new file mode 100644 index 000000000000..be223a0e7e5d --- /dev/null +++ b/test/pecoff/armnt-addr32-exec.test @@ -0,0 +1,11 @@ +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-addr32-exec.obj.yaml +# RUN: llvm-objdump -s %t.obj | FileCheck %s -check-prefix BEFORE +# RUN: lld -flavor link /out:%t.exe /entry:function /subsystem:console %t.obj +# RUN: llvm-objdump -s %t.exe | FileCheck %s -check-prefix AFTER + +BEFORE: Contents of section .rdata: +BEFORE: 0000 00000000 + +AFTER: Contents of section .rdata: +AFTER: 1000 01204000 + diff --git a/test/pecoff/armnt-addr32.test b/test/pecoff/armnt-addr32.test new file mode 100644 index 000000000000..716217d45758 --- /dev/null +++ b/test/pecoff/armnt-addr32.test @@ -0,0 +1,11 @@ +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-addr32.obj.yaml +# RUN: llvm-objdump -s %t.obj | FileCheck %s -check-prefix BEFORE +# RUN: lld -flavor link /entry:is /subsystem:console /out:%t.exe %t.obj +# RUN: llvm-objdump -s %t.exe | FileCheck %s -check-prefix AFTER + +BEFORE: Contents of section .rdata: +BEFORE: 0000 00000000 00000000 + +AFTER: Contents of section .rdata: +AFTER: 1000 00104000 00000000 + diff --git a/test/pecoff/armnt-address-of-entry-point.test b/test/pecoff/armnt-address-of-entry-point.test new file mode 100644 index 000000000000..3013b230bbd1 --- /dev/null +++ b/test/pecoff/armnt-address-of-entry-point.test @@ -0,0 +1,6 @@ +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/executable.obj.yaml +# RUN: lld -flavor link /out:%t.exe %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s + +# CHECK: AddressOfEntryPoint: 0x1001 + diff --git a/test/pecoff/armnt-blx23t.test b/test/pecoff/armnt-blx23t.test new file mode 100644 index 000000000000..56639fa22be9 --- /dev/null +++ b/test/pecoff/armnt-blx23t.test @@ -0,0 +1,27 @@ +# REQUIRES: arm + +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-blx23t.obj.yaml +# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE +# RUN: lld -flavor link /entry:function /subsystem:console /out:%t.exe %t.obj +# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER + +BEFORE: Disassembly of section .text: +BEFORE: 0: 70 47 bx lr +BEFORE: 2: 00 bf nop +BEFORE: 4: 2d e9 00 48 push.w {r11, lr} +BEFORE: 8: eb 46 mov r11, sp +BEFORE: a: 20 20 movs r0, #32 +BEFORE: c: 00 f0 00 f8 bl #0 +BEFORE: 10: 01 30 adds r0, #1 +BEFORE: 12: bd e8 00 88 pop.w {r11, pc} + +AFTER: Disassembly of section .text: +AFTER: 1000: 70 47 bx lr +AFTER: 1002: 00 bf nop +AFTER: 1004: 2d e9 00 48 push.w {r11, lr} +AFTER: 1008: eb 46 mov r11, sp +AFTER: 100a: 20 20 movs r0, #32 +AFTER: 100c: ff f7 f8 ff bl #-16 +AFTER: 1010: 01 30 adds r0, #1 +AFTER: 1012: bd e8 00 88 pop.w {r11, pc} + diff --git a/test/pecoff/armnt-branch24t.test b/test/pecoff/armnt-branch24t.test new file mode 100644 index 000000000000..1a727ed7d725 --- /dev/null +++ b/test/pecoff/armnt-branch24t.test @@ -0,0 +1,20 @@ +# REQUIRES: arm + +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-branch24t.obj.yaml +# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE +# RUN: lld -flavor link /entry:function /subsystem:console /out:%t.exe %t.obj +# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER + +BEFORE: Disassembly of section .text: +BEFORE: 0: 70 47 bx lr +BEFORE: 2: 00 bf nop +BEFORE: 4: 20 20 movs r0, #32 +BEFORE: 6: 00 f0 00 b8 b.w #0 + +AFTER: Disassembly of section .text: +AFTER: .text: +AFTER: 1000: 70 47 bx lr +AFTER: 1002: 00 bf nop +AFTER: 1004: 20 20 movs r0, #32 +AFTER: 1006: ff f7 fb bf b.w #-10 + diff --git a/test/pecoff/armnt-exports.s b/test/pecoff/armnt-exports.s new file mode 100644 index 000000000000..cb500bf02e07 --- /dev/null +++ b/test/pecoff/armnt-exports.s @@ -0,0 +1,28 @@ + +# void __declspec(dllexport) function() {} +# void _DllMainCRTStartup() {} + + .syntax unified + .thumb + .text + + .def function + .scl 2 + .type 32 + .endef + .global function + .align 2 + .thumb_func +function: + bx lr + + .def _DllMainCRTStartup + .scl 2 + .type 32 + .endef + .global _DllMainCRTStartup + .align 2 + .thumb_func +_DllMainCRTStartup + bx lr + diff --git a/test/pecoff/armnt-exports.test b/test/pecoff/armnt-exports.test new file mode 100644 index 000000000000..f0aa3eabcacc --- /dev/null +++ b/test/pecoff/armnt-exports.test @@ -0,0 +1,10 @@ +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-exports.obj.yaml +# RUN: lld -flavor link /dll /def:%p/Inputs/armnt-exports.def /out:%t.dll %t.obj +# RUN: llvm-readobj -coff-exports %t.dll | FileCheck %s + +CHECK: Export { +CHECK: Ordinal: 1 +CHECK: Name: function +CHECK: RVA: 0x2001 +CHECK: } + diff --git a/test/pecoff/armnt-imports.test b/test/pecoff/armnt-imports.test new file mode 100644 index 000000000000..596270909c52 --- /dev/null +++ b/test/pecoff/armnt-imports.test @@ -0,0 +1,11 @@ +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-import.obj.yaml +# RUN: lld -flavor link /out:%t.exe /subsystem:console %t.obj %p/Inputs/library.lib +# RUN: llvm-readobj -coff-imports %t.exe | FileCheck %s + +CHECK: Import { +CHECK: Name: library.dll +CHECK: ImportLookupTableRVA: 0x4000 +CHECK: ImportAddressTableRVA: 0x2000 +CHECK: Symbol: function (0) +CHECK: } + diff --git a/test/pecoff/armnt-mov32t-exec.test b/test/pecoff/armnt-mov32t-exec.test new file mode 100644 index 000000000000..de4feffea0cc --- /dev/null +++ b/test/pecoff/armnt-mov32t-exec.test @@ -0,0 +1,21 @@ +# REQUIRES: arm + +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-mov32t-exec.obj.yaml +# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE +# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:get_function %t.obj +# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER + +BEFORE: Disassembly of section .text: +BEFORE: 0: 70 47 bx lr +BEFORE: 2: 00 bf nop +BEFORE: 4: 40 f2 00 00 movw r0, #0 +BEFORE: 8: c0 f2 00 00 movt r0, #0 +BEFORE: c: 70 47 bx lr + +AFTER: Disassembly of section .text: +AFTER: 1000: 70 47 bx lr +AFTER: 1002: 00 bf nop +AFTER: 1004: 41 f2 01 00 movw r0, #4097 +AFTER: 1008: c0 f2 40 00 movt r0, #64 +AFTER: 100c: 70 47 bx lr + diff --git a/test/pecoff/armnt-movt32t.test b/test/pecoff/armnt-movt32t.test new file mode 100644 index 000000000000..2ae47ef75846 --- /dev/null +++ b/test/pecoff/armnt-movt32t.test @@ -0,0 +1,17 @@ +# REQUIRES: arm + +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-mov32t.obj.yaml +# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE +# RUN: lld -flavor link /entry:get_buffer /subsystem:console /out:%t.exe %t.obj +# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER + +BEFORE: Disassembly of section .text: +BEFORE: 0: 40 f2 00 00 movw r0, #0 +BEFORE: 4: c0 f2 00 00 movt r0, #0 +BEFORE: 8: 70 47 bx lr + +AFTER: Disassembly of section .text: +AFTER: 0: 41 f2 00 00 movw r0, #4096 +AFTER: 4: c0 f2 40 00 movt r0, #64 +AFTER: 8: 70 47 bx lr + diff --git a/test/pecoff/armnt.test b/test/pecoff/armnt.test new file mode 100644 index 000000000000..1cf6cd8114a4 --- /dev/null +++ b/test/pecoff/armnt.test @@ -0,0 +1,6 @@ +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-obj.yaml +# RUN: lld -flavor link /out:%t.dll /subsystem:console /entry:main %t.obj +# RUN: llvm-readobj -sections %t.dll | FileCheck %s + +CHECK: Format: COFF-ARM + diff --git a/test/pecoff/associative.test b/test/pecoff/associative.test new file mode 100644 index 000000000000..f998befd007e --- /dev/null +++ b/test/pecoff/associative.test @@ -0,0 +1,10 @@ +# RUN: yaml2obj %p/Inputs/associative1.obj.yaml > %t1.obj +# RUN: yaml2obj %p/Inputs/associative1.obj.yaml > %t2.obj +# RUN: yaml2obj %p/Inputs/associative3.obj.yaml > %t3.obj +# +# RUN: lld -flavor link /machine:x86 /subsystem:console /entry:main \ +# RUN: /out:%t.exe -- %t1.obj %t2.obj %t3.obj +# RUN: obj2yaml %t.exe | FileCheck %s + +CHECK: - Name: .CRT +CHECK: SectionData: '77777777' diff --git a/test/pecoff/base-reloc.test b/test/pecoff/base-reloc.test new file mode 100644 index 000000000000..5bc83de4d1c2 --- /dev/null +++ b/test/pecoff/base-reloc.test @@ -0,0 +1,78 @@ +# RUN: yaml2obj %p/Inputs/basereloc.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force /opt:noref \ +# RUN: -- %t.obj +# RUN: llvm-readobj -coff-basereloc %t.exe | FileCheck %s --check-prefix=BASEREL +# +# RUN: lld -flavor link /out:%t2.exe /subsystem:console /force /fixed \ +# RUN: /opt:noref -- %t.obj +# RUN: llvm-readobj -coff-basereloc %t2.exe | FileCheck %s --check-prefix=NOBASEREL + +BASEREL: BaseReloc [ +BASEREL-NEXT: Entry { +BASEREL-NEXT: Type: HIGHLOW +BASEREL-NEXT: Address: 0x2007 +BASEREL-NEXT: } +BASEREL-NEXT: Entry { +BASEREL-NEXT: Type: HIGHLOW +BASEREL-NEXT: Address: 0x200C +BASEREL-NEXT: } +BASEREL-NEXT: Entry { +BASEREL-NEXT: Type: HIGHLOW +BASEREL-NEXT: Address: 0x201E +BASEREL-NEXT: } +BASEREL-NEXT: Entry { +BASEREL-NEXT: Type: ABSOLUTE +BASEREL-NEXT: Address: 0x2000 +BASEREL-NEXT: } +BASEREL-NEXT: Entry { +BASEREL-NEXT: Type: HIGHLOW +BASEREL-NEXT: Address: 0x3007 +BASEREL-NEXT: } +BASEREL-NEXT: Entry { +BASEREL-NEXT: Type: HIGHLOW +BASEREL-NEXT: Address: 0x300C +BASEREL-NEXT: } +BASEREL-NEXT: Entry { +BASEREL-NEXT: Type: HIGHLOW +BASEREL-NEXT: Address: 0x301E +BASEREL-NEXT: } +BASEREL-NEXT: Entry { +BASEREL-NEXT: Type: ABSOLUTE +BASEREL-NEXT: Address: 0x3000 +BASEREL-NEXT: } +BASEREL-NEXT: ] + +NOBASEREL: BaseReloc [ +NOBASEREL-NEXT: ] + +# RUN: lld -flavor link /out:%t3.exe /subsystem:console /force /opt:noref \ +# RUN: -- %t.obj +# RUN: llvm-readobj -file-headers -sections %t3.exe | FileCheck %s \ +# RUN: --check-prefix=BASEREL-HEADER +# +# RUN: lld -flavor link /out:%t4.exe /subsystem:console /force /opt:noref \ +# RUN: /fixed -- %t.obj +# RUN: llvm-readobj -file-headers %t4.exe | FileCheck %s \ +# RUN: --check-prefix=NOBASEREL-HEADER + +BASEREL-HEADER-NOT: IMAGE_FILE_RELOCS_STRIPPED + +NOBASEREL-HEADER: IMAGE_FILE_RELOCS_STRIPPED + +BASEREL-HEADER: BaseRelocationTableRVA: 0x4000 +BASEREL-HEADER: BaseRelocationTableSize: 0x20 +BASEREL-HEADER: Name: .reloc (2E 72 65 6C 6F 63 00 00) +BASEREL-HEADER-NEXT: VirtualSize: 0x20 +BASEREL-HEADER-NEXT: VirtualAddress: 0x4000 +BASEREL-HEADER-NEXT: RawDataSize: 512 +BASEREL-HEADER-NEXT: PointerToRawData: 0xA00 +BASEREL-HEADER-NEXT: PointerToRelocations: 0x0 +BASEREL-HEADER-NEXT: PointerToLineNumbers: 0x0 +BASEREL-HEADER-NEXT: RelocationCount: 0 +BASEREL-HEADER-NEXT: LineNumberCount: 0 +BASEREL-HEADER-NEXT: Characteristics [ (0x42000040) +BASEREL-HEADER-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +BASEREL-HEADER-NEXT: IMAGE_SCN_MEM_DISCARDABLE (0x2000000) +BASEREL-HEADER-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +BASEREL-HEADER-NEXT: ] diff --git a/test/pecoff/baseaddr.test b/test/pecoff/baseaddr.test new file mode 100644 index 000000000000..dbd091bc2e30 --- /dev/null +++ b/test/pecoff/baseaddr.test @@ -0,0 +1,18 @@ +# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t1.exe /opt:noref /subsystem:console /force \ +# RUN: -- %t.obj +# RUN: llvm-readobj -file-headers %t1.exe | FileCheck -check-prefix=DEFAULT %s +# +# RUN: lld -flavor link /out:%t2.exe /opt:noref /base:8388608 \ +# RUN: /subsystem:console /force -- %t.obj +# RUN: llvm-readobj -file-headers %t2.exe | FileCheck -check-prefix=BASE %s + +DEFAULT: ImageBase: 0x400000 + +BASE: ImageBase: 0x800000 + +# RUN: not lld -flavor link /base:3 /subsystem:console -- %t.obj >& %t.log +# RUN: FileCheck -check-prefix=ERROR %s < %t.log + +ERROR: Base address have to be multiple of 64K, but got 3 diff --git a/test/pecoff/bss-section.test b/test/pecoff/bss-section.test new file mode 100644 index 000000000000..4181e994fbf5 --- /dev/null +++ b/test/pecoff/bss-section.test @@ -0,0 +1,21 @@ +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force \ +# RUN: -- %p/Inputs/bss.obj +# RUN: llvm-readobj -sections %t.exe | FileCheck %s + +CHECK: Section { +CHECK: Number: 1 +CHECK-NEXT: Name: .bss +CHECK-NEXT: VirtualSize: 0x320 +CHECK-NEXT: VirtualAddress: 0x1000 +CHECK-NEXT: RawDataSize: 0 +CHECK-NEXT: PointerToRawData: 0x0 +CHECK-NEXT: PointerToRelocations: 0x0 +CHECK-NEXT: PointerToLineNumbers: 0x0 +CHECK-NEXT: RelocationCount: 0 +CHECK-NEXT: LineNumberCount: 0 +CHECK-NEXT: Characteristics [ +CHECK-NEXT: IMAGE_SCN_CNT_UNINITIALIZED_DATA +CHECK-NEXT: IMAGE_SCN_MEM_READ +CHECK-NEXT: IMAGE_SCN_MEM_WRITE +CHECK-NEXT: ] +CHECK-NEXT: } diff --git a/test/pecoff/comdat.test b/test/pecoff/comdat.test new file mode 100644 index 000000000000..d752309d7515 --- /dev/null +++ b/test/pecoff/comdat.test @@ -0,0 +1,12 @@ +# RUN: yaml2obj %p/Inputs/comdat.obj.yaml > %t1.obj +# RUN: yaml2obj %p/Inputs/comdat.obj.yaml > %t2.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /opt:noref /force \ +# RUN: -- %t1.obj %t2.obj 2>&1 > %t.log +# +# FileCheck complains if the input files is empty, so add a dummy line. +# RUN: echo foo >> %t.log +# +# RUN: FileCheck %s < %t.log + +CHECK-NOT: duplicate symbol error diff --git a/test/pecoff/common-symbol.test b/test/pecoff/common-symbol.test new file mode 100644 index 000000000000..49d4d8725da4 --- /dev/null +++ b/test/pecoff/common-symbol.test @@ -0,0 +1,14 @@ +# REQUIRES: x86 + +# RUN: yaml2obj %p/Inputs/common-symbol.obj.yaml > %t.obj +# +# RUN: lld -flavor link /machine:x64 /out:%t.exe /subsystem:console /force \ +# RUN: /opt:noref -- %t.obj %t.obj +# RUN: llvm-objdump -d %t.exe | FileCheck %s + +# Operands of B8 (MOV EAX) are common symbols +CHECK: 3000: b8 00 10 00 40 +CHECK: 3005: b8 04 10 00 40 +CHECK: 300a: b8 20 10 00 40 +CHECK: 300f: b8 60 10 00 40 +CHECK: 3014: b8 80 10 00 40 diff --git a/test/pecoff/conflicting-machine.test b/test/pecoff/conflicting-machine.test new file mode 100644 index 000000000000..6c71521fe1b7 --- /dev/null +++ b/test/pecoff/conflicting-machine.test @@ -0,0 +1,6 @@ +# RUN: yaml2obj %p/Inputs/vars-main-x64.obj.yaml > %t-x64.obj + +# RUN: not lld -flavor link /machine:x86 /out:%t.exe /entry:main %t-x64.obj 2>&1 \ +# RUN: | FileCheck %s + +CHECK: module machine type 'X64' conflicts with target machine type 'X86' diff --git a/test/pecoff/delayimport.test b/test/pecoff/delayimport.test new file mode 100644 index 000000000000..89ceb4ad5b20 --- /dev/null +++ b/test/pecoff/delayimport.test @@ -0,0 +1,54 @@ +# RUN: yaml2obj %p/Inputs/vars-main-x86.obj.yaml > %t-x86.obj +# RUN: yaml2obj %p/Inputs/vars-main-x64.obj.yaml > %t-x64.obj +# +# RUN: lld -flavor link /out:%t1.exe /subsystem:console /entry:main \ +# RUN: /delayload:vars.dll -- %t-x86.obj %p/Inputs/vars.lib +# RUN: llvm-readobj -coff-imports %t1.exe | FileCheck -check-prefix=X86 %s +# +# RUN: lld -flavor link /out:%t2.exe /subsystem:console /entry:main \ +# RUN: /machine:x64 /delayload:vars64.dll -- %t-x64.obj %p/Inputs/vars64.lib +# RUN: llvm-readobj -coff-imports %t2.exe | FileCheck -check-prefix=X64 %s + +X86: DelayImport { +X86-NEXT: Name: vars.dll +X86-NEXT: Attributes: 0x1 +X86-NEXT: ModuleHandle: 0x1000 +X86-NEXT: ImportAddressTable: 0x1004 +X86-NEXT: ImportNameTable: 0x2000 +X86-NEXT: BoundDelayImportTable: 0x0 +X86-NEXT: UnloadDelayImportTable: 0x0 +X86-NEXT: Import { +X86-NEXT: Symbol: _name_with_underscore (0) +X86-NEXT: Address: 0x40501F +X86-NEXT: } +X86-NEXT: Import { +X86-NEXT: Symbol: fn (1) +X86-NEXT: Address: 0x405034 +X86-NEXT: } +X86-NEXT: Import { +X86-NEXT: Symbol: (1) +X86-NEXT: Address: 0x405049 +X86-NEXT: } +X86-NEXT: } + +X64: DelayImport { +X64-NEXT: Name: vars64.dll +X64-NEXT: Attributes: 0x1 +X64-NEXT: ModuleHandle: 0x1000 +X64-NEXT: ImportAddressTable: 0x1008 +X64-NEXT: ImportNameTable: 0x2000 +X64-NEXT: BoundDelayImportTable: 0x0 +X64-NEXT: UnloadDelayImportTable: 0x0 +X64-NEXT: Import { +X64-NEXT: Symbol: _name_with_underscore (0) +X64-NEXT: Address: 0x14000501F +X64-NEXT: } +X64-NEXT: Import { +X64-NEXT: Symbol: fn (1) +X64-NEXT: Address: 0x140005076 +X64-NEXT: } +X64-NEXT: Import { +X64-NEXT: Symbol: (1) +X64-NEXT: Address: 0x1400050CD +X64-NEXT: } +X64-NEXT: } diff --git a/test/pecoff/dll.test b/test/pecoff/dll.test new file mode 100644 index 000000000000..666e9f1152b0 --- /dev/null +++ b/test/pecoff/dll.test @@ -0,0 +1,7 @@ +# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console \ +# RUN: /entry:start /dll -- %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s + +CHECK: IMAGE_FILE_DLL (0x2000) diff --git a/test/pecoff/dosstub.test b/test/pecoff/dosstub.test new file mode 100644 index 000000000000..f0458501704d --- /dev/null +++ b/test/pecoff/dosstub.test @@ -0,0 +1,11 @@ +# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj + +# RUN: echo "MZ Hello world" > %t.stub +# RUN: lld -flavor link /out:%t.exe /entry:start /subsystem:console \ +# RUN: /stub:%t.stub -- %t.obj +# RUN: FileCheck -check-prefix=FILE %s < %t.exe +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=READOBJ %s + +FILE: MZ Hello world + +READOBJ: Format: COFF-i386 diff --git a/test/pecoff/drectve.test b/test/pecoff/drectve.test new file mode 100644 index 000000000000..258f608e5dff --- /dev/null +++ b/test/pecoff/drectve.test @@ -0,0 +1,39 @@ +# Test if the linker can properly parse the .drectve section contents. +# "drectve.obj" contains "/defaultlib:vars /subsystem:console,42.195 -?foo" +# in its .drectve section. + +# RUN: yaml2obj %p/Inputs/drectve.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.exe /entry:main /opt:noref /libpath:%p/Inputs \ +# RUN: -- %t.obj >& %t.log +# +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=HEADER %s +# RUN: llvm-objdump -p %t.exe | FileCheck -check-prefix=IMPORT %s +# RUN: echo >> %t.log +# RUN: FileCheck -check-prefix=ERROR %s < %t.log + +HEADER: MajorOperatingSystemVersion: 42 +HEADER: MinorOperatingSystemVersion: 195 + +IMPORT: DLL Name: vars.dll +IMPORT-NEXT: Hint/Ord Name +IMPORT-NEXT: 0 _name_with_underscore +IMPORT-NEXT: 1 fn +IMPORT-NEXT: 1 + +ERROR-NOT: foo + + +# drectve2.obj contains "/include:foo". +# RUN: yaml2obj %p/Inputs/drectve2.obj.yaml > %t2.obj +# RUN: not lld -flavor link /out:%t2.exe /entry:main -- %t2.obj >& %t2.log +# RUN: FileCheck -check-prefix=UNDEF2 %s < %t2.log + +UNDEF2: Undefined symbol: {{.*}}: foo + +# drectve4.lib contains "/include:bar". +# RUN: not lld -flavor link /force /out:%t3.exe /entry:main /include:_fn1 -- \ +# RUN: %t2.obj %p/Inputs/drectve3.lib >& %t3.log +# RUN: FileCheck -check-prefix=UNDEF3 %s < %t3.log + +UNDEF3: Undefined symbol: {{.*}}: bar diff --git a/test/pecoff/dynamic.test b/test/pecoff/dynamic.test new file mode 100644 index 000000000000..6b9a945b1fc5 --- /dev/null +++ b/test/pecoff/dynamic.test @@ -0,0 +1,11 @@ +# RUN: yaml2obj %p/Inputs/vars-main-x86.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:main /opt:noref \ +# RUN: -- %t.obj %p/Inputs/vars.lib +# RUN: llvm-objdump -p %t.exe | FileCheck %s + +CHECK: DLL Name: vars.dll +CHECK-NEXT: Hint/Ord Name +CHECK-NEXT: 0 _name_with_underscore +CHECK-NEXT: 1 fn +CHECK-NEXT: 1 diff --git a/test/pecoff/dynamicbase.test b/test/pecoff/dynamicbase.test new file mode 100644 index 000000000000..9ed795b99db9 --- /dev/null +++ b/test/pecoff/dynamicbase.test @@ -0,0 +1,24 @@ +# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t1.exe /subsystem:console /force -- %t.obj +# RUN: llvm-readobj -file-headers %t1.exe | FileCheck %s \ +# RUN: --check-prefix=DYNAMICBASE +# +# RUN: lld -flavor link /out:%t2.exe /subsystem:console /force /dynamicbase:no \ +# RUN: -- %t.obj +# RUN: llvm-readobj -file-headers %t2.exe | FileCheck %s \ +# RUN: --check-prefix=NODYNAMICBASE +# +# RUN: lld -flavor link /out:%t3.exe /subsystem:console /force /fixed -- %t.obj +# RUN: llvm-readobj -file-headers %t3.exe | FileCheck %s \ +# RUN: --check-prefix=NODYNAMICBASE +# +# RUN: not lld -flavor link /out:%t4.exe /subsystem:console /force /fixed \ +# RUN: /dynamicbase -- %t.obj 2> %t.err +# RUN: FileCheck %s --check-prefix=DYNAMIC-AND-FIXED < %t.err + +DYNAMICBASE: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE + +NODYNAMICBASE-NOT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE + +DYNAMIC-AND-FIXED: /dynamicbase must not be specified with /fixed diff --git a/test/pecoff/entry.test b/test/pecoff/entry.test new file mode 100644 index 000000000000..b48e5a038293 --- /dev/null +++ b/test/pecoff/entry.test @@ -0,0 +1,41 @@ +# REQUIRES: asserts + +# RUN: yaml2obj %p/Inputs/entry.obj.yaml > %t.obj + +# RUN: not lld -flavor link /out:%t.exe /alternatename:_main=_foo \ +# RUN: -- %t.obj 2> %t.log +# RUN: FileCheck -check-prefix=MAIN %s < %t.log + +MAIN: _mainCRTStartup + +# RUN: not lld -flavor link /out:%t.exe /alternatename:_wmain=_foo \ +# RUN: -- %t.obj 2> %t.log +# RUN: FileCheck -check-prefix=WMAIN %s < %t.log + +WMAIN: _wmainCRTStartup + +# RUN: not lld -flavor link /out:%t.exe /alternatename:_WinMain=_foo \ +# RUN: -- %t.obj 2> %t.log +# RUN: FileCheck -check-prefix=WINMAIN %s < %t.log +# RUN: not lld -flavor link /out:%t.exe /alternatename:_WinMain@16=_foo \ +# RUN: -- %t.obj 2> %t.log +# RUN: FileCheck -check-prefix=WINMAIN %s < %t.log + +WINMAIN: _WinMainCRTStartup + +# RUN: not lld -flavor link /out:%t.exe /alternatename:_wWinMain=_foo \ +# RUN: -- %t.obj 2> %t.log +# RUN: FileCheck -check-prefix=WWINMAIN %s < %t.log + +WWINMAIN: _wWinMainCRTStartup + +# RUN: lld -flavor link /out:%t.exe /alternatename:_main=_foo \ +# RUN: /alternatename:_mainCRTStartup=_bar -- %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=MAINADDR %s + +MAINADDR: AddressOfEntryPoint: 0x1004 + +# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:baz -- %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=MANGLE %s + +MANGLE: AddressOfEntryPoint: 0x1004 diff --git a/test/pecoff/export-warning.test b/test/pecoff/export-warning.test new file mode 100644 index 000000000000..5c7647de00bd --- /dev/null +++ b/test/pecoff/export-warning.test @@ -0,0 +1,19 @@ +# RUN: yaml2obj %p/Inputs/export.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t1.dll /dll /entry:init \ +# RUN: /export:exportfn1 /export:exportfn1 -- %t.obj 2> %t1.log +# RUN: echo >> %t1.log +# RUN: FileCheck -check-prefix=CHECK1 %s < %t1.log +CHECK1-NOT: Export symbol '_exportfn1' specified more than once. + +# RUN: lld -flavor link /out:%t2.dll /dll /entry:init \ +# RUN: /export:exportfn1 /export:exportfn1,@5 -- %t.obj 2> %t2.log +# RUN: echo >> %t2.log +# RUN: FileCheck -check-prefix=CHECK2 %s < %t2.log +CHECK2: Export symbol '_exportfn1' specified more than once. + +# RUN: lld -flavor link /out:%t3.dll /dll /entry:init \ +# RUN: /export:exportfn1,@8 /export:exportfn1,@5 -- %t.obj 2> %t3.log +# RUN: echo >> %t3.log +# RUN: FileCheck -check-prefix=CHECK3 %s < %t3.log +CHECK3: Export symbol '_exportfn1' specified more than once. diff --git a/test/pecoff/export.test b/test/pecoff/export.test new file mode 100644 index 000000000000..63b8677cd4b7 --- /dev/null +++ b/test/pecoff/export.test @@ -0,0 +1,90 @@ +# RUN: yaml2obj %p/Inputs/export.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t1.dll /dll /entry:init \ +# RUN: /export:exportfn1 /export:exportfn2 -- %t.obj +# RUN: llvm-objdump -p %t1.dll | FileCheck -check-prefix=CHECK1 %s + +CHECK1: Export Table: +CHECK1: DLL name: export.test.tmp1.dll +CHECK1: Ordinal RVA Name +CHECK1-NEXT: 1 0x2008 exportfn1 +CHECK1-NEXT: 2 0x2010 exportfn2 + +# RUN: lld -flavor link /out:%t2.dll /dll /subsystem:console /entry:init \ +# RUN: /export:exportfn1,@5 /export:exportfn2 -- %t.obj +# RUN: llvm-objdump -p %t2.dll | FileCheck -check-prefix=CHECK2 %s + +CHECK2: Export Table: +CHECK2: DLL name: export.test.tmp2.dll +CHECK2: Ordinal RVA Name +CHECK2-NEXT: 5 0x2008 exportfn1 +CHECK2-NEXT: 6 0x2010 exportfn2 + +# RUN: lld -flavor link /out:%t3.dll /dll /subsystem:console /entry:init \ +# RUN: /export:exportfn1,@5,noname /export:exportfn2 -- %t.obj +# RUN: llvm-objdump -p %t3.dll | FileCheck -check-prefix=CHECK3 %s + +CHECK3: Export Table: +CHECK3: DLL name: export.test.tmp3.dll +CHECK3: Ordinal RVA Name +CHECK3-NEXT: 5 0x2008 +CHECK3-NEXT: 6 0x2010 exportfn2 + +# RUN: lld -flavor link /out:%t4.dll /dll /entry:init \ +# RUN: /def:%p/Inputs/exports.def -- %t.obj +# RUN: llvm-objdump -p %t4.dll | FileCheck -check-prefix=CHECK4 %s + +CHECK4: Export Table: +CHECK4: DLL name: export.test.tmp4.dll +CHECK4: Ordinal RVA Name +CHECK4-NEXT: 5 0x2008 exportfn1 +CHECK4-NEXT: 6 0x2010 exportfn2 +CHECK4-NEXT: 7 0x2010 exportfn3@256 +CHECK4-NEXT: 8 0x2010 exportfn5 + +# RUN: lld -flavor link /out:%t5.dll /dll /entry:init \ +# RUN: /export:exportfn7 -- %t.obj +# RUN: llvm-objdump -p %t5.dll | FileCheck -check-prefix=CHECK5 %s + +CHECK5: Export Table: +CHECK5: DLL name: export.test.tmp5.dll +CHECK5: Ordinal RVA Name +CHECK5-NEXT: 1 0x2010 exportfn3@256 +CHECK5-NEXT: 2 0x2010 exportfn7 + +# RUN: lld -flavor link /out:%t6.dll /dll /entry:init \ +# RUN: /export:exportfn8 -- %t.obj +# RUN: llvm-objdump -p %t6.dll | FileCheck -check-prefix=CHECK6 %s + +CHECK6: Export Table: +CHECK6: DLL name: export.test.tmp6.dll +CHECK6: Ordinal RVA Name +CHECK6-NEXT: 1 0x2010 exportfn3@256 +CHECK6-NEXT: 2 0x2010 exportfn8 + +# RUN: lld -flavor link /out:%t7.dll /dll /entry:init \ +# RUN: /export:exportfn7 /export:exportfn7@8 \ +# RUN: /export:exportfn8 /export:exportfn8 /export:exportfn3 -- %t.obj +# RUN: llvm-objdump -p %t7.dll | FileCheck -check-prefix=DUP %s + +DUP: Export Table: +DUP: DLL name: export.test.tmp7.dll +DUP: Ordinal RVA Name +DUP-NEXT: 1 0x2010 exportfn3 +DUP-NEXT: 2 0x2010 exportfn7 +DUP-NEXT: 3 0x2010 exportfn8 +DUP-NOT: ?exportfn8@@YAXXZ +DUP-NOT: exportfn3@256 + +# RUN: yaml2obj %p/Inputs/export.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t8.dll /dll /entry:init \ +# RUN: /export:f1=exportfn1 /export:f2@4=exportfn2,private -- %t.obj +# RUN: llvm-objdump -p %t8.dll | FileCheck -check-prefix=EQUAL %s + +EQUAL: Export Table: +EQUAL: DLL name: export.test.tmp8.dll +EQUAL: Ordinal RVA Name +EQUAL-NEXT: 1 0x2010 exportfn3@256 +EQUAL-NEXT: 2 0x2008 f1 +EQUAL-NEXT: 3 0x2010 f2{{$}} diff --git a/test/pecoff/exportlib.test b/test/pecoff/exportlib.test new file mode 100644 index 000000000000..b65751cfebd7 --- /dev/null +++ b/test/pecoff/exportlib.test @@ -0,0 +1,32 @@ +# REQUIRES: winlib + +# RUN: yaml2obj %p/Inputs/export.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.dll /dll /entry:init \ +# RUN: /export:exportfn1 /export:exportfn2 -- %t.obj +# RUN: llvm-readobj %t.lib | FileCheck %s + +CHECK: File: exportlib.test.tmp.dll +CHECK: Format: COFF-i386 +CHECK: Arch: i386 +CHECK: AddressSize: 32bit + +CHECK: File: exportlib.test.tmp.dll +CHECK: Format: COFF-i386 +CHECK: Arch: i386 +CHECK: AddressSize: 32bit + +CHECK: File: exportlib.test.tmp.dll +CHECK: Format: COFF-i386 +CHECK: Arch: i386 +CHECK: AddressSize: 32bit + +CHECK: File: exportlib.test.tmp.dll +CHECK: Format: COFF-<unknown arch> +CHECK: Arch: unknown +CHECK: AddressSize: 32bit + +CHECK: File: exportlib.test.tmp.dll +CHECK: Format: COFF-<unknown arch> +CHECK: Arch: unknown +CHECK: AddressSize: 32bit diff --git a/test/pecoff/exportlib2.test b/test/pecoff/exportlib2.test new file mode 100644 index 000000000000..e846b0bdd064 --- /dev/null +++ b/test/pecoff/exportlib2.test @@ -0,0 +1,21 @@ +# RUN: yaml2obj %p/Inputs/export.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.dll /dll /entry:init \ +# RUN: /export:exportfn1 /export:exportfn2 /lldmoduledeffile:%t1.def -- %t.obj +# RUN: FileCheck -check-prefix=CHECK1 %s < %t1.def + +CHECK1: LIBRARY "exportlib2.test.tmp.dll" +CHECK1: EXPORTS +CHECK1: exportfn1 @1 +CHECK1: exportfn2 @2 +CHECK1: exportfn3@256 @3 + +# RUN: lld -flavor link /out:%t.dll /dll /entry:init \ +# RUN: /def:%p/Inputs/exports2.def /lldmoduledeffile:%t2.def -- %t.obj +# RUN: FileCheck -check-prefix=CHECK2 %s < %t2.def + +CHECK2: LIBRARY "exportlib2.test.tmp.dll" +CHECK2: EXPORTS +CHECK2: exportfn1 @5 +CHECK2: exportfn3@256 @6 +CHECK2: exportfn7@8 @7 diff --git a/test/pecoff/grouped-sections.test b/test/pecoff/grouped-sections.test new file mode 100644 index 000000000000..40ae1478997e --- /dev/null +++ b/test/pecoff/grouped-sections.test @@ -0,0 +1,17 @@ +# RUN: yaml2obj %p/Inputs/grouped-sections.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:main -- %t.obj +# RUN: llvm-objdump -s %t.exe | FileCheck %s +# +# The file "grouped-sections.obj" has three data sections in the following +# order: +# +# .data$2 +# .data$1 +# .data +# +# If all the sections will be merged correctly, the resulting ".data" +# section will have the string "Hello, world". + +CHECK: Contents of section .data: +CHECK-NEXT: Hello, world diff --git a/test/pecoff/hello.test b/test/pecoff/hello.test new file mode 100644 index 000000000000..679b8b3ad984 --- /dev/null +++ b/test/pecoff/hello.test @@ -0,0 +1,51 @@ +# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj + +# RUN: lld -flavor link /out:%t1.exe /subsystem:console /force -- %t.obj +# RUN: llvm-readobj -file-headers %t1.exe | FileCheck -check-prefix=FILE %s + +FILE: ImageOptionalHeader { +FILE: SizeOfInitializedData: 1024 +FILE: SizeOfHeaders: 512 +FILE: } + +# RUN: lld -flavor link /out:%t2.exe /subsystem:console /force -- %t.obj +# RUN: llvm-readobj -sections %t2.exe | FileCheck -check-prefix=SECTIONS %s + +SECTIONS: Format: COFF-i386 +SECTIONS-NEXT: Arch: i386 +SECTIONS-NEXT: AddressSize: 32bit +SECTIONS-NEXT: Sections [ +SECTIONS-NEXT: Section { +SECTIONS-NEXT: Number: 1 +SECTIONS-NEXT: Name: .data +SECTIONS-NEXT: VirtualSize: 0x12 +SECTIONS-NEXT: VirtualAddress: 0x1000 +SECTIONS-NEXT: RawDataSize: 512 +SECTIONS-NEXT: PointerToRawData: 0x200 +SECTIONS-NEXT: PointerToRelocations: 0x0 +SECTIONS-NEXT: PointerToLineNumbers: 0x0 +SECTIONS-NEXT: RelocationCount: 0 +SECTIONS-NEXT: LineNumberCount: 0 +SECTIONS-NEXT: Characteristics [ +SECTIONS-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA +SECTIONS-NEXT: IMAGE_SCN_MEM_READ +SECTIONS-NEXT: IMAGE_SCN_MEM_WRITE +SECTIONS-NEXT: ] +SECTIONS-NEXT: } +SECTIONS-NEXT: Section { +SECTIONS-NEXT: Number: 2 +SECTIONS-NEXT: Name: .text (2E 74 65 78 74 00 00 00) +SECTIONS-NEXT: VirtualSize: 0x1C +SECTIONS-NEXT: VirtualAddress: 0x2000 +SECTIONS-NEXT: RawDataSize: 512 +SECTIONS-NEXT: PointerToRawData: 0x400 +SECTIONS-NEXT: PointerToRelocations: 0x0 +SECTIONS-NEXT: PointerToLineNumbers: 0x0 +SECTIONS-NEXT: RelocationCount: 0 +SECTIONS-NEXT: LineNumberCount: 0 +SECTIONS-NEXT: Characteristics [ +SECTIONS-NEXT: IMAGE_SCN_CNT_CODE +SECTIONS-NEXT: IMAGE_SCN_MEM_EXECUTE +SECTIONS-NEXT: IMAGE_SCN_MEM_READ +SECTIONS-NEXT: ] +SECTIONS-NEXT: } diff --git a/test/pecoff/hello64.test b/test/pecoff/hello64.test new file mode 100644 index 000000000000..7536e5a8fd26 --- /dev/null +++ b/test/pecoff/hello64.test @@ -0,0 +1,22 @@ +# REQUIRES: x86 + +# RUN: yaml2obj %p/Inputs/hello64.obj.yaml > %t.obj + +# RUN: lld -flavor link /out:%t.exe /subsystem:windows /machine:x64 \ +# RUN: /entry:main -- %t.obj %p/Inputs/hello64lib.lib +# RUN: llvm-objdump -disassemble %t.exe | FileCheck %s + +CHECK: 6000: 48 83 ec 28 subq $40, %rsp +CHECK: 6004: 48 c7 c1 00 00 00 00 movq $0, %rcx +CHECK: 600b: 48 8d 15 f4 af ff ff leaq -20492(%rip), %rdx +CHECK: 6012: 4c 8d 05 e7 af ff ff leaq -20505(%rip), %r8 +CHECK: 6019: 41 b9 00 00 00 00 movl $0, %r9d +CHECK: 601f: e8 12 00 00 00 callq 18 +CHECK: 6024: b9 00 00 00 00 movl $0, %ecx +CHECK: 6029: e8 00 00 00 00 callq 0 +CHECK: 602e: ff 25 cc cf ff ff jmpq *-12340(%rip) +CHECK: 6034: cc int3 +CHECK: 6035: cc int3 +CHECK: 6036: ff 25 cc cf ff ff jmpq *-12340(%rip) +CHECK: 603c: cc int3 +CHECK: 603d: cc int3 diff --git a/test/pecoff/help.test b/test/pecoff/help.test new file mode 100644 index 000000000000..f5e9c358f1a8 --- /dev/null +++ b/test/pecoff/help.test @@ -0,0 +1,4 @@ +# RUN: not lld -flavor link /help | FileCheck %s +# RUN: not lld -flavor link '/?' | FileCheck %s + +CHECK: USAGE diff --git a/test/pecoff/imagebase.test b/test/pecoff/imagebase.test new file mode 100644 index 000000000000..bb83e6b66124 --- /dev/null +++ b/test/pecoff/imagebase.test @@ -0,0 +1,15 @@ +# REQUIRES: x86 + +# RUN: yaml2obj %p/Inputs/imagebase.obj.yaml > %t.obj + +# RUN: lld -flavor link /out:%t1.exe /subsystem:console /entry:_start \ +# RUN: /opt:noref -- %t.obj +# RUN: llvm-objdump -disassemble %t1.exe | FileCheck -check-prefix=DEFAULT %s + +DEFAULT: a1 00 00 40 00 movl 4194304, %eax + +# RUN: lld -flavor link /out:%t2.exe /subsystem:console /entry:_start \ +# RUN: /base:65536 /opt:noref -- %t.obj +# RUN: llvm-objdump -disassemble %t2.exe | FileCheck -check-prefix=BASE %s + +BASE: a1 00 00 01 00 movl 65536, %eax diff --git a/test/pecoff/importlib.test b/test/pecoff/importlib.test new file mode 100644 index 000000000000..28e74f9dc78d --- /dev/null +++ b/test/pecoff/importlib.test @@ -0,0 +1,55 @@ +# REQUIRES: x86 + +# Verify that lld can handle .lib files. "main.obj" refers "var" and +# "fn" defined in "vars.lib". +# +# RUN: yaml2obj %p/Inputs/vars-main-x86.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t1.exe /subsystem:console /entry:main /opt:noref \ +# RUN: -- %t.obj %p/Inputs/vars.lib +# RUN: llvm-objdump -d %t1.exe | FileCheck -check-prefix=TEXT %s +# RUN: llvm-readobj -coff-imports %t1.exe | FileCheck -check-prefix=IMPORT %s +# +# RUN: lld -flavor link /out:%t2.exe /subsystem:console /entry:main /opt:noref \ +# RUN: /libpath:%p/Inputs -- %t.obj vars.lib +# RUN: llvm-objdump -d %t2.exe | FileCheck -check-prefix=TEXT %s +# RUN: llvm-readobj -coff-imports %t2.exe | FileCheck -check-prefix=IMPORT %s +# +# RUN: lld -flavor link /out:%t3.exe /subsystem:console /entry:main /opt:noref \ +# RUN: /libpath:%p/Inputs /defaultlib:vars.lib -- %t.obj +# RUN: llvm-objdump -d %t3.exe | FileCheck -check-prefix=TEXT %s +# RUN: llvm-readobj -coff-imports %t3.exe | FileCheck -check-prefix=IMPORT %s +# +# RUN: env LIB=%p/Inputs lld -flavor link /out:%t4.exe /subsystem:console \ +# RUN: /opt:noref /entry:main -- %t.obj vars.lib +# RUN: llvm-objdump -d %t4.exe | FileCheck -check-prefix=TEXT %s +# RUN: llvm-readobj -coff-imports %t4.exe | FileCheck -check-prefix=IMPORT %s +# +# RUN: env LINK="/out:%t5.exe /subsystem:console /entry:main /opt:noref \ +# RUN: -- %t.obj" lld -flavor link %p/Inputs/vars.lib +# RUN: llvm-objdump -d %t5.exe | FileCheck -check-prefix=TEXT %s +# RUN: llvm-readobj -coff-imports %t5.exe | FileCheck -check-prefix=IMPORT %s + +TEXT: Disassembly of section .text: +TEXT-NEXT: .text: +TEXT-NEXT: pushl %ebp +TEXT-NEXT: movl %esp, %ebp +TEXT-NEXT: pushl %esi +TEXT-NEXT: calll *{{[0-9]+}} +TEXT-NEXT: movl {{[0-9]+}}, %ecx +TEXT-NEXT: movl (%ecx), %esi +TEXT-NEXT: addl %eax, %esi +TEXT-NEXT: calll *{{[0-9]+}} +TEXT-NEXT: addl %esi, %eax +TEXT-NEXT: popl %esi +TEXT-NEXT: popl %ebp +TEXT-NEXT: ret + +IMPORT: Import { +IMPORT-NEXT: Name: vars.dll +IMPORT-NEXT: ImportLookupTableRVA: 0x4000 +IMPORT-NEXT: ImportAddressTableRVA: 0x2000 +IMPORT-NEXT: Symbol: _name_with_underscore (0) +IMPORT-NEXT: Symbol: fn (1) +IMPORT-NEXT: Symbol: (1) +IMPORT-NEXT: } diff --git a/test/pecoff/include.test b/test/pecoff/include.test new file mode 100644 index 000000000000..bee1f48bf1a7 --- /dev/null +++ b/test/pecoff/include.test @@ -0,0 +1,8 @@ +# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj +# +# RUN: not lld -flavor link /out:%t.exe /include:sym1 /include:sym2 \ +# RUN: /subsystem:console -- %t.obj 2> %t.log +# RUN: FileCheck %s < %t.log + +CHECK: Undefined symbol: <command line option /include>: sym1 +CHECK: Undefined symbol: <command line option /include>: sym2 diff --git a/test/pecoff/lib.test b/test/pecoff/lib.test new file mode 100644 index 000000000000..f435c117bc46 --- /dev/null +++ b/test/pecoff/lib.test @@ -0,0 +1,15 @@ +# REQUIRES: x86 + +# Verify that lld can handle a library file. +# +# RUN: yaml2obj %p/Inputs/main.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:main /opt:noref \ +# RUN: -- %t.obj %p/Inputs/static.lib +# RUN: llvm-objdump -d %t.exe | FileCheck %s + +CHECK: Disassembly of section .text: +CHECK-NEXT: .text: +CHECK-NEXT: movl 4198400, %eax +CHECK-NEXT: addl 4198404, %eax +CHECK-NEXT: ret diff --git a/test/pecoff/libarg.test b/test/pecoff/libarg.test new file mode 100644 index 000000000000..314f030c4fe0 --- /dev/null +++ b/test/pecoff/libarg.test @@ -0,0 +1,9 @@ +# REQUIRES: winlib +# +# If argv[1] == "/lib", link.exe morphs into lib.exe. +# +# RUN: lld -flavor link /lib >& %t.log +# RUN: FileCheck %s < %t.log + +CHECK-NOT: unrecognized option '/lib' +CHECK: usage: LIB diff --git a/test/pecoff/localyimported.test b/test/pecoff/localyimported.test new file mode 100644 index 000000000000..52b32d7b80bd --- /dev/null +++ b/test/pecoff/localyimported.test @@ -0,0 +1,15 @@ +# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj +# +# RUN: not lld -flavor link /out:%t.exe /include:__imp__nosuchsym %t.obj \ +# RUN: >& %t.log +# RUN: FileCheck -check-prefix=X86 %s < %t.log + +X86: Undefined symbol: __imp__nosuchsym: _nosuchsym + +# RUN: yaml2obj %p/Inputs/hello64.obj.yaml > %t2.obj +# +# RUN: not lld -flavor link /out:%t2.exe /include:__imp__nosuchsym %t2.obj \ +# RUN: /machine:x64 >& %t2.log +# RUN: FileCheck -check-prefix=X64 %s < %t2.log + +X64: Undefined symbol: __imp__nosuchsym: _nosuchsym diff --git a/test/pecoff/long-section-name.test b/test/pecoff/long-section-name.test new file mode 100644 index 000000000000..e6721c28302f --- /dev/null +++ b/test/pecoff/long-section-name.test @@ -0,0 +1,7 @@ +# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:start \ +# RUN: /merge:.text=.longsectionname -- %t.obj +# RUN: llvm-readobj -sections %t.exe | FileCheck %s + +CHECK: Name: .longsectionname (2F 34 00 00 00 00 00 00) diff --git a/test/pecoff/machinetype.test b/test/pecoff/machinetype.test new file mode 100644 index 000000000000..5d387f3b0393 --- /dev/null +++ b/test/pecoff/machinetype.test @@ -0,0 +1,13 @@ +# RUN: yaml2obj %p/Inputs/machine-type-unknown.obj.yaml > %t1.obj +# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t2.obj +# RUN: yaml2obj %p/Inputs/hello64.obj.yaml > %t3.obj + +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force -- %t1.obj %t2.obj +# RUN: llvm-readobj %t.exe | FileCheck -check-prefix=X86 %s + +X86: Arch: i386 + +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force -- %t1.obj %t3.obj +# RUN: llvm-readobj %t.exe | FileCheck -check-prefix=X64 %s + +X64: Arch: x86_64 diff --git a/test/pecoff/manifest.test b/test/pecoff/manifest.test new file mode 100644 index 000000000000..33229a45516b --- /dev/null +++ b/test/pecoff/manifest.test @@ -0,0 +1,63 @@ +# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj + +# RUN: lld -flavor link /out:%t1.exe /subsystem:console /force \ +# RUN: -- %t.obj +# RUN: FileCheck -check-prefix=MANIFEST %s < %t1.exe.manifest + +MANIFEST: <?xml version="1.0" standalone="yes"?> +MANIFEST: <assembly xmlns="urn:schemas-microsoft-com:asm.v1" +MANIFEST: manifestVersion="1.0"> +MANIFEST: <trustInfo> +MANIFEST: <security> +MANIFEST: <requestedPrivileges> +MANIFEST: <requestedExecutionLevel level='asInvoker' uiAccess='false'/> +MANIFEST: </requestedPrivileges> +MANIFEST: </security> +MANIFEST: </trustInfo> +MANIFEST: </assembly> + +# RUN: lld -flavor link /out:%t2.exe /subsystem:console /force \ +# RUN: /manifestuac:"level='requireAdministrator' uiAccess='true'" -- %t.obj +# RUN: FileCheck -check-prefix=UAC %s < %t2.exe.manifest + +UAC: <?xml version="1.0" standalone="yes"?> +UAC: <assembly xmlns="urn:schemas-microsoft-com:asm.v1" +UAC: manifestVersion="1.0"> +UAC: <trustInfo> +UAC: <security> +UAC: <requestedPrivileges> +UAC: <requestedExecutionLevel level='requireAdministrator' uiAccess='true'/> +UAC: </requestedPrivileges> +UAC: </security> +UAC: </trustInfo> +UAC: </assembly> + +# RUN: lld -flavor link /out:%t3.exe /subsystem:console /force \ +# RUN: /manifestdependency:"foo='bar'" -- %t.obj +# RUN: FileCheck -check-prefix=DEPENDENCY %s < %t3.exe.manifest + +DEPENDENCY: <?xml version="1.0" standalone="yes"?> +DEPENDENCY: <assembly xmlns="urn:schemas-microsoft-com:asm.v1" +DEPENDENCY: manifestVersion="1.0"> +DEPENDENCY: <trustInfo> +DEPENDENCY: <security> +DEPENDENCY: <requestedPrivileges> +DEPENDENCY: <requestedExecutionLevel level='asInvoker' uiAccess='false'/> +DEPENDENCY: </requestedPrivileges> +DEPENDENCY: </security> +DEPENDENCY: </trustInfo> +DEPENDENCY: <dependency> +DEPENDENCY: <dependentAssembly> +DEPENDENCY: <assemblyIdentity foo='bar' /> +DEPENDENCY: </dependentAssembly> +DEPENDENCY: </dependency> +DEPENDENCY: </assembly> + +# RUN: lld -flavor link /out:%t4.exe /subsystem:console /force \ +# RUN: /manifestuac:no -- %t.obj +# RUN: FileCheck -check-prefix=NOUAC %s < %t4.exe.manifest + +NOUAC: <?xml version="1.0" standalone="yes"?> +NOUAC: <assembly xmlns="urn:schemas-microsoft-com:asm.v1" +NOUAC: manifestVersion="1.0"> +NOUAC: </assembly> diff --git a/test/pecoff/merge-largest.test b/test/pecoff/merge-largest.test new file mode 100644 index 000000000000..c3ee96ca9c53 --- /dev/null +++ b/test/pecoff/merge-largest.test @@ -0,0 +1,24 @@ +# RUN: yaml2obj %p/Inputs/merge-largest1.obj.yaml > %t1.obj +# RUN: yaml2obj %p/Inputs/merge-largest2.obj.yaml > %t2.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /opt:noref /force \ +# RUN: -- %t1.obj %t2.obj 2>&1 > %t.log +# +# FileCheck complains if the input files is empty, so add a dummy line. +# RUN: echo foo >> %t.log +# RUN: FileCheck -check-prefix=STDERR %s < %t.log +# +# RUN: llvm-readobj -sections %t.exe | FileCheck -check-prefix=READOBJ %s + +STDERR-NOT: duplicate symbol error + +READOBJ: Format: COFF-i386 +READOBJ-NEXT: Arch: i386 +READOBJ-NEXT: AddressSize: 32bit +READOBJ-NEXT: Sections [ +READOBJ-NEXT: Section { +READOBJ-NEXT: Number: 1 +READOBJ-NEXT: Name: .text (2E 74 65 78 74 00 00 00) +READOBJ-NEXT: VirtualSize: 0x8 +READOBJ-NEXT: VirtualAddress: 0x1000 +READOBJ-NEXT: RawDataSize: 512 diff --git a/test/pecoff/merge-same-size.test b/test/pecoff/merge-same-size.test new file mode 100644 index 000000000000..c2918a2bc1a4 --- /dev/null +++ b/test/pecoff/merge-same-size.test @@ -0,0 +1,32 @@ +# RUN: yaml2obj %p/Inputs/merge-same-size1.obj.yaml > %t1.obj +# RUN: yaml2obj %p/Inputs/merge-same-size2.obj.yaml > %t2.obj +# RUN: yaml2obj %p/Inputs/merge-same-size3.obj.yaml > %t3.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /opt:noref /force \ +# RUN: -- %t1.obj %t2.obj > %t1.log 2>&1 +# +# FileCheck complains if the input files is empty, so add a dummy line. +# RUN: echo foo >> %t1.log +# RUN: FileCheck -check-prefix=SAMESIZE %s < %t1.log +# +# RUN: not lld -flavor link /out:%t.exe /subsystem:console /opt:noref /force \ +# RUN: -- %t1.obj %t3.obj > %t2.log 2>&1 +# RUN: FileCheck -check-prefix=DIFFERENT %s < %t2.log +# +# RUN: llvm-readobj -sections %t.exe | FileCheck -check-prefix=READOBJ %s + +SAMESIZE-NOT: duplicate symbol error + +DIFFERENT: Size mismatch +DIFFERENT: duplicate symbol error + +READOBJ: Format: COFF-i386 +READOBJ-NEXT: Arch: i386 +READOBJ-NEXT: AddressSize: 32bit +READOBJ-NEXT: Sections [ +READOBJ-NEXT: Section { +READOBJ-NEXT: Number: 1 +READOBJ-NEXT: Name: .text (2E 74 65 78 74 00 00 00) +READOBJ-NEXT: VirtualSize: 0x7 +READOBJ-NEXT: VirtualAddress: 0x1000 +READOBJ-NEXT: RawDataSize: 512 diff --git a/test/pecoff/multi.test b/test/pecoff/multi.test new file mode 100644 index 000000000000..e0bfdba6dda4 --- /dev/null +++ b/test/pecoff/multi.test @@ -0,0 +1,17 @@ +# REQUIRES: x86 + +# Verify that lld can handle multiple input files. +# +# RUN: yaml2obj %p/Inputs/main.obj.yaml > %t1.obj +# RUN: yaml2obj %p/Inputs/static-data1.obj.yaml > %t2.obj +# RUN: yaml2obj %p/Inputs/static-data2.obj.yaml > %t3.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:main /opt:noref \ +# RUN: -- %t1.obj %t2.obj %t3.obj +# RUN: llvm-objdump -d %t.exe | FileCheck %s + +CHECK: Disassembly of section .text: +CHECK: .text: +CHECK: movl {{[0-9]+}}, %eax +CHECK: addl {{[0-9]+}}, %eax +CHECK: ret diff --git a/test/pecoff/noentry.test b/test/pecoff/noentry.test new file mode 100644 index 000000000000..55b326dd84cb --- /dev/null +++ b/test/pecoff/noentry.test @@ -0,0 +1,10 @@ +# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj +# RUN: lld -flavor link /out:%t.exe /noentry /dll -- %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s + +CHECK: AddressOfEntryPoint: 0x0 + +# RUN: not lld -flavor link /out:%t.exe /noentry -- %t.obj >& %t.log +# RUN: FileCheck --check-prefix=ERROR %s < %t.log + +ERROR: /noentry must be specified with /dll diff --git a/test/pecoff/nonstandard-sections.test b/test/pecoff/nonstandard-sections.test new file mode 100644 index 000000000000..2ca181629230 --- /dev/null +++ b/test/pecoff/nonstandard-sections.test @@ -0,0 +1,75 @@ +# RUN: yaml2obj %p/Inputs/nonstandard-sections.obj.yaml > %t.obj +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force -- %t.obj +# RUN: llvm-readobj -sections %t.exe | FileCheck %s + +CHECK: Arch: i386 +CHECK-NEXT: AddressSize: 32bit +CHECK-NEXT: Sections [ +CHECK-NEXT: Section { +CHECK-NEXT: Number: 1 +CHECK-NEXT: Name: .bar (2E 62 61 72 00 00 00 00) +CHECK-NEXT: VirtualSize: 0x4 +CHECK-NEXT: VirtualAddress: 0x1000 +CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: PointerToRawData: 0x400 +CHECK-NEXT: PointerToRelocations: 0x0 +CHECK-NEXT: PointerToLineNumbers: 0x0 +CHECK-NEXT: RelocationCount: 0 +CHECK-NEXT: LineNumberCount: 0 +CHECK-NEXT: Characteristics [ (0x40000040) +CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +CHECK-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +CHECK-NEXT: ] +CHECK-NEXT: } +CHECK-NEXT: Section { +CHECK-NEXT: Number: 2 +CHECK-NEXT: Name: .data (2E 64 61 74 61 00 00 00) +CHECK-NEXT: VirtualSize: 0x4 +CHECK-NEXT: VirtualAddress: 0x2000 +CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: PointerToRawData: 0x600 +CHECK-NEXT: PointerToRelocations: 0x0 +CHECK-NEXT: PointerToLineNumbers: 0x0 +CHECK-NEXT: RelocationCount: 0 +CHECK-NEXT: LineNumberCount: 0 +CHECK-NEXT: Characteristics [ (0xC0000040) +CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +CHECK-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +CHECK-NEXT: IMAGE_SCN_MEM_WRITE (0x80000000) +CHECK-NEXT: ] +CHECK-NEXT: } +CHECK-NEXT: Section { +CHECK-NEXT: Number: 3 +CHECK-NEXT: Name: .foo (2E 66 6F 6F 00 00 00 00) +CHECK-NEXT: VirtualSize: 0x4 +CHECK-NEXT: VirtualAddress: 0x3000 +CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: PointerToRawData: 0x800 +CHECK-NEXT: PointerToRelocations: 0x0 +CHECK-NEXT: PointerToLineNumbers: 0x0 +CHECK-NEXT: RelocationCount: 0 +CHECK-NEXT: LineNumberCount: 0 +CHECK-NEXT: Characteristics [ (0xC0000040) +CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +CHECK-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +CHECK-NEXT: IMAGE_SCN_MEM_WRITE (0x80000000) +CHECK-NEXT: ] +CHECK-NEXT: } +CHECK-NEXT: Section { +CHECK-NEXT: Number: 4 +CHECK-NEXT: Name: .text (2E 74 65 78 74 00 00 00) +CHECK-NEXT: VirtualSize: 0x4 +CHECK-NEXT: VirtualAddress: 0x4000 +CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: PointerToRawData: 0xA00 +CHECK-NEXT: PointerToRelocations: 0x0 +CHECK-NEXT: PointerToLineNumbers: 0x0 +CHECK-NEXT: RelocationCount: 0 +CHECK-NEXT: LineNumberCount: 0 +CHECK-NEXT: Characteristics [ (0x60000020) +CHECK-NEXT: IMAGE_SCN_CNT_CODE (0x20) +CHECK-NEXT: IMAGE_SCN_MEM_EXECUTE (0x20000000) +CHECK-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +CHECK-NEXT: ] +CHECK-NEXT: } +CHECK-NEXT: ] diff --git a/test/pecoff/options.test b/test/pecoff/options.test new file mode 100644 index 000000000000..3aca2c9fcc91 --- /dev/null +++ b/test/pecoff/options.test @@ -0,0 +1,40 @@ +# Tests for miscellaneous command line options. + +# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t-x86.obj +# RUN: yaml2obj %p/Inputs/nop64.obj.yaml > %t-x64.obj + +# RUN: lld -flavor link /align:8192 /out:%t.exe /entry:start \ +# RUN: /subsystem:console -- %t-x86.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=ALIGN %s +ALIGN: SectionAlignment: 8192 + +# RUN: lld -flavor link /allowbind:no /out:%t.exe /entry:start \ +# RUN: /subsystem:console -- %t-x86.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOBIND %s +NOBIND: IMAGE_DLL_CHARACTERISTICS_NO_BIND + +# RUN: lld -flavor link /allowisolation:no /out:%t.exe /entry:start \ +# RUN: /subsystem:console -- %t-x86.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOISO %s +NOISO: IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION + +# RUN: lld -flavor link /swaprun:cd /out:%t.exe /entry:start \ +# RUN: /subsystem:console -- %t-x86.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=RUNCD %s +RUNCD: IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP + +# RUN: lld -flavor link /swaprun:net /out:%t.exe /entry:start \ +# RUN: /subsystem:console -- %t-x86.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=RUNNET %s +RUNNET: IMAGE_FILE_NET_RUN_FROM_SWAP + +# RUN: lld -flavor link /machine:x64 /force /highentropyva /out:%t.exe \ +# RUN: /entry:start /subsystem:console -- %t-x64.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=ENT %s +ENT: IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA + +# RUN: lld -flavor link /machine:x64 /force /highentropyva:no /out:%t.exe \ +# RUN: /entry:start /subsystem:console -- %t-x64.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOENT %s +NOENT-NOT: IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA + diff --git a/test/pecoff/pe32plus.test b/test/pecoff/pe32plus.test new file mode 100644 index 000000000000..1c64e184cbaf --- /dev/null +++ b/test/pecoff/pe32plus.test @@ -0,0 +1,87 @@ +# RUN: yaml2obj %p/Inputs/nop64.obj.yaml > %t.obj + +# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:start \ +# RUN: /machine:x64 -- %t.obj %p/Inputs/vars.lib +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s + +CHECK: Format: COFF-x86-64 +CHECK-NEXT: Arch: x86_64 +CHECK-NEXT: AddressSize: 64bit +CHECK-NEXT: ImageFileHeader { +CHECK-NEXT: Machine: IMAGE_FILE_MACHINE_AMD64 (0x8664) +CHECK-NEXT: SectionCount: 5 +CHECK-NEXT: TimeDateStamp: +CHECK-NEXT: PointerToSymbolTable: 0x0 +CHECK-NEXT: SymbolCount: 0 +CHECK-NEXT: OptionalHeaderSize: 240 +CHECK-NEXT: Characteristics [ (0x22) +CHECK-NEXT: IMAGE_FILE_EXECUTABLE_IMAGE (0x2) +CHECK-NEXT: IMAGE_FILE_LARGE_ADDRESS_AWARE (0x20) +CHECK-NEXT: ] +CHECK-NEXT: } +CHECK-NEXT: ImageOptionalHeader { +CHECK-NEXT: MajorLinkerVersion: 0 +CHECK-NEXT: MinorLinkerVersion: 0 +CHECK-NEXT: SizeOfCode: 512 +CHECK-NEXT: SizeOfInitializedData: 2048 +CHECK-NEXT: SizeOfUninitializedData: 0 +CHECK-NEXT: AddressOfEntryPoint: 0x5000 +CHECK-NEXT: BaseOfCode: 0x5000 +CHECK-NEXT: ImageBase: 0x140000000 +CHECK-NEXT: SectionAlignment: 4096 +CHECK-NEXT: FileAlignment: 512 +CHECK-NEXT: MajorOperatingSystemVersion: 6 +CHECK-NEXT: MinorOperatingSystemVersion: 0 +CHECK-NEXT: MajorImageVersion: 0 +CHECK-NEXT: MinorImageVersion: 0 +CHECK-NEXT: MajorSubsystemVersion: 6 +CHECK-NEXT: MinorSubsystemVersion: 0 +CHECK-NEXT: SizeOfImage: 24576 +CHECK-NEXT: SizeOfHeaders: 1024 +CHECK-NEXT: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI (0x3) +CHECK-NEXT: Characteristics [ (0x8160) +CHECK-NEXT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE (0x40) +CHECK-NEXT: IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA (0x20) +CHECK-NEXT: IMAGE_DLL_CHARACTERISTICS_NX_COMPAT (0x100) +CHECK-NEXT: IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE (0x8000) +CHECK-NEXT: ] +CHECK-NEXT: SizeOfStackReserve: 1048576 +CHECK-NEXT: SizeOfStackCommit: 4096 +CHECK-NEXT: SizeOfHeapReserve: 1048576 +CHECK-NEXT: SizeOfHeapCommit: 4096 +CHECK-NEXT: NumberOfRvaAndSize: 16 +CHECK-NEXT: DataDirectory { +CHECK-NEXT: ExportTableRVA: 0x0 +CHECK-NEXT: ExportTableSize: 0x0 +CHECK-NEXT: ImportTableRVA: 0x3000 +CHECK-NEXT: ImportTableSize: 0x28 +CHECK-NEXT: ResourceTableRVA: 0x0 +CHECK-NEXT: ResourceTableSize: 0x0 +CHECK-NEXT: ExceptionTableRVA: 0x0 +CHECK-NEXT: ExceptionTableSize: 0x0 +CHECK-NEXT: CertificateTableRVA: 0x0 +CHECK-NEXT: CertificateTableSize: 0x0 +CHECK-NEXT: BaseRelocationTableRVA: 0x0 +CHECK-NEXT: BaseRelocationTableSize: 0x0 +CHECK-NEXT: DebugRVA: 0x0 +CHECK-NEXT: DebugSize: 0x0 +CHECK-NEXT: ArchitectureRVA: 0x0 +CHECK-NEXT: ArchitectureSize: 0x0 +CHECK-NEXT: GlobalPtrRVA: 0x0 +CHECK-NEXT: GlobalPtrSize: 0x0 +CHECK-NEXT: TLSTableRVA: 0x0 +CHECK-NEXT: TLSTableSize: 0x0 +CHECK-NEXT: LoadConfigTableRVA: 0x0 +CHECK-NEXT: LoadConfigTableSize: 0x0 +CHECK-NEXT: BoundImportRVA: 0x0 +CHECK-NEXT: BoundImportSize: 0x0 +CHECK-NEXT: IATRVA: 0x2000 +CHECK-NEXT: IATSize: 0x10 +CHECK-NEXT: DelayImportDescriptorRVA: 0x0 +CHECK-NEXT: DelayImportDescriptorSize: 0x0 +CHECK-NEXT: CLRRuntimeHeaderRVA: 0x0 +CHECK-NEXT: CLRRuntimeHeaderSize: 0x0 +CHECK-NEXT: ReservedRVA: 0x0 +CHECK-NEXT: ReservedSize: 0x0 +CHECK-NEXT: } +CHECK-NEXT: } diff --git a/test/pecoff/reloc.test b/test/pecoff/reloc.test new file mode 100644 index 000000000000..5a969e9beaa0 --- /dev/null +++ b/test/pecoff/reloc.test @@ -0,0 +1,16 @@ +# REQUIRES: x86 + +# RUN: yaml2obj %p/Inputs/reloc.obj.yaml > %t1.obj +# RUN: yaml2obj %p/Inputs/abs.obj.yaml > %t2.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force /opt:noref \ +# RUN: -- %t1.obj %t2.obj +# RUN: llvm-objdump -d %t.exe | FileCheck %s + +CHECK: .text: +CHECK: 3000: 68 02 00 00 00 +CHECK: 3005: 68 05 00 00 00 +CHECK: 300a: 68 00 10 40 00 +CHECK: 300f: 68 00 10 40 00 +CHECK: 3014: 68 00 20 40 00 +CHECK: 3019: 68 ef be ad de diff --git a/test/pecoff/reloc64.test b/test/pecoff/reloc64.test new file mode 100644 index 000000000000..fc38bff03275 --- /dev/null +++ b/test/pecoff/reloc64.test @@ -0,0 +1,20 @@ +# REQUIRES: x86 + +# RUN: yaml2obj %p/Inputs/reloc64.obj.yaml > %t.obj + +# RUN: lld -flavor link /out:%t.exe /subsystem:console /machine:x64 \ +# RUN: /entry:entry -- %t.obj +# RUN: llvm-objdump -d %t.exe | FileCheck %s + +CHECK: Disassembly of section .text: +CHECK-NEXT: .text: +CHECK-NEXT: 1000: 48 b8 28 10 00 40 01 00 00 ff +CHECK-NEXT: 100a: e8 19 00 00 ff +CHECK-NEXT: 100f: e8 13 00 00 ff +CHECK-NEXT: 1014: e8 0d 00 00 ff +CHECK-NEXT: 1019: e8 07 00 00 ff +CHECK-NEXT: 101e: e8 01 00 00 ff +CHECK-NEXT: 1023: e8 fb ff ff fe +CHECK-NEXT: 1028: e8 01 00 00 ff +CHECK-NEXT: 102d: e8 28 00 00 ff +CHECK-NEXT: 1032: c3 diff --git a/test/pecoff/resource.test b/test/pecoff/resource.test new file mode 100644 index 000000000000..8cdc9a5bf83f --- /dev/null +++ b/test/pecoff/resource.test @@ -0,0 +1,16 @@ +# REQUIRES: winres + +# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj + +# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:start /opt:noref \ +# RUN: -- %t.obj %p/Inputs/resource.res + +# Check if the binary contains UTF-16LE string "Hello" copied from resource.res. +# RUN: cat %t.exe | grep 'H.e.l.l.o' + +# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:start /opt:noref \ +# RUN: /manifest:embed -- %t.obj %p/Inputs/resource.res +# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s + +CHECK: ResourceTableRVA: 0x1000 +CHECK: ResourceTableSize: 0x208 diff --git a/test/pecoff/responsefile.test b/test/pecoff/responsefile.test new file mode 100644 index 000000000000..6a5da298e730 --- /dev/null +++ b/test/pecoff/responsefile.test @@ -0,0 +1,7 @@ +# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj +# RUN: not lld -flavor link /verbose @%p/Inputs/responsefile.txt >& %t.log +# RUN: FileCheck %s < %t.log + +CHECK: warning: ignoring unknown argument: -foo +CHECK: warning: ignoring unknown argument: -bar\baz +Command line: link /verbose -foo -bar\baz diff --git a/test/pecoff/safeseh.test b/test/pecoff/safeseh.test new file mode 100644 index 000000000000..78b1b0b53ac1 --- /dev/null +++ b/test/pecoff/safeseh.test @@ -0,0 +1,9 @@ +# "hello.obj" does not have the symbol "@feat.00", so it's not +# compatible with SEH. + +# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t1.obj +# RUN: not lld -flavor link /safeseh /out:%t1.exe /subsystem:console \ +# RUN: -- %t1.obj 2> %t1.err +# RUN: FileCheck -check-prefix=INCOMPAT %s < %t1.err + +INCOMPAT: /SAFESEH is specified, but {{.*}} is not compatible with SEH. diff --git a/test/pecoff/secrel.test b/test/pecoff/secrel.test new file mode 100644 index 000000000000..05014c47af48 --- /dev/null +++ b/test/pecoff/secrel.test @@ -0,0 +1,16 @@ +# RUN: yaml2obj %p/Inputs/secrel1.obj.yaml > %t1.obj +# RUN: yaml2obj %p/Inputs/secrel2.obj.yaml > %t2.obj +# RUN: yaml2obj %p/Inputs/secrel2.obj.yaml > %t3.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:main \ +# RUN: -- %t1.obj %t2.obj %t3.obj +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +CHECK: Contents of section .data: +CHECK: 1000 00000000 00000000 00000000 00000000 +CHECK: 1010 10000000 00000000 00000000 00000000 +CHECK: 1020 20000000 00000000 00000000 00000000 +CHECK: Contents of section .data2: +CHECK: 2000 00000000 00000000 00000000 00000000 +CHECK: 2010 10000000 00000000 00000000 00000000 +CHECK: 2020 20000000 00000000 00000000 00000000 diff --git a/test/pecoff/section-attribute.test b/test/pecoff/section-attribute.test new file mode 100644 index 000000000000..a5e71625df99 --- /dev/null +++ b/test/pecoff/section-attribute.test @@ -0,0 +1,45 @@ +# RUN: yaml2obj %p/Inputs/nonstandard-sections.obj.yaml > %t.obj +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force \ +# RUN: /section:.foo,d /section:.bar,rw /section:.text,rwe -- %t.obj +# RUN: llvm-readobj -sections %t.exe | FileCheck %s + +CHECK: Sections [ +CHECK: Section { +CHECK: Number: 1 +CHECK: Name: .bar (2E 62 61 72 00 00 00 00) +CHECK: Characteristics [ (0xC0000040) +CHECK: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +CHECK: IMAGE_SCN_MEM_READ (0x40000000) +CHECK: IMAGE_SCN_MEM_WRITE (0x80000000) +CHECK: ] +CHECK: } +CHECK: Section { +CHECK: Number: 2 +CHECK: Name: .data (2E 64 61 74 61 00 00 00) +CHECK: Characteristics [ (0xC0000040) +CHECK: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +CHECK: IMAGE_SCN_MEM_READ (0x40000000) +CHECK: IMAGE_SCN_MEM_WRITE (0x80000000) +CHECK: ] +CHECK: } +CHECK: Section { +CHECK: Number: 3 +CHECK: Name: .foo (2E 66 6F 6F 00 00 00 00) +CHECK: Characteristics [ (0xC2000040) +CHECK: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +CHECK: IMAGE_SCN_MEM_DISCARDABLE (0x2000000) +CHECK: IMAGE_SCN_MEM_READ (0x40000000) +CHECK: IMAGE_SCN_MEM_WRITE (0x80000000) +CHECK: ] +CHECK: } +CHECK: Section { +CHECK: Number: 4 +CHECK: Name: .text (2E 74 65 78 74 00 00 00) +CHECK: Characteristics [ (0xE0000020) +CHECK: IMAGE_SCN_CNT_CODE (0x20) +CHECK: IMAGE_SCN_MEM_EXECUTE (0x20000000) +CHECK: IMAGE_SCN_MEM_READ (0x40000000) +CHECK: IMAGE_SCN_MEM_WRITE (0x80000000) +CHECK: ] +CHECK: } +CHECK: ] diff --git a/test/pecoff/section-renaming.test b/test/pecoff/section-renaming.test new file mode 100644 index 000000000000..d4fc154693af --- /dev/null +++ b/test/pecoff/section-renaming.test @@ -0,0 +1,61 @@ +# RUN: yaml2obj %p/Inputs/nonstandard-sections.obj.yaml > %t.obj +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force \ +# RUN: /merge:.foo=.hoge /merge:.bar=.text -- %t.obj +# RUN: llvm-readobj -sections %t.exe | FileCheck %s + +CHECK: Format: COFF-i386 +CHECK-NEXT: Arch: i386 +CHECK-NEXT: AddressSize: 32bit +CHECK-NEXT: Sections [ +CHECK-NEXT: Section { +CHECK-NEXT: Number: 1 +CHECK-NEXT: Name: .data (2E 64 61 74 61 00 00 00) +CHECK-NEXT: VirtualSize: 0x4 +CHECK-NEXT: VirtualAddress: 0x1000 +CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: PointerToRawData: 0x200 +CHECK-NEXT: PointerToRelocations: 0x0 +CHECK-NEXT: PointerToLineNumbers: 0x0 +CHECK-NEXT: RelocationCount: 0 +CHECK-NEXT: LineNumberCount: 0 +CHECK-NEXT: Characteristics [ (0xC0000040) +CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +CHECK-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +CHECK-NEXT: IMAGE_SCN_MEM_WRITE (0x80000000) +CHECK-NEXT: ] +CHECK-NEXT: } +CHECK-NEXT: Section { +CHECK-NEXT: Number: 2 +CHECK-NEXT: Name: .hoge (2E 68 6F 67 65 00 00 00) +CHECK-NEXT: VirtualSize: 0x4 +CHECK-NEXT: VirtualAddress: 0x2000 +CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: PointerToRawData: 0x400 +CHECK-NEXT: PointerToRelocations: 0x0 +CHECK-NEXT: PointerToLineNumbers: 0x0 +CHECK-NEXT: RelocationCount: 0 +CHECK-NEXT: LineNumberCount: 0 +CHECK-NEXT: Characteristics [ (0xC0000040) +CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +CHECK-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +CHECK-NEXT: IMAGE_SCN_MEM_WRITE (0x80000000) +CHECK-NEXT: ] +CHECK-NEXT: } +CHECK-NEXT: Section { +CHECK-NEXT: Number: 3 +CHECK-NEXT: Name: .text (2E 74 65 78 74 00 00 00) +CHECK-NEXT: VirtualSize: 0x8 +CHECK-NEXT: VirtualAddress: 0x3000 +CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: PointerToRawData: 0x600 +CHECK-NEXT: PointerToRelocations: 0x0 +CHECK-NEXT: PointerToLineNumbers: 0x0 +CHECK-NEXT: RelocationCount: 0 +CHECK-NEXT: LineNumberCount: 0 +CHECK-NEXT: Characteristics [ (0x60000020) +CHECK-NEXT: IMAGE_SCN_CNT_CODE (0x20) +CHECK-NEXT: IMAGE_SCN_MEM_EXECUTE (0x20000000) +CHECK-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +CHECK-NEXT: ] +CHECK-NEXT: } +CHECK-NEXT: ] diff --git a/test/pecoff/seh.test b/test/pecoff/seh.test new file mode 100644 index 000000000000..c563dc3f31e0 --- /dev/null +++ b/test/pecoff/seh.test @@ -0,0 +1,31 @@ +# RUN: yaml2obj %p/Inputs/seh.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force /nodefaultlib \ +# RUN: -- %t.obj +# RUN: llvm-objdump -private-headers %t.exe | FileCheck %s + +CHECK: Load configuration: +CHECK: Timestamp: 0 +CHECK: Major Version: 0 +CHECK: Minor Version: 0 +CHECK: GlobalFlags Clear: 0 +CHECK: GlobalFlags Set: 0 +CHECK: Critical Section Default Timeout: 0 +CHECK: Decommit Free Block Threshold: 0 +CHECK: Decommit Total Free Threshold: 0 +CHECK: Lock Prefix Table: 0 +CHECK: Maximum Allocation Size: 0 +CHECK: Virtual Memory Threshold: 0 +CHECK: Process Affinity Mask: 0 +CHECK: Process Heap Flags: 0 +CHECK: CSD Version: 0 +CHECK: Security Cookie: 0 +CHECK: SEH Table: 4206592 +CHECK: SEH Count: 2 +CHECK: SEH Table: 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} + +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force /nodefaultlib \ +# RUN: /safeseh:no -- %t.obj +# RUN: llvm-objdump -private-headers %t.exe | FileCheck -check-prefix=NOSEH %s + +NOSEH-NOT: SEH Table: diff --git a/test/pecoff/seh64.test b/test/pecoff/seh64.test new file mode 100644 index 000000000000..664ec29e5258 --- /dev/null +++ b/test/pecoff/seh64.test @@ -0,0 +1,57 @@ +# RUN: yaml2obj %p/Inputs/unwind.obj.yaml > %t.obj +# +# RUN: lld -flavor link /machine:x64 /out:%t.exe /subsystem:console /force \ +# RUN: /nodefaultlib -- %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=HEADER %s +# RUN: llvm-objdump -unwind-info %t.exe | FileCheck -check-prefix=UNWIND %s + +HEADER: ExceptionTableRVA: 0x1000 + +UNWIND: Function Table: +UNWIND: Start Address: 0x2000 +UNWIND: End Address: 0x201b +UNWIND: Unwind Info Address: 0x3000 +UNWIND: Version: 1 +UNWIND: Flags: 1 UNW_ExceptionHandler +UNWIND: Size of prolog: 18 +UNWIND: Number of Codes: 8 +UNWIND: Frame register: RBX +UNWIND: Frame offset: 0 +UNWIND: Unwind Codes: +UNWIND: 0x12: UOP_SetFPReg +UNWIND: 0x0f: UOP_PushNonVol RBX +UNWIND: 0x0e: UOP_SaveXMM128 XMM8 [0x0000] +UNWIND: 0x09: UOP_SaveNonVol RSI [0x0010] +UNWIND: 0x04: UOP_AllocSmall 24 +UNWIND: 0x00: UOP_PushMachFrame w/o error code +UNWIND: Function Table: +UNWIND: Start Address: 0x2012 +UNWIND: End Address: 0x2012 +UNWIND: Unwind Info Address: 0x301c +UNWIND: Version: 1 +UNWIND: Flags: 4 UNW_ChainInfo +UNWIND: Size of prolog: 0 +UNWIND: Number of Codes: 0 +UNWIND: No frame pointer used +UNWIND: Function Table: +UNWIND: Start Address: 0x201b +UNWIND: End Address: 0x201c +UNWIND: Unwind Info Address: 0x302c +UNWIND: Version: 1 +UNWIND: Flags: 0 +UNWIND: Size of prolog: 0 +UNWIND: Number of Codes: 0 +UNWIND: No frame pointer used +UNWIND: Function Table: +UNWIND: Start Address: 0x201c +UNWIND: End Address: 0x2039 +UNWIND: Unwind Info Address: 0x3034 +UNWIND: Version: 1 +UNWIND: Flags: 0 +UNWIND: Size of prolog: 14 +UNWIND: Number of Codes: 6 +UNWIND: No frame pointer used +UNWIND: Unwind Codes: +UNWIND: 0x0e: UOP_AllocLarge 8454128 +UNWIND: 0x07: UOP_AllocLarge 8190 +UNWIND: 0x00: UOP_PushMachFrame w/o error code diff --git a/test/pecoff/subsystem.test b/test/pecoff/subsystem.test new file mode 100644 index 000000000000..3ed3572bf231 --- /dev/null +++ b/test/pecoff/subsystem.test @@ -0,0 +1,12 @@ +# RUN: yaml2obj %p/Inputs/subsystem.main.yaml > %t.main.obj +# RUN: yaml2obj %p/Inputs/subsystem.winmain.yaml > %t.winmain.obj +# +# RUN: lld -flavor link /out:%t.main.exe -- %t.main.obj +# RUN: llvm-readobj -file-headers %t.main.exe | FileCheck -check-prefix=MAIN %s +# +# RUN: lld -flavor link /out:%t.winmain.exe -- %t.winmain.obj +# RUN: llvm-readobj -file-headers %t.winmain.exe | \ +# RUN: FileCheck -check-prefix=WINMAIN %s + +MAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI +WINMAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI diff --git a/test/pecoff/tls.test b/test/pecoff/tls.test new file mode 100644 index 000000000000..7e400ff60a0b --- /dev/null +++ b/test/pecoff/tls.test @@ -0,0 +1,14 @@ +# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t1.obj +# RUN: yaml2obj %p/Inputs/tlsused.obj.yaml > %t2.obj + +# RUN: lld -flavor link /out:%t1.exe /subsystem:console /force -- %t1.obj +# RUN: llvm-readobj -file-headers %t1.exe | FileCheck -check-prefix=NOTLS %s + +# RUN: lld -flavor link /out:%t2.exe /subsystem:console /force -- %t1.obj %t2.obj +# RUN: llvm-readobj -file-headers %t2.exe | FileCheck -check-prefix=TLS %s + +NOTLS: TLSTableRVA: 0x0 +NOTLS: TLSTableSize: 0x0 + +TLS: TLSTableRVA: 0x1014 +TLS: TLSTableSize: 0x18 diff --git a/test/pecoff/trivial.test b/test/pecoff/trivial.test new file mode 100644 index 000000000000..b1960f632813 --- /dev/null +++ b/test/pecoff/trivial.test @@ -0,0 +1,103 @@ +# Checks functionality of PECOFF writer. "nop.obj" is an object that has only +# text section. Other data, including data sections, relocations, symbol +# tables are not present in nop.obj. +# +# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t1.exe /subsystem:console,3.11 /version:1.25 \ +# RUN: /entry:start /opt:noref -- %t.obj +# RUN: llvm-readobj -file-headers %t1.exe | FileCheck -check-prefix=FILE %s +# +# RUN: lld -flavor link /out:%t2.exe /subsystem:console /entry:start \ +# RUN: /opt:noref -- %t.obj +# RUN: llvm-readobj -sections %t2.exe | FileCheck -check-prefix=SECTIONS %s + +FILE: Format: COFF-i386 +FILE-NEXT: Arch: i386 +FILE-NEXT: AddressSize: 32bit +FILE-NEXT: ImageFileHeader { +FILE-NEXT: Machine: IMAGE_FILE_MACHINE_I386 (0x14C) +FILE-NEXT: SectionCount: 1 +FILE-NEXT: TimeDateStamp: +FILE-NEXT: PointerToSymbolTable: 0x0 +FILE-NEXT: SymbolCount: 0 +FILE-NEXT: OptionalHeaderSize: 224 +FILE-NEXT: Characteristics [ (0x102) +FILE-NEXT: IMAGE_FILE_32BIT_MACHINE (0x100) +FILE-NEXT: IMAGE_FILE_EXECUTABLE_IMAGE (0x2) +FILE-NEXT: ] +FILE-NEXT: } +FILE-NEXT: ImageOptionalHeader { +FILE-NEXT: MajorLinkerVersion: 0 +FILE-NEXT: MinorLinkerVersion: 0 +FILE-NEXT: SizeOfCode: 512 +FILE-NEXT: SizeOfInitializedData: 0 +FILE-NEXT: SizeOfUninitializedData: 0 +FILE-NEXT: AddressOfEntryPoint: 0x1000 +FILE-NEXT: BaseOfCode: 0x1000 +FILE-NEXT: BaseOfData: 0 +FILE-NEXT: ImageBase: 0x400000 +FILE-NEXT: SectionAlignment: 4096 +FILE-NEXT: FileAlignment: 512 +FILE-NEXT: MajorOperatingSystemVersion: 3 +FILE-NEXT: MinorOperatingSystemVersion: 11 +FILE-NEXT: MajorImageVersion: 1 +FILE-NEXT: MinorImageVersion: 25 +FILE-NEXT: MajorSubsystemVersion: 3 +FILE-NEXT: MinorSubsystemVersion: 11 +FILE-NEXT: SizeOfImage: 8192 +FILE-NEXT: SizeOfHeaders: 512 +FILE-NEXT: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI (0x3) +FILE-NEXT: Characteristics [ (0x8540) +FILE-NEXT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE (0x40) +FILE-NEXT: IMAGE_DLL_CHARACTERISTICS_NO_SEH (0x400) +FILE-NEXT: IMAGE_DLL_CHARACTERISTICS_NX_COMPAT (0x100) +FILE-NEXT: IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE (0x8000) +FILE-NEXT: ] +FILE-NEXT: SizeOfStackReserve: 1048576 +FILE-NEXT: SizeOfStackCommit: 4096 +FILE-NEXT: SizeOfHeapReserve: 1048576 +FILE-NEXT: SizeOfHeapCommit: 4096 +FILE-NEXT: NumberOfRvaAndSize: 16 +FILE: DOSHeader { +FILE-NEXT: Magic: MZ +FILE-NEXT: UsedBytesInTheLastPage: 0 +FILE-NEXT: FileSizeInPages: 0 +FILE-NEXT: NumberOfRelocationItems: 0 +FILE-NEXT: HeaderSizeInParagraphs: 0 +FILE-NEXT: MinimumExtraParagraphs: 0 +FILE-NEXT: MaximumExtraParagraphs: 0 +FILE-NEXT: InitialRelativeSS: 0 +FILE-NEXT: InitialSP: 0 +FILE-NEXT: Checksum: 0 +FILE-NEXT: InitialIP: 0 +FILE-NEXT: InitialRelativeCS: 0 +FILE-NEXT: AddressOfRelocationTable: 64 +FILE-NEXT: OverlayNumber: 0 +FILE-NEXT: OEMid: 0 +FILE-NEXT: OEMinfo: 0 +FILE-NEXT: AddressOfNewExeHeader: 128 +FILE-NEXT: } + +SECTIONS: Format: COFF-i386 +SECTIONS-NEXT: Arch: i386 +SECTIONS-NEXT: AddressSize: 32bit +SECTIONS-NEXT: Sections [ +SECTIONS-NEXT: Section { +SECTIONS-NEXT: Number: 1 +SECTIONS-NEXT: Name: .text (2E 74 65 78 74 00 00 00) +SECTIONS-NEXT: VirtualSize: 0x6 +SECTIONS-NEXT: VirtualAddress: 0x1000 +SECTIONS-NEXT: RawDataSize: 512 +SECTIONS-NEXT: PointerToRawData: 0x200 +SECTIONS-NEXT: PointerToRelocations: 0x0 +SECTIONS-NEXT: PointerToLineNumbers: 0x0 +SECTIONS-NEXT: RelocationCount: 0 +SECTIONS-NEXT: LineNumberCount: 0 +SECTIONS-NEXT: Characteristics [ +SECTIONS-NEXT: IMAGE_SCN_CNT_CODE +SECTIONS-NEXT: IMAGE_SCN_MEM_EXECUTE +SECTIONS-NEXT: IMAGE_SCN_MEM_READ +SECTIONS-NEXT: ] +SECTIONS-NEXT: } +SECTIONS-NEXT: ] diff --git a/test/pecoff/unknown-drectve.test b/test/pecoff/unknown-drectve.test new file mode 100644 index 000000000000..2c687c5d9163 --- /dev/null +++ b/test/pecoff/unknown-drectve.test @@ -0,0 +1,6 @@ +# RUN: yaml2obj %p/Inputs/unknown-drectve.obj.yaml > %t.obj +# +# RUN: not lld -flavor link /out:%t.exe -- %t.obj >& %t.log +# RUN: FileCheck -check-prefix=ERROR %s < %t.log + +ERROR: Cannot open /nosuchoption:foobar diff --git a/test/pecoff/weak-external.test b/test/pecoff/weak-external.test new file mode 100644 index 000000000000..ff7492dcfd5e --- /dev/null +++ b/test/pecoff/weak-external.test @@ -0,0 +1,9 @@ +# RUN: yaml2obj %p/Inputs/weak-externals.obj.yaml > %t.obj + +# RUN: lld -flavor link /force /out:%t.exe /subsystem:console \ +# RUN: /entry:fn -- %t.obj %p/Inputs/static.lib 2> %t2.log +# RUN: FileCheck %s < %t2.log + +CHECK: _no_such_symbol1 +CHECK-NOT: _no_such_symbol2 +CHECK: _no_such_symbol3 |