diff options
Diffstat (limited to 'test/MC/ELF')
54 files changed, 2318 insertions, 1 deletions
diff --git a/test/MC/ELF/abs.s b/test/MC/ELF/abs.s new file mode 100644 index 0000000..d7fa0c0 --- /dev/null +++ b/test/MC/ELF/abs.s @@ -0,0 +1,16 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that zed will be an ABS symbol + +.Lfoo: +.Lbar: + zed = .Lfoo - .Lbar + +// CHECK: # Symbol 0x00000001 +// CHECK-NEXT: (('st_name', 0x00000001) # 'zed' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x0000fff1) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) diff --git a/test/MC/ELF/alias-reloc.s b/test/MC/ELF/alias-reloc.s new file mode 100644 index 0000000..6ad1134 --- /dev/null +++ b/test/MC/ELF/alias-reloc.s @@ -0,0 +1,52 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that this produces a R_X86_64_PLT32 with bar. + + .globl foo +foo: +bar = foo + .section zed, "", @progbits + call bar@PLT + + +// Test that this produres a relocation with bar2 + + .weak foo2 +foo2: + .weak bar2 + .set bar2,foo2 + .quad bar2 + +// CHECK: # Symbol 0x00000001 +// CHECK-NEXT: (('st_name', 0x00000005) # 'bar' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), + +// CHECK: # Symbol 0x00000006 +// CHECK-NEXT: (('st_name', 0x0000000e) # 'bar2' +// CHECK-NEXT: ('st_bind', 0x00000002) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000004) +// CHECK-NEXT: ('st_value', 0x00000005) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), + +// CHECK: # Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', 0x00000001) +// CHECK-NEXT: ('r_sym', 0x00000001) +// CHECK-NEXT: ('r_type', 0x00000004) +// CHECK-NEXT: ('r_addend', 0xfffffffc) +// CHECK-NEXT: ), + +// CHECK: # Relocation 0x00000001 +// CHECK-NEXT: (('r_offset', 0x00000005) +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x00000001) +// CHECK-NEXT: ('r_addend', 0x00000000) +// CHECK-NEXT: ), diff --git a/test/MC/ELF/alias.s b/test/MC/ELF/alias.s new file mode 100644 index 0000000..98ef50b --- /dev/null +++ b/test/MC/ELF/alias.s @@ -0,0 +1,85 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +foo: +bar = foo + + .globl foo2 +foo2 = bar2 + +foo3: + .globl bar3 +bar3 = foo3 + +// Test that bar4 is also a function + .type foo4,@function +foo4: +bar4 = foo4 + + .long foo2 +// CHECK: # Symbol 0x00000001 +// CHECK-NEXT: (('st_name', 0x00000005) # 'bar' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000002 +// CHECK-NEXT: (('st_name', 0x0000001d) # 'bar4' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000002) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000003 +// CHECK-NEXT: (('st_name', 0x00000001) # 'foo' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000004 +// CHECK-NEXT: (('st_name', 0x0000000e) # 'foo3' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000005 +// CHECK-NEXT: (('st_name', 0x00000018) # 'foo4' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000002) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000006 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK: # Symbol 0x00000007 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK: # Symbol 0x00000008 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK: # Symbol 0x00000009 +// CHECK-NEXT: (('st_name', 0x00000013) # 'bar3' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK: # Symbol 0x0000000a +// CHECK-NEXT: (('st_name', 0x00000009) # 'bar2' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) diff --git a/test/MC/ELF/align-bss.s b/test/MC/ELF/align-bss.s new file mode 100644 index 0000000..4f73a29 --- /dev/null +++ b/test/MC/ELF/align-bss.s @@ -0,0 +1,17 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that the bss section is correctly aligned + + .local foo + .comm foo,2048,16 + +// CHECK: ('sh_name', 0x0000000d) # '.bss' +// CHECK-NEXT: ('sh_type', 0x00000008) +// CHECK-NEXT: ('sh_flags', 0x00000003) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x00000800) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000010) +// CHECK-NEXT: ('sh_entsize', 0x00000000) diff --git a/test/MC/ELF/align-nops.s b/test/MC/ELF/align-nops.s new file mode 100644 index 0000000..28d4b89 --- /dev/null +++ b/test/MC/ELF/align-nops.s @@ -0,0 +1,40 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +// Test that we get optimal nops in text + .text +f0: + .long 0 + .align 8, 0x00000090 + .long 0 + .align 8 + +// But not in another section + .data + .long 0 + .align 8, 0x00000090 + .long 0 + .align 8 + +// CHECK: (('sh_name', 0x00000001) # '.text' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000006) +// CHECK-NEXT: ('sh_addr', +// CHECK-NEXT: ('sh_offset', +// CHECK-NEXT: ('sh_size', 0x00000010) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000008) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ('_section_data', '00000000 0f1f4000 00000000 0f1f4000') + +// CHECK: (('sh_name', 0x00000007) # '.data' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000003) +// CHECK-NEXT: ('sh_addr', +// CHECK-NEXT: ('sh_offset', +// CHECK-NEXT: ('sh_size', 0x00000010) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000008) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ('_section_data', '00000000 90909090 00000000 00000000') diff --git a/test/MC/ELF/align-size.s b/test/MC/ELF/align-size.s new file mode 100644 index 0000000..85331d7 --- /dev/null +++ b/test/MC/ELF/align-size.s @@ -0,0 +1,13 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that the alignment does contribute to the size of the section. + + .zero 4 + .align 8 + +// CHECK: (('sh_name', 0x00000001) # '.text' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000006) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x00000008) diff --git a/test/MC/ELF/align-text.s b/test/MC/ELF/align-text.s new file mode 100644 index 0000000..1d2dacb --- /dev/null +++ b/test/MC/ELF/align-text.s @@ -0,0 +1,19 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that the .text directive doesn't cause alignment. + + .zero 1 + .text + .zero 1 + +// CHECK: (('sh_name', 0x00000001) # '.text' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000006) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x00000002) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ), diff --git a/test/MC/ELF/align.s b/test/MC/ELF/align.s new file mode 100644 index 0000000..c3912a7 --- /dev/null +++ b/test/MC/ELF/align.s @@ -0,0 +1,32 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that the alignment of rodata doesn't force a alignment of the +// previous section (.bss) + + nop + .section .rodata,"a",@progbits + .align 8 + +// CHECK: # Section 0x00000003 +// CHECK-NEXT: (('sh_name', 0x0000000d) # '.bss' +// CHECK-NEXT: ('sh_type', 0x00000008) +// CHECK-NEXT: ('sh_flags', 0x00000003) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000044) +// CHECK-NEXT: ('sh_size', 0x00000000) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Section 0x00000004 +// CHECK-NEXT: (('sh_name', 0x00000012) # '.rodata' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000002) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000048) +// CHECK-NEXT: ('sh_size', 0x00000000) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000008) +// CHECK-NEXT: ('sh_entsize', 0x00000000) diff --git a/test/MC/ELF/basic-elf.ll b/test/MC/ELF/basic-elf.ll new file mode 100644 index 0000000..f478b32 --- /dev/null +++ b/test/MC/ELF/basic-elf.ll @@ -0,0 +1,111 @@ +; RUN: llc -filetype=obj -mtriple i686-pc-linux-gnu %s -o - | elf-dump | FileCheck -check-prefix=32 %s +; RUN: llc -filetype=obj -mtriple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck -check-prefix=64 %s + +@.str1 = private constant [6 x i8] c"Hello\00" +@.str2 = private constant [7 x i8] c"World!\00" + +define i32 @main() nounwind { + %1 = call i32 @puts(i8* getelementptr inbounds ([6 x i8]* @.str1, i32 0, i32 0)) + %2 = call i32 @puts(i8* getelementptr inbounds ([7 x i8]* @.str2, i32 0, i32 0)) + ret i32 0 +} + +declare i32 @puts(i8* nocapture) nounwind + +; 32: ('e_indent[EI_CLASS]', 0x00000001) +; 32: ('e_indent[EI_DATA]', 0x00000001) +; 32: ('e_indent[EI_VERSION]', 0x00000001) +; 32: ('_sections', [ +; 32: # Section 0 +; 32: (('sh_name', 0x00000000) # '' + +; 32: # '.text' + +; 32: ('st_bind', 0x00000000) +; 32: ('st_type', 0x00000003) + +; 32: ('st_bind', 0x00000000) +; 32: ('st_type', 0x00000003) + +; 32: ('st_bind', 0x00000000) +; 32: ('st_type', 0x00000003) + +; 32: # 'main' +; 32: ('st_bind', 0x00000001) +; 32-NEXT: ('st_type', 0x00000002) + +; 32: # 'puts' +; 32: ('st_bind', 0x00000001) +; 32-NEXT: ('st_type', 0x00000000) + +; 32: # '.rel.text' + +; 32: ('_relocations', [ +; 32: # Relocation 0x00000000 +; 32: (('r_offset', 0x00000006) +; 32: ('r_type', 0x00000001) +; 32: ), +; 32: # Relocation 0x00000001 +; 32: (('r_offset', 0x0000000b) +; 32: ('r_type', 0x00000002) +; 32: ), +; 32: # Relocation 0x00000002 +; 32: (('r_offset', 0x00000012) +; 32: ('r_type', 0x00000001) +; 32: ), +; 32: # Relocation 0x00000003 +; 32: (('r_offset', 0x00000017) +; 32: ('r_type', 0x00000002) +; 32: ), +; 32: ]) + +; 64: ('e_indent[EI_CLASS]', 0x00000002) +; 64: ('e_indent[EI_DATA]', 0x00000001) +; 64: ('e_indent[EI_VERSION]', 0x00000001) +; 64: ('_sections', [ +; 64: # Section 0 +; 64: (('sh_name', 0x00000000) # '' + +; 64: # '.text' + +; 64: ('st_bind', 0x00000000) +; 64: ('st_type', 0x00000003) + +; 64: ('st_bind', 0x00000000) +; 64: ('st_type', 0x00000003) + +; 64: ('st_bind', 0x00000000) +; 64: ('st_type', 0x00000003) + +; 64: # 'main' +; 64-NEXT: ('st_bind', 0x00000001) +; 64-NEXT: ('st_type', 0x00000002) + +; 64: # 'puts' +; 64-NEXT: ('st_bind', 0x00000001) +; 64-NEXT: ('st_type', 0x00000000) + +; 64: # '.rela.text' + +; 64: ('_relocations', [ +; 64: # Relocation 0x00000000 +; 64: (('r_offset', 0x00000005) +; 64: ('r_type', 0x0000000a) +; 64: ('r_addend', 0x00000000) +; 64: ), +; 64: # Relocation 0x00000001 +; 64: (('r_offset', 0x0000000a) +; 64: ('r_type', 0x00000002) +; 64: ('r_addend', 0xfffffffc) +; 64: ), +; 64: # Relocation 0x00000002 +; 64: (('r_offset', 0x0000000f) +; 64: ('r_type', 0x0000000a) +; 64: ('r_addend', 0x00000006) +; 64: ), +; 64: # Relocation 0x00000003 +; 64: (('r_offset', 0x00000014) +; 64: ('r_type', 0x00000002) +; 64: ('r_addend', 0xfffffffc) +; 64: ), +; 64: ]) diff --git a/test/MC/ELF/comdat.s b/test/MC/ELF/comdat.s new file mode 100644 index 0000000..745dfbb --- /dev/null +++ b/test/MC/ELF/comdat.s @@ -0,0 +1,86 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that we produce the group sections and that they are a the beginning +// of the file. + +// CHECK: # Section 0x00000001 +// CHECK-NEXT: (('sh_name', 0x00000026) # '.group' +// CHECK-NEXT: ('sh_type', 0x00000011) +// CHECK-NEXT: ('sh_flags', 0x00000000) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x0000000c) +// CHECK-NEXT: ('sh_link', 0x0000000c) +// CHECK-NEXT: ('sh_info', 0x00000001) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000004) +// CHECK-NEXT: ), +// CHECK-NEXT: # Section 0x00000002 +// CHECK-NEXT: (('sh_name', 0x00000026) # '.group' +// CHECK-NEXT: ('sh_type', 0x00000011) +// CHECK-NEXT: ('sh_flags', 0x00000000) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x0000004c) +// CHECK-NEXT: ('sh_size', 0x00000008) +// CHECK-NEXT: ('sh_link', 0x0000000c) +// CHECK-NEXT: ('sh_info', 0x00000002) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000004) +// CHECK-NEXT: ), +// CHECK-NEXT: # Section 0x00000003 +// CHECK-NEXT: (('sh_name', 0x00000026) # '.group' +// CHECK-NEXT: ('sh_type', 0x00000011) +// CHECK-NEXT: ('sh_flags', 0x00000000) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000054) +// CHECK-NEXT: ('sh_size', 0x00000008) +// CHECK-NEXT: ('sh_link', 0x0000000c) +// CHECK-NEXT: ('sh_info', 0x0000000d) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000004) +// CHECK-NEXT: ), + +// Test that g1 and g2 are local, but g3 is an undefined global. + +// CHECK: # Symbol 0x00000001 +// CHECK-NEXT: (('st_name', 0x00000001) # 'g1' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000007) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000002 +// CHECK-NEXT: (('st_name', 0x00000004) # 'g2' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000002) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), + +// CHECK: # Symbol 0x0000000d +// CHECK-NEXT: (('st_name', 0x00000007) # 'g3' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), + + + .section .foo,"axG",@progbits,g1,comdat +g1: + nop + + .section .bar,"axG",@progbits,g1,comdat + nop + + .section .zed,"axG",@progbits,g2,comdat + nop + + .section .baz,"axG",@progbits,g3,comdat + .long g3 diff --git a/test/MC/ELF/common.s b/test/MC/ELF/common.s new file mode 100644 index 0000000..0ffa6f4 --- /dev/null +++ b/test/MC/ELF/common.s @@ -0,0 +1,88 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + + + .text + +// Test that this produces a regular local symbol. + .type common1,@object + .local common1 + .comm common1,1,1 + +// CHECK: ('st_name', 0x00000001) # 'common1' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000001) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000001) + + +// Same as common1, but with directives in a different order. + .local common2 + .type common2,@object + .comm common2,1,1 + +// CHECK: ('st_name', 0x00000009) # 'common2' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000001) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', +// CHECK-NEXT: ('st_value', 0x00000001) +// CHECK-NEXT: ('st_size', 0x00000001) + + .local common6 + .comm common6,8,16 + +// CHECK: # Symbol 0x00000003 +// CHECK-NEXT: (('st_name', 0x00000011) # 'common6' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000001) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000003) +// CHECK-NEXT: ('st_value', 0x00000010) +// CHECK-NEXT: ('st_size', 0x00000008) +// CHECK-NEXT: ), + +// Test that without an explicit .local we produce a global. + .type common3,@object + .comm common3,4,4 + +// CHECK: ('st_name', 0x00000019) # 'common3' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000001) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x0000fff2) +// CHECK-NEXT: ('st_value', 0x00000004) +// CHECK-NEXT: ('st_size', 0x00000004) + + +// Test that without an explicit .local we produce a global, even if the first +// occurrence is not in a directive. + .globl foo + .type foo,@function +foo: + movsbl common4+3(%rip), %eax + + + .type common4,@object + .comm common4,40,16 + +// CHECK: ('st_name', 0x00000025) # 'common4' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000001) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x0000fff2) +// CHECK-NEXT: ('st_value', 0x00000010) +// CHECK-NEXT: ('st_size', 0x00000028) + + .comm common5,4,4 + +// CHECK: # Symbol 0x00000009 +// CHECK-NEXT: (('st_name', 0x0000002d) # 'common5' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000001) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x0000fff2) +// CHECK-NEXT: ('st_value', 0x00000004) +// CHECK-NEXT: ('st_size', 0x00000004) +// CHECK-NEXT: ), diff --git a/test/MC/ELF/common2.s b/test/MC/ELF/common2.s new file mode 100644 index 0000000..b54cdfe --- /dev/null +++ b/test/MC/ELF/common2.s @@ -0,0 +1,21 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that the common symbols are placed at the end of .bss. In this example +// it causes .bss to have size 9 instead of 8. + + .local vimvardict + .comm vimvardict,1,8 + .bss + .zero 1 + .align 8 + +// CHECK: (('sh_name', 0x0000000d) # '.bss' +// CHECK-NEXT: ('sh_type', +// CHECK-NEXT: ('sh_flags' +// CHECK-NEXT: ('sh_addr', +// CHECK-NEXT: ('sh_offset', +// CHECK-NEXT: ('sh_size', 0x00000009) +// CHECK-NEXT: ('sh_link', +// CHECK-NEXT: ('sh_info', +// CHECK-NEXT: ('sh_addralign', +// CHECK-NEXT: ('sh_entsize', diff --git a/test/MC/ELF/debug-line.s b/test/MC/ELF/debug-line.s new file mode 100644 index 0000000..2979ca2 --- /dev/null +++ b/test/MC/ELF/debug-line.s @@ -0,0 +1,22 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +// Test that .debug_line is populated. + +// CHECK: (('sh_name', 0x00000012) # '.debug_line' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000000) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000044) +// CHECK-NEXT: ('sh_size', 0x00000037) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ('_section_data', '33000000 02001c00 00000101 fb0e0d00 01010101 00000001 00000100 666f6f2e 63000000 00000009 02000000 00000000 00150204 000101') + + .section .debug_line,"",@progbits + .text + + .file 1 "foo.c" + .loc 1 4 0 + subq $8, %rsp diff --git a/test/MC/ELF/debug-loc.s b/test/MC/ELF/debug-loc.s new file mode 100644 index 0000000..36ae485 --- /dev/null +++ b/test/MC/ELF/debug-loc.s @@ -0,0 +1,32 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that we don't regress on the size of the line info section. We used +// to handle negative line diffs incorrectly which manifested as very +// large integers being passed to DW_LNS_advance_line. + +// FIXME: This size is the same as gnu as, but we can probably do a bit better. +// FIXME2: We need a debug_line dumper so that we can test the actual contents. + +// CHECK: # Section 0x00000004 +// CHECK-NEXT: (('sh_name', 0x00000012) # '.debug_line' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000000) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000044) +// CHECK-NEXT: ('sh_size', 0x0000003d) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ), + + .section .debug_line,"",@progbits + .text +foo: + .file 1 "Driver.ii" + .loc 1 2 0 + nop + .loc 1 4 0 + nop + .loc 1 3 0 + nop diff --git a/test/MC/ELF/dg.exp b/test/MC/ELF/dg.exp index 7b7bd4e..d46d700 100644 --- a/test/MC/ELF/dg.exp +++ b/test/MC/ELF/dg.exp @@ -1,5 +1,5 @@ load_lib llvm.exp if { [llvm_supports_target X86] } { - RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll}]] + RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,s}]] } diff --git a/test/MC/ELF/diff.s b/test/MC/ELF/diff.s new file mode 100644 index 0000000..1879a39 --- /dev/null +++ b/test/MC/ELF/diff.s @@ -0,0 +1,15 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + + .global zed +foo: + nop +bar: + nop +zed: + mov zed+(bar-foo), %eax + +// CHECK: # Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', 0x00000005) +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x0000000b) +// CHECK-NEXT: ('r_addend', 0x00000001) diff --git a/test/MC/ELF/diff2.s b/test/MC/ELF/diff2.s new file mode 100644 index 0000000..4a9fbd1 --- /dev/null +++ b/test/MC/ELF/diff2.s @@ -0,0 +1,13 @@ +// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s 2> %t +// RUN: FileCheck -input-file %t %s + +.global zed + .data +foo: + .text + nop +bar: + nop +zed: +// CHECK: expected relocatable expression + mov zed+(bar-foo), %eax diff --git a/test/MC/ELF/elf_directive_previous.s b/test/MC/ELF/elf_directive_previous.s new file mode 100644 index 0000000..5db1eac --- /dev/null +++ b/test/MC/ELF/elf_directive_previous.s @@ -0,0 +1,13 @@ +# RUN: llvm-mc -triple i386-pc-linux-gnu %s | FileCheck %s + +.bss +# CHECK: .bss + +.text +# CHECK: .text + +.previous +# CHECK: .bss + +.previous +# CHECK: .text diff --git a/test/MC/ELF/elf_directive_section.s b/test/MC/ELF/elf_directive_section.s new file mode 100644 index 0000000..9531c02 --- /dev/null +++ b/test/MC/ELF/elf_directive_section.s @@ -0,0 +1,23 @@ +# RUN: llvm-mc -triple i386-pc-linux-gnu %s | FileCheck %s + + .bss +# CHECK: .bss + + .data.rel.ro +# CHECK: .data.rel.ro + + .data.rel +# CHECK: .data.rel + + .eh_frame +# CHECK: .eh_frame + + .rodata +# CHECK: .rodata + + .tbss +# CHECK: .tbss + + .tdata +# CHECK: .tdata + diff --git a/test/MC/ELF/empty.s b/test/MC/ELF/empty.s new file mode 100644 index 0000000..e351936 --- /dev/null +++ b/test/MC/ELF/empty.s @@ -0,0 +1,70 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that like gnu as we create text, data and bss by default. Also test +// that shstrtab, symtab and strtab are listed in that order. + +// CHECK: ('sh_name', 0x00000001) # '.text' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000006) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x00000000) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000000) + +// CHECK: ('sh_name', 0x00000007) # '.data' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000003) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x00000000) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000000) + +// CHECK: ('sh_name', 0x0000000d) # '.bss' +// CHECK-NEXT: ('sh_type', 0x00000008) +// CHECK-NEXT: ('sh_flags', 0x00000003) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x00000000) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000000) + +// CHECK: ('sh_name', 0x00000012) # '.shstrtab' +// CHECK-NEXT: ('sh_type', 0x00000003) +// CHECK-NEXT: ('sh_flags', 0x00000000) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x0000002c) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000000) + +// CHECK: ('sh_name', 0x0000001c) # '.symtab' +// CHECK-NEXT: ('sh_type', 0x00000002) +// CHECK-NEXT: ('sh_flags', 0x00000000) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', +// CHECK-NEXT: ('sh_size', 0x00000060) +// CHECK-NEXT: ('sh_link', 0x00000006) +// CHECK-NEXT: ('sh_info', 0x00000004) +// CHECK-NEXT: ('sh_addralign', 0x00000008) +// CHECK-NEXT: ('sh_entsize', 0x00000018) + +// CHECK: ('sh_name', 0x00000024) # '.strtab' +// CHECK-NEXT: ('sh_type', 0x00000003) +// CHECK-NEXT: ('sh_flags', 0x00000000) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', +// CHECK-NEXT: ('sh_size', 0x00000001) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000000) diff --git a/test/MC/ELF/entsize.ll b/test/MC/ELF/entsize.ll new file mode 100644 index 0000000..62683af --- /dev/null +++ b/test/MC/ELF/entsize.ll @@ -0,0 +1,44 @@ +; RUN: llc -filetype=obj -mtriple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck -check-prefix=64 %s + +; Test that constant mergeable strings have sh_entsize set. + +@.str1 = private constant [6 x i8] c"tring\00" +@.str2 = private constant [7 x i8] c"String\00" +@.c8a = private constant [1 x i64] [i64 42] +@.c8b = private constant [1 x i64] [i64 42] + +define i32 @main() nounwind { + %1 = call i32 @puts(i8* getelementptr inbounds ([6 x i8]* @.str1, i32 0, i32 0)) + %2 = call i32 @puts(i8* getelementptr inbounds ([7 x i8]* @.str2, i32 0, i32 0)) + call void @foo(i64* getelementptr inbounds ([1 x i64]* @.c8a, i32 0, i32 0)) + call void @foo(i64* getelementptr inbounds ([1 x i64]* @.c8b, i32 0, i32 0)) + ret i32 0 +} + +declare i32 @puts(i8* nocapture) nounwind +declare void @foo(i64* nocapture) nounwind + +;;;;; + +; 64: (('sh_name', 0x00000012) # '.rodata.str1.1' +; 64-NEXT: ('sh_type', 0x00000001) +; 64-NEXT: ('sh_flags', 0x00000032) +; 64-NEXT: ('sh_addr', +; 64-NEXT: ('sh_offset', +; 64-NEXT: ('sh_size', 0x0000000d) +; 64-NEXT: ('sh_link', +; 64-NEXT: ('sh_info', +; 64-NEXT: ('sh_addralign', 0x00000001) +; 64-NEXT: ('sh_entsize', 0x00000001) + +; 64: (('sh_name', 0x00000021) # '.rodata.cst8' +; 64-NEXT: ('sh_type', 0x00000001) +; 64-NEXT: ('sh_flags', 0x00000012) +; 64-NEXT: ('sh_addr', +; 64-NEXT: ('sh_offset', +; 64-NEXT: ('sh_size', 0x00000010) +; 64-NEXT: ('sh_link', +; 64-NEXT: ('sh_info', +; 64-NEXT: ('sh_addralign', 0x00000008) +; 64-NEXT: ('sh_entsize', 0x00000008) + diff --git a/test/MC/ELF/entsize.s b/test/MC/ELF/entsize.s new file mode 100644 index 0000000..e8eb62e --- /dev/null +++ b/test/MC/ELF/entsize.s @@ -0,0 +1,69 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +// Test that mergeable constants have sh_entsize set. + +// 1 byte strings + .section .rodata.str1.1,"aMS",@progbits,1 + + .type .L.str1,@object # @.str1 +.L.str1: + .asciz "tring" + .size .L.str1, 6 + + .type .L.str2,@object # @.str2 +.L.str2: + .asciz "String" + .size .L.str2, 7 + +// 2 byte strings + .section .rodata.str2.1,"aMS",@progbits,2 + .type .L.str3,@object # @.str3 +.L.str3: + .asciz "L\000o\000n\000g\000" + .size .L.str3, 9 + + .type .L.str4,@object # @.str4 +.L.str4: + .asciz "o\000n\000g\000" + .size .L.str4, 7 + + // 8 byte constants + .section .rodata.cst8,"aM",@progbits,8 + .quad 42 + .quad 42 + +// CHECK: # Section 0x00000004 +// CHECK-NEXT: ('sh_name', 0x00000012) # '.rodata.str1.1' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000032) +// CHECK-NEXT: ('sh_addr', +// CHECK-NEXT: ('sh_offset', +// CHECK-NEXT: ('sh_size', 0x0000000d) +// CHECK-NEXT: ('sh_link', +// CHECK-NEXT: ('sh_info', +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000001) + +// CHECK: # Section 0x00000005 +// CHECK-NEXT: ('sh_name', 0x00000021) # '.rodata.str2.1' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000032) +// CHECK-NEXT: ('sh_addr', +// CHECK-NEXT: ('sh_offset', +// CHECK-NEXT: ('sh_size', 0x00000010) +// CHECK-NEXT: ('sh_link', +// CHECK-NEXT: ('sh_info', +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000002) + +// CHECK: # Section 0x00000006 +// CHECK-NEXT: ('sh_name', 0x00000030) # '.rodata.cst8 +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000012) +// CHECK-NEXT: ('sh_addr', +// CHECK-NEXT: ('sh_offset', +// CHECK-NEXT: ('sh_size', 0x00000010) +// CHECK-NEXT: ('sh_link', +// CHECK-NEXT: ('sh_info', +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000008) diff --git a/test/MC/ELF/file.s b/test/MC/ELF/file.s new file mode 100644 index 0000000..8dd72a7 --- /dev/null +++ b/test/MC/ELF/file.s @@ -0,0 +1,23 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that the STT_FILE symbol precedes the other local symbols. + +.file "foo" +foa: +// CHECK: # Symbol 0x00000001 +// CHECK-NEXT: (('st_name', 0x00000001) # 'foo' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000004) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x0000fff1) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000002 +// CHECK-NEXT: (('st_name', 0x00000005) # 'foa' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) diff --git a/test/MC/ELF/global-offset.s b/test/MC/ELF/global-offset.s new file mode 100644 index 0000000..aa63287 --- /dev/null +++ b/test/MC/ELF/global-offset.s @@ -0,0 +1,18 @@ +// RUN: llvm-mc -filetype=obj -triple i386-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +// We test that _GLOBAL_OFFSET_TABLE_ will account for the two bytes at the +// start of the addl. + + addl $_GLOBAL_OFFSET_TABLE_, %ebx + +// CHECK: ('sh_name', 0x00000001) # '.text' +// CHECK-NEXT: ('sh_type', +// CHECK-NEXT: ('sh_flags', +// CHECK-NEXT: ('sh_addr', +// CHECK-NEXT: ('sh_offset', +// CHECK-NEXT: ('sh_size', +// CHECK-NEXT: ('sh_link', +// CHECK-NEXT: ('sh_info', +// CHECK-NEXT: ('sh_addralign', +// CHECK-NEXT: ('sh_entsize', +// CHECK-NEXT: ('_section_data', '81c30200 0000') diff --git a/test/MC/ELF/got.s b/test/MC/ELF/got.s new file mode 100644 index 0000000..798150e --- /dev/null +++ b/test/MC/ELF/got.s @@ -0,0 +1,25 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that this produces a R_X86_64_GOT32 and that we have an undefined +// reference to _GLOBAL_OFFSET_TABLE_. + + movl foo@GOT, %eax + movl foo@GOTPCREL(%rip), %eax + +// CHECK: (('st_name', 0x00000005) # '_GLOBAL_OFFSET_TABLE_' +// CHECK-NEXT: ('st_bind', 0x00000001) + +// CHECK: ('_relocations', [ +// CHECK-NEXT: # Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', +// CHECK-NEXT: ('r_type', 0x00000003) +// CHECK-NEXT: ('r_addend', +// CHECK-NEXT: ), +// CHECK-NEXT: # Relocation 0x00000001 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', +// CHECK-NEXT: ('r_type', 0x00000009) +// CHECK-NEXT: ('r_addend', +// CHECK-NEXT: ), +// CHECK-NEXT: ]) diff --git a/test/MC/ELF/ident.s b/test/MC/ELF/ident.s new file mode 100644 index 0000000..f79458f --- /dev/null +++ b/test/MC/ELF/ident.s @@ -0,0 +1,17 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +// CHECK: (('sh_name', 0x00000012) # '.comment' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000030) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x0000000d) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000001) +// CHECK-NEXT: ('_section_data', '00666f6f 00626172 007a6564 00') + + .ident "foo" + .ident "bar" + .ident "zed" diff --git a/test/MC/ELF/invalid-symver.s b/test/MC/ELF/invalid-symver.s new file mode 100644 index 0000000..3c4f8c0 --- /dev/null +++ b/test/MC/ELF/invalid-symver.s @@ -0,0 +1,7 @@ +// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t 2> %t.out +// RUN: FileCheck --input-file=%t.out %s + +// CHECK: A @@ version cannot be undefined + + .symver undefined, foo@@bar + .long undefined diff --git a/test/MC/ELF/leb128.s b/test/MC/ELF/leb128.s new file mode 100644 index 0000000..e5f31f4 --- /dev/null +++ b/test/MC/ELF/leb128.s @@ -0,0 +1,19 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + + .sleb128 .Lfoo - .Lbar +.Lfoo: + .uleb128 .Lbar - .Lfoo + .fill 126, 1, 0x90 +.Lbar: + +// CHECK: (('sh_name', 0x00000001) # '.text' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000006) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x00000081) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ('_section_data', '817f7f90 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90909090 90') diff --git a/test/MC/ELF/local-reloc.s b/test/MC/ELF/local-reloc.s new file mode 100644 index 0000000..d275646 --- /dev/null +++ b/test/MC/ELF/local-reloc.s @@ -0,0 +1,31 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +// Test that relocations with local symbols are represented as relocations +// with the section. They should be equivalent, but gas behaves like this. + + movl foo, %r14d +foo: + +// Section number 1 is .text +// CHECK: # Section 0x00000001 +// CHECK-next: (('sh_name', 0x00000001) # '.text' + +// Symbol number 2 is section number 1 +// CHECK: # Symbol 0x00000002 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000003) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) + +// Relocation refers to symbol number 2 +// CHECK: ('_relocations', [ +// CHECK-NEXT: # Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', 0x00000002) +// CHECK-NEXT: ('r_type', +// CHECK-NEXT: ('r_addend', +// CHECK-NEXT: ), +// CHECK-NEXT: ]) diff --git a/test/MC/ELF/merge.s b/test/MC/ELF/merge.s new file mode 100644 index 0000000..ec02228 --- /dev/null +++ b/test/MC/ELF/merge.s @@ -0,0 +1,97 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +// Test that PIC relocations with local symbols in a mergeable section are done +// with a reference to the symbol. Not sure if this is a linker limitation, +// but this matches the behavior of gas. + +// Non-PIC relocations with 0 offset don't use the symbol. + + + movsd .Lfoo(%rip), %xmm1 + movl $.Lfoo, %edi + movl $.Lfoo+2, %edi + jmp foo@PLT + movq foo@GOTPCREL, %rax + movq zed, %rax + + .section .sec1,"aM",@progbits,16 +.Lfoo: +zed: + .global zed + + .section bar,"ax",@progbits +foo: + +// Section 4 is "sec1" +// CHECK: # Section 0x00000004 +// CHECK-NEXT: (('sh_name', 0x00000012) # '.sec1' + +// Symbol number 1 is .Lfoo +// CHECK: # Symbol 0x00000001 +// CHECK-NEXT: (('st_name', 0x00000001) # '.Lfoo' + +// Symbol number 2 is foo +// CHECK: # Symbol 0x00000002 +// CHECK-NEXT: (('st_name', 0x00000007) # 'foo' + +// Symbol number 6 is section 4 +// CHECK: # Symbol 0x00000006 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000003) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000004) + +// Symbol number 8 is zed +// CHECK: # Symbol 0x00000008 +// CHECK-NEXT: (('st_name', 0x0000000b) # 'zed' + +// Relocation 0 refers to symbol 1 +// CHECK: ('_relocations', [ +// CHECK-NEXT: # Relocation 0 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', 0x00000001) +// CHECK-NEXT: ('r_type', 0x00000002 +// CHECK-NEXT: ('r_addend', +// CHECK-NEXT: ), + +// Relocation 1 refers to symbol 6 +// CHECK-NEXT: # Relocation 0x00000001 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x0000000a) +// CHECK-NEXT: ('r_addend', +// CHECK-NEXT: ), + +// Relocation 2 refers to symbol 1 +// CHECK-NEXT: # Relocation 0x00000002 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', 0x00000001) +// CHECK-NEXT: ('r_type', 0x0000000a +// CHECK-NEXT: ('r_addend', +// CHECK-NEXT: ), + +// Relocation 3 refers to symbol 2 +// CHECK-NEXT: # Relocation 0x00000003 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', 0x00000002) +// CHECK-NEXT: ('r_type', 0x00000004 +// CHECK-NEXT: ('r_addend', +// CHECK-NEXT: ), + +// Relocation 4 refers to symbol 2 +// CHECK-NEXT: # Relocation 0x00000004 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', 0x00000002) +// CHECK-NEXT: ('r_type', 0x00000009 +// CHECK-NEXT: ('r_addend', +// CHECK-NEXT: ), + +// Relocation 5 refers to symbol 8 +// CHECK-NEXT: # Relocation 0x00000005 +// CHECK-NEXT: (('r_offset', 0x00000023) +// CHECK-NEXT: ('r_sym', 0x00000008) +// CHECK-NEXT: ('r_type', 0x0000000b) +// CHECK-NEXT: ('r_addend', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: ]) diff --git a/test/MC/ELF/norelocation.s b/test/MC/ELF/norelocation.s new file mode 100644 index 0000000..0a0efe1 --- /dev/null +++ b/test/MC/ELF/norelocation.s @@ -0,0 +1,18 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + + call bar +bar: + +// CHECK: ('sh_name', 0x00000001) # '.text' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000006) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x00000005) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ('_section_data', 'e8000000 00') +// CHECK-NOT: .rela.text +// CHECK: shstrtab diff --git a/test/MC/ELF/pic-diff.s b/test/MC/ELF/pic-diff.s new file mode 100644 index 0000000..b47c413 --- /dev/null +++ b/test/MC/ELF/pic-diff.s @@ -0,0 +1,29 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// CHECK: # Symbol 0x00000005 +// CHECK-NEXT: (('st_name', 0x00000005) # 'baz' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), + +// CHECK: ('_relocations', [ +// CHECK-NEXT: # Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', 0x0000000c) +// CHECK-NEXT: ('r_sym', 0x00000005) +// CHECK-NEXT: ('r_type', 0x00000002) +// CHECK-NEXT: ('r_addend', 0x00000008) +// CHECK-NEXT: ), +// CHECK-NEXT: ]) + +.zero 4 +.data + +.zero 1 +.align 4 +foo: +.zero 8 +.long baz - foo diff --git a/test/MC/ELF/plt.s b/test/MC/ELF/plt.s new file mode 100644 index 0000000..7d0073c --- /dev/null +++ b/test/MC/ELF/plt.s @@ -0,0 +1,14 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that this produces a R_X86_64_PLT32. + + jmp foo@PLT + +// CHECK: ('_relocations', [ +// CHECK-NEXT: # Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', +// CHECK-NEXT: ('r_type', 0x00000004) +// CHECK-NEXT: ('r_addend', +// CHECK-NEXT: ), +// CHECK-NEXT: ]) diff --git a/test/MC/ELF/relax-arith.s b/test/MC/ELF/relax-arith.s new file mode 100644 index 0000000..3236b41 --- /dev/null +++ b/test/MC/ELF/relax-arith.s @@ -0,0 +1,75 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +// Test that we correctly relax these instructions into versions that use +// 16 or 32 bit immediate values. + +bar: +// CHECK: 'imul' +// CHECK: ('_section_data', '6669db00 0066691c 25000000 00000069 db000000 00691c25 00000000 00000000 4869db00 00000048 691c2500 00000000 000000') + .section imul + imul $foo, %bx, %bx + imul $foo, bar, %bx + imul $foo, %ebx, %ebx + imul $foo, bar, %ebx + imul $foo, %rbx, %rbx + imul $foo, bar, %rbx + +// CHECK: and' +// CHECK:('_section_data', '6681e300 00668124 25000000 00000081 e3000000 00812425 00000000 00000000 4881e300 00000048 81242500 00000000 000000') + .section and + and $foo, %bx + andw $foo, bar + and $foo, %ebx + andl $foo, bar + and $foo, %rbx + andq $foo, bar + +// CHECK: 'or' +// CHECK: ('_section_data', '6681cb00 0066810c 25000000 00000081 cb000000 00810c25 00000000 00000000 4881cb00 00000048 810c2500 00000000 000000') + .section or + or $foo, %bx + orw $foo, bar + or $foo, %ebx + orl $foo, bar + or $foo, %rbx + orq $foo, bar + +// CHECK: 'xor' +// CHECK: ('_section_data', '6681f300 00668134 25000000 00000081 f3000000 00813425 00000000 00000000 4881f300 00000048 81342500 00000000 000000') + .section xor + xor $foo, %bx + xorw $foo, bar + xor $foo, %ebx + xorl $foo, bar + xor $foo, %rbx + xorq $foo, bar + +// CHECK: 'add' +// CHECK: ('_section_data', '6681c300 00668104 25000000 00000081 c3000000 00810425 00000000 00000000 4881c300 00000048 81042500 00000000 000000') + .section add + add $foo, %bx + addw $foo, bar + add $foo, %ebx + addl $foo, bar + add $foo, %rbx + addq $foo, bar + +// CHECK: 'sub' +// CHECK: ('_section_data', '6681eb00 0066812c 25000000 00000081 eb000000 00812c25 00000000 00000000 4881eb00 00000048 812c2500 00000000 000000') + .section sub + sub $foo, %bx + subw $foo, bar + sub $foo, %ebx + subl $foo, bar + sub $foo, %rbx + subq $foo, bar + +// CHECK: 'cmp' +// CHECK: ('_section_data', '6681fb00 0066813c 25000000 00000081 fb000000 00813c25 00000000 00000000 4881fb00 00000048 813c2500 00000000 000000') + .section cmp + cmp $foo, %bx + cmpw $foo, bar + cmp $foo, %ebx + cmpl $foo, bar + cmp $foo, %rbx + cmpq $foo, bar diff --git a/test/MC/ELF/relax-crash.s b/test/MC/ELF/relax-crash.s new file mode 100644 index 0000000..442825d --- /dev/null +++ b/test/MC/ELF/relax-crash.s @@ -0,0 +1,11 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t + +// This is a test that we don't crash. We used to do so by going in a infinite +// recursion trying to compute the size of a MCDwarfLineAddrFragment. + + .section .debug_line,"",@progbits + .text + .file 1 "Disassembler.ii" + .section foo + .loc 1 1 0 + ret diff --git a/test/MC/ELF/relax.s b/test/MC/ELF/relax.s new file mode 100644 index 0000000..48b9c4e --- /dev/null +++ b/test/MC/ELF/relax.s @@ -0,0 +1,38 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +// Test that we do a relaxation for foo but not for bar. Relaxing foo is +// probably not necessary, but matches what gnu as does. + +// Also test that the relaxation done for foo uses the symbol, not section and +// offset. + +bar: +.globl foo +foo: + jmp bar + jmp foo + +// CHECK: ('sh_name', 0x00000001) # '.text' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000006) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x00000007) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ('_section_data', 'ebfee900 000000') + +// CHECK: # Symbol 0x00000005 +// CHECK-NEXT: (('st_name', 0x00000005) # 'foo' + +// CHECK: .rela.text +// CHECK: ('_relocations', [ +// CHECK-NEXT: Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', 0x00000003) +// CHECK-NEXT: ('r_sym', 0x00000005) +// CHECK-NEXT: ('r_type', 0x00000002) +// CHECK-NEXT: ('r_addend', 0xfffffffc) +// CHECK-NEXT: ), +// CHECK-NEXT: ]) diff --git a/test/MC/ELF/relocation-386.s b/test/MC/ELF/relocation-386.s new file mode 100644 index 0000000..c390323 --- /dev/null +++ b/test/MC/ELF/relocation-386.s @@ -0,0 +1,128 @@ +// RUN: llvm-mc -filetype=obj -triple i386-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that we produce the correct relocation types and that the relocation +// to .Lfoo uses the symbol and not the section. + +// Section 3 is bss +// CHECK: # Section 0x00000003 +// CHECK-NEXT: (('sh_name', 0x0000000d) # '.bss' + +// CHECK: # Symbol 0x00000001 +// CHECK-NEXT: (('st_name', 0x00000005) # '.Lfoo' + +// Symbol 6 is section 3 +// CHECK: # Symbol 0x00000006 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000003) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000003) + +// CHECK: # Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', 0x00000002) +// CHECK-NEXT: ('r_sym', 0x00000001) +// CHECK-NEXT: ('r_type', 0x00000009) +// CHECK-NEXT: ), +// CHECK-NEXT: # Relocation 0x00000001 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', +// CHECK-NEXT: ('r_type', 0x00000004) +// CHECK-NEXT: ), +// CHECK-NEXT: # Relocation 0x00000002 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', +// CHECK-NEXT: ('r_type', 0x0000000a) +// CHECK-NEXT: ), + +// Relocation 3 (bar3@GOTOFF) is done with symbol 6 (bss) +// CHECK-NEXT: # Relocation 0x00000003 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', 0x00000006 +// CHECK-NEXT: ('r_type', +// CHECK-NEXT: ), + +// Relocation 4 (bar2@GOT) is of type R_386_GOT32 +// CHECK-NEXT: # Relocation 0x00000004 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', +// CHECK-NEXT: ('r_type', 0x00000003 +// CHECK-NEXT: ), + +// Relocation 5 (foo@TLSGD) is of type R_386_TLS_GD +// CHECK-NEXT: # Relocation 0x00000005 +// CHECK-NEXT: (('r_offset', 0x00000020) +// CHECK-NEXT: ('r_sym', 0x0000000b) +// CHECK-NEXT: ('r_type', 0x00000012) +// CHECK-NEXT: ), + +// Relocation 6 ($foo@TPOFF) is of type R_386_TLS_LE_32 +// CHECK-NEXT: # Relocation 0x00000006 +// CHECK-NEXT: (('r_offset', 0x00000025) +// CHECK-NEXT: ('r_sym', 0x0000000b) +// CHECK-NEXT: ('r_type', 0x00000022) +// CHECK-NEXT: ), + +// Relocation 7 (foo@INDNTPOFF) is of type R_386_TLS_IE +// CHECK-NEXT: # Relocation 0x00000007 +// CHECK-NEXT: (('r_offset', 0x0000002b) +// CHECK-NEXT: ('r_sym', 0x0000000b) +// CHECK-NEXT: ('r_type', 0x0000000f) +// CHECK-NEXT: ), + +// Relocation 8 (foo@NTPOFF) is of type R_386_TLS_LE +// CHECK-NEXT: # Relocation 0x00000008 +// CHECK-NEXT: (('r_offset', 0x00000031) +// CHECK-NEXT: ('r_sym', 0x0000000b) +// CHECK-NEXT: ('r_type', 0x00000011) +// CHECK-NEXT: ), + +// Relocation 9 (foo@GOTNTPOFF) is of type R_386_TLS_GOTIE +// CHECK-NEXT: # Relocation 0x00000009 +// CHECK-NEXT: (('r_offset', 0x00000037) +// CHECK-NEXT: ('r_sym', 0x0000000b) +// CHECK-NEXT: ('r_type', 0x00000010) +// CHECK-NEXT: ), + +// Relocation 10 (foo@TLSLDM) is of type R_386_TLS_LDM +// CHECK-NEXT: # Relocation 0x0000000a +// CHECK-NEXT: (('r_offset', 0x0000003d) +// CHECK-NEXT: ('r_sym', 0x0000000b) +// CHECK-NEXT: ('r_type', 0x00000013) +// CHECK-NEXT: ), + +// Relocation 11 (foo@DTPOFF) is of type R_386_TLS_LDO_32 +// CHECK-NEXT: # Relocation 0x0000000b +// CHECK-NEXT: (('r_offset', 0x00000043) +// CHECK-NEXT: ('r_sym', 0x0000000b) +// CHECK-NEXT: ('r_type', 0x00000020) +// CHECK-NEXT: ), + + .text +bar: + leal .Lfoo@GOTOFF(%ebx), %eax + + .global bar2 +bar2: + calll bar2@PLT + addl $_GLOBAL_OFFSET_TABLE_, %ebx + movb bar3@GOTOFF(%ebx), %al + + .type bar3,@object + .local bar3 + .comm bar3,1,1 + + movl bar2j@GOT(%eax), %eax + + leal foo@TLSGD(, %ebx,1), %eax + movl $foo@TPOFF, %edx + movl foo@INDNTPOFF, %ecx + addl foo@NTPOFF(%eax), %eax + addl foo@GOTNTPOFF(%ebx), %ecx + leal foo@TLSLDM(%ebx), %eax + leal foo@DTPOFF(%eax), %edx + + .section .rodata.str1.16,"aMS",@progbits,1 +.Lfoo: + .asciz "bool llvm::llvm_start_multithreaded()" diff --git a/test/MC/ELF/relocation.s b/test/MC/ELF/relocation.s new file mode 100644 index 0000000..8d38b86 --- /dev/null +++ b/test/MC/ELF/relocation.s @@ -0,0 +1,92 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +// Test that we produce the correct relocation. + +bar: + movl $bar, %edx # R_X86_64_32 + movq $bar, %rdx # R_X86_64_32S + movq $bar, bar(%rip) # R_X86_64_32S + movl bar, %edx # R_X86_64_32S + movq bar, %rdx # R_X86_64_32S +.long bar # R_X86_64_32 + leaq foo@GOTTPOFF(%rip), %rax # R_X86_64_GOTTPOFF + leaq foo@TLSGD(%rip), %rax # R_X86_64_TLSGD + leaq foo@TPOFF(%rax), %rax # R_X86_64_TPOFF32 + leaq foo@TLSLD(%rip), %rdi # R_X86_64_TLSLD + leaq foo@DTPOFF(%rax), %rcx # R_X86_64_DTPOFF32 + +// CHECK: # Section 0x00000001 +// CHECK: (('sh_name', 0x00000001) # '.text' + +// CHECK: # Symbol 0x00000002 +// CHECK: (('st_name', 0x00000000) # '' +// CHECK: ('st_bind', 0x00000000) +// CHECK ('st_type', 0x00000003) +// CHECK: ('st_other', 0x00000000) +// CHECK: ('st_shndx', 0x00000001) + +// CHECK: # Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', 0x00000001) +// CHECK-NEXT: ('r_sym', 0x00000002) +// CHECK-NEXT: ('r_type', 0x0000000a) +// CHECK-NEXT: ('r_addend', + +// CHECK: # Relocation 0x00000001 +// CHECK-NEXT: (('r_offset', 0x00000008) +// CHECK-NEXT: ('r_sym', 0x00000002) +// CHECK-NEXT: ('r_type', 0x0000000b) +// CHECK-NEXT: ('r_addend', + +// CHECK: # Relocation 0x00000002 +// CHECK-NEXT: (('r_offset', 0x00000013) +// CHECK-NEXT: ('r_sym', 0x00000002) +// CHECK-NEXT: ('r_type', 0x0000000b) +// CHECK-NEXT: ('r_addend', + +// CHECK: # Relocation 0x00000003 +// CHECK-NEXT: (('r_offset', 0x0000001a) +// CHECK-NEXT: ('r_sym', 0x00000002) +// CHECK-NEXT: ('r_type', 0x0000000b) +// CHECK-NEXT: ('r_addend', + +// CHECK: # Relocation 0x00000004 +// CHECK-NEXT: (('r_offset', 0x00000022) +// CHECK-NEXT: ('r_sym', 0x00000002) +// CHECK-NEXT: ('r_type', 0x0000000b) +// CHECK-NEXT: ('r_addend', + +// CHECK: # Relocation 0x00000005 +// CHECK-NEXT: (('r_offset', 0x00000026) +// CHECK-NEXT: ('r_sym', 0x00000002) +// CHECK-NEXT: ('r_type', 0x0000000a) +// CHECK-NEXT: ('r_addend', + +// CHECK: # Relocation 0x00000006 +// CHECK-NEXT: (('r_offset', 0x0000002d) +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x00000016) +// CHECK-NEXT: ('r_addend', 0xfffffffc) + +// CHECK: # Relocation 0x00000007 +// CHECK-NEXT: (('r_offset', 0x00000034) +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x00000013) +// CHECK-NEXT: ('r_addend', 0xfffffffc) + +// CHECK: # Relocation 0x00000008 +// CHECK-NEXT: (('r_offset', 0x0000003b) +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x00000017) +// CHECK-NEXT: ('r_addend', 0x00000000) + +// CHECK: # Relocation 0x00000009 +// CHECK-NEXT: (('r_offset', 0x00000042) +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x00000014) +// CHECK-NEXT: ('r_addend', 0xfffffffc) + +// CHECK: # Relocation 0x0000000a +// CHECK-NEXT: (('r_offset', 0x00000049) +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x00000015) +// CHECK-NEXT: ('r_addend', 0x00000000) diff --git a/test/MC/ELF/rename.s b/test/MC/ELF/rename.s new file mode 100644 index 0000000..290fff6 --- /dev/null +++ b/test/MC/ELF/rename.s @@ -0,0 +1,46 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// When doing a rename, all the checks for where the relocation should go +// should be performed with the original symbol. Only if we decide to relocate +// with the symbol we should then use the renamed one. + +// This is a regression test for a bug where we used bar5@@@zed when deciding +// if we should relocate with the symbol or with the section and we would then +// not produce a relocation with .text. + +defined1: +defined3: + .symver defined3, bar5@@@zed + .long defined3 + + .global defined1 + +// Section 1 is .text +// CHECK: # Section 0x00000001 +// CHECK-NEXT: (('sh_name', 0x00000001) # '.text' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000006) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000040) +// CHECK-NEXT: ('sh_size', 0x00000004) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000004) +// CHECK-NEXT: ('sh_entsize', 0x00000000) + +// Symbol 2 is section 1 +// CHECK: # Symbol 0x00000002 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000003) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) + +// The relocation uses symbol 2 +// CHECK: # Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', 0x00000000) +// CHECK-NEXT: ('r_sym', 0x00000002) +// CHECK-NEXT: ('r_type', 0x0000000a) +// CHECK-NEXT: ('r_addend', 0x00000000) diff --git a/test/MC/ELF/section.s b/test/MC/ELF/section.s new file mode 100644 index 0000000..f3700ca --- /dev/null +++ b/test/MC/ELF/section.s @@ -0,0 +1,61 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that these names are accepted. + +.section .note.GNU-stack,"",@progbits +.section .note.GNU-stack2,"",%progbits +.section .note.GNU-,"",@progbits +.section -.note.GNU,"",@progbits + +// CHECK: ('sh_name', 0x00000012) # '.note.GNU-stack' +// CHECK: ('sh_name', 0x00000022) # '.note.GNU-stack2' +// CHECK: ('sh_name', 0x00000033) # '.note.GNU-' +// CHECK: ('sh_name', 0x0000003e) # '-.note.GNU' + +// Test that the dafults are used + +.section .init +.section .fini +.section .rodata + +// CHECK: (('sh_name', 0x00000049) # '.init' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000006) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000050) +// CHECK-NEXT: ('sh_size', 0x00000000) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Section 0x0000000b +// CHECK-NEXT: (('sh_name', 0x0000004f) # '.fini' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000006) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000050) +// CHECK-NEXT: ('sh_size', 0x00000000) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Section 0x0000000c +// CHECK-NEXT: (('sh_name', 0x00000055) # '.rodata' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000002) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000050) +// CHECK-NEXT: ('sh_size', 0x00000000) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ), + +// Test that we can parse these +foo: +bar: +.section .text.foo,"axG",@progbits,foo,comdat +.section .text.bar,"axMG",@progbits,42,bar,comdat diff --git a/test/MC/ELF/set.s b/test/MC/ELF/set.s new file mode 100644 index 0000000..a782bed --- /dev/null +++ b/test/MC/ELF/set.s @@ -0,0 +1,21 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +// Test that we accept .set of a symbol after it has been used in a statement. + + jmp foo + .set foo, bar + +// or a .quad + + .quad foo2 + .set foo2,bar2 + +// Test that there is an undefined reference to bar +// CHECK: (('st_name', 0x00000001) # 'bar' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), diff --git a/test/MC/ELF/size.s b/test/MC/ELF/size.s new file mode 100644 index 0000000..ceb9486 --- /dev/null +++ b/test/MC/ELF/size.s @@ -0,0 +1,10 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Mostly a test that this doesn't crash anymore. + +// CHECK: # Symbol 0x00000004 +// CHECK-NEXT: (('st_name', 0x00000001) # 'foo' +// CHECK-NEXT: ('st_bind', 0x00000001) + + .size foo, .Lbar-foo + .long foo diff --git a/test/MC/ELF/sleb.s b/test/MC/ELF/sleb.s new file mode 100644 index 0000000..00e5b4b --- /dev/null +++ b/test/MC/ELF/sleb.s @@ -0,0 +1,29 @@ +// RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck -check-prefix=ELF_32 %s +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck -check-prefix=ELF_64 %s +// RUN: llvm-mc -filetype=obj -triple i386-apple-darwin9 %s -o - | macho-dump --dump-section-data | FileCheck -check-prefix=MACHO_32 %s +// RUN: llvm-mc -filetype=obj -triple x86_64-apple-darwin9 %s -o - | macho-dump --dump-section-data | FileCheck -check-prefix=MACHO_64 %s + + .text +foo: + .sleb128 0 + .sleb128 1 + .sleb128 -1 + .sleb128 63 + .sleb128 -64 + + .sleb128 64 + .sleb128 -65 + + .sleb128 8191 + .sleb128 -8192 + + .sleb128 8193 + +// ELF_32: ('sh_name', 0x00000001) # '.text' +// ELF_32: ('_section_data', '00017f3f 40c000bf 7fff3f80 4081c000') +// ELF_64: ('sh_name', 0x00000001) # '.text' +// ELF_64: ('_section_data', '00017f3f 40c000bf 7fff3f80 4081c000') +// MACHO_32: ('section_name', '__text\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +// MACHO_32: ('_section_data', '00017f3f 40c000bf 7fff3f80 4081c000') +// MACHO_64: ('section_name', '__text\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +// MACHO_64: ('_section_data', '00017f3f 40c000bf 7fff3f80 4081c000') diff --git a/test/MC/ELF/symref.s b/test/MC/ELF/symref.s new file mode 100644 index 0000000..f1563e5 --- /dev/null +++ b/test/MC/ELF/symref.s @@ -0,0 +1,165 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +defined1: +defined2: +defined3: + .symver defined1, bar1@zed + .symver undefined1, bar2@zed + + .symver defined2, bar3@@zed + + .symver defined3, bar5@@@zed + .symver undefined3, bar6@@@zed + + .long defined1 + .long undefined1 + .long defined2 + .long defined3 + .long undefined3 + + .global global1 + .symver global1, g1@@zed +global1: + + +// CHECK: # Symbol 0x00000001 +// CHECK-NEXT: (('st_name', 0x00000013) # 'bar1@zed' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000002 +// CHECK-NEXT: (('st_name', 0x00000025) # 'bar3@@zed' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000003 +// CHECK-NEXT: (('st_name', 0x0000002f) # 'bar5@@zed' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000004 +// CHECK-NEXT: (('st_name', 0x00000001) # 'defined1' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000005 +// CHECK-NEXT: (('st_name', 0x0000000a) # 'defined2' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000006 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000003) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000007 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000003) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000002) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000008 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000003) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000003) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000009 +// CHECK-NEXT: (('st_name', 0x0000004a) # 'g1@@zed' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000014) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x0000000a +// CHECK-NEXT: (('st_name', 0x00000042) # 'global1' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000014) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x0000000b +// CHECK-NEXT: (('st_name', 0x0000001c) # 'bar2@zed' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x0000000c +// CHECK-NEXT: (('st_name', 0x00000039) # 'bar6@zed' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT:]) + +// CHECK: # Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', 0x00000000) +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x0000000a) +// CHECK-NEXT: ('r_addend', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Relocation 0x00000001 +// CHECK-NEXT: (('r_offset', 0x00000004) +// CHECK-NEXT: ('r_sym', 0x0000000b) +// CHECK-NEXT: ('r_type', 0x0000000a) +// CHECK-NEXT: ('r_addend', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Relocation 0x00000002 +// CHECK-NEXT: (('r_offset', 0x00000008) +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x0000000a) +// CHECK-NEXT: ('r_addend', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Relocation 0x00000003 +// CHECK-NEXT: (('r_offset', 0x0000000c) +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x0000000a) +// CHECK-NEXT: ('r_addend', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Relocation 0x00000004 +// CHECK-NEXT: (('r_offset', 0x00000010) +// CHECK-NEXT: ('r_sym', 0x0000000c) +// CHECK-NEXT: ('r_type', 0x0000000a) +// CHECK-NEXT: ('r_addend', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT:]) diff --git a/test/MC/ELF/tls.s b/test/MC/ELF/tls.s new file mode 100644 index 0000000..395c270 --- /dev/null +++ b/test/MC/ELF/tls.s @@ -0,0 +1,15 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that foobar is of type STT_TLS. + + .section .zed,"awT",@progbits +foobar: + .long 43 + +// CHECK: (('st_name', 0x00000001) # 'foobar' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000006) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000004) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) diff --git a/test/MC/ELF/type.s b/test/MC/ELF/type.s new file mode 100644 index 0000000..a2d0787 --- /dev/null +++ b/test/MC/ELF/type.s @@ -0,0 +1,32 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that both % and @ are accepted. + .global foo + .type foo,%function +foo: + + .global bar + .type bar,@object +bar: + +// Test that gnu_unique_object is accepted. + .type zed,@gnu_unique_object + +// CHECK: # Symbol 0x00000004 +// CHECK-NEXT: (('st_name', 0x00000005) # 'bar' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000001) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000005 +// CHECK-NEXT: (('st_name', 0x00000001) # 'foo' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000002) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), diff --git a/test/MC/ELF/uleb.s b/test/MC/ELF/uleb.s new file mode 100644 index 0000000..1e4734b --- /dev/null +++ b/test/MC/ELF/uleb.s @@ -0,0 +1,22 @@ +// RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck -check-prefix=ELF_32 %s +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck -check-prefix=ELF_64 %s +// RUN: llvm-mc -filetype=obj -triple i386-apple-darwin9 %s -o - | macho-dump --dump-section-data | FileCheck -check-prefix=MACHO_32 %s +// RUN: llvm-mc -filetype=obj -triple x86_64-apple-darwin9 %s -o - | macho-dump --dump-section-data | FileCheck -check-prefix=MACHO_64 %s + + .text +foo: + .uleb128 0 + .uleb128 1 + .uleb128 127 + .uleb128 128 + .uleb128 16383 + .uleb128 16384 + +// ELF_32: ('sh_name', 0x00000001) # '.text' +// ELF_32: ('_section_data', '00017f80 01ff7f80 8001') +// ELF_64: ('sh_name', 0x00000001) # '.text' +// ELF_64: ('_section_data', '00017f80 01ff7f80 8001') +// MACHO_32: ('section_name', '__text\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +// MACHO_32: ('_section_data', '00017f80 01ff7f80 8001') +// MACHO_64: ('section_name', '__text\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +// MACHO_64: ('_section_data', '00017f80 01ff7f80 8001') diff --git a/test/MC/ELF/undef.s b/test/MC/ELF/undef.s new file mode 100644 index 0000000..cdef5e4 --- /dev/null +++ b/test/MC/ELF/undef.s @@ -0,0 +1,46 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test which symbols should be in the symbol table + + .long .Lsym1 +.Lsym2: +.Lsym3: +.Lsym4 = .Lsym2 - .Lsym3 + .long .Lsym4 + + .type .Lsym5,@object + .type sym6,@object + .long sym6 + + .section .rodata.str1.1,"aMS",@progbits,1 +.Lsym7: +.Lsym8: + + .text + movsd .Lsym8(%rip), %xmm1 + +// CHECK: ('_symbols', [ +// CHECK-NEXT: # Symbol 0x00000000 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK: # Symbol 0x00000001 +// CHECK-NEXT: (('st_name', 0x0000000d) # '.Lsym8' +// CHECK: # Symbol 0x00000002 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK: # Symbol 0x00000003 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK: # Symbol 0x00000004 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK: # Symbol 0x00000005 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK: # Symbol 0x00000006 +// CHECK-NEXT: (('st_name', 0x00000001) # '.Lsym1' +// CHECK: # Symbol 0x00000007 +// CHECK-NEXT: (('st_name', 0x00000008) # 'sym6' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000001) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: ]) diff --git a/test/MC/ELF/undef2.s b/test/MC/ELF/undef2.s new file mode 100644 index 0000000..9544fbc --- /dev/null +++ b/test/MC/ELF/undef2.s @@ -0,0 +1,10 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that this produces an undefined reference to .Lfoo + + je .Lfoo + +// CHECK: ('_symbols', [ +// CHECK: (('st_name', 0x00000001) # '.Lfoo' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK: (('sh_name', 0x00000024) # '.strtab' diff --git a/test/MC/ELF/weak.s b/test/MC/ELF/weak.s new file mode 100644 index 0000000..f1a66b5 --- /dev/null +++ b/test/MC/ELF/weak.s @@ -0,0 +1,30 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that this produces a weak undefined symbol. + + .weak foo + .long foo + +// And that bar is after all local symbols and has non zero value. + .weak bar +bar: + +//CHECK: # Symbol 0x00000004 +//CHECK-NEXT: (('st_name', 0x00000005) # 'bar' +//CHECK-NEXT: ('st_bind', 0x00000002) +//CHECK-NEXT: ('st_type', 0x00000000) +//CHECK-NEXT: ('st_other', 0x00000000) +//CHECK-NEXT: ('st_shndx', 0x00000001) +//CHECK-NEXT: ('st_value', 0x00000004) +//CHECK-NEXT: ('st_size', 0x00000000) +//CHECK-NEXT: ), +//CHECK-NEXT: # Symbol 0x00000005 +//CHECK: (('st_name', 0x00000001) # 'foo' +//CHECK-NEXT: ('st_bind', 0x00000002) +//CHECK-NEXT: ('st_type', 0x00000000) +//CHECK-NEXT: ('st_other', 0x00000000) +//CHECK-NEXT: ('st_shndx', 0x00000000) +//CHECK-NEXT: ('st_value', 0x00000000) +//CHECK-NEXT: ('st_size', 0x00000000) +//CHECK-NEXT: ), +//CHECK-NEXT: ]) diff --git a/test/MC/ELF/weakref-plt.s b/test/MC/ELF/weakref-plt.s new file mode 100644 index 0000000..26ba3f6 --- /dev/null +++ b/test/MC/ELF/weakref-plt.s @@ -0,0 +1,8 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + + .weakref bar,foo + call bar@PLT + +// CHECK: # Symbol 0x00000005 +// CHECK-NEXT: (('st_name', 0x00000001) # 'foo' +// CHECK-NEXT: ('st_bind', 0x00000002) diff --git a/test/MC/ELF/weakref-reloc.s b/test/MC/ELF/weakref-reloc.s new file mode 100644 index 0000000..580d754 --- /dev/null +++ b/test/MC/ELF/weakref-reloc.s @@ -0,0 +1,49 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that the relocations point to the correct symbols. We used to get the +// symbol index wrong for weakrefs when creating _GLOBAL_OFFSET_TABLE_. + + .weakref bar,foo + call zed@PLT + call bar + +// CHECK: # Symbol 0x00000004 +// CHECK-NEXT: (('st_name', 0x00000009) # '_GLOBAL_OFFSET_TABLE_' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000005 +// CHECK-NEXT: (('st_name', 0x00000001) # 'foo' +// CHECK-NEXT: ('st_bind', 0x00000002) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000006 +// CHECK-NEXT: (('st_name', 0x00000005) # 'zed' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), + +// CHECK: # Relocation 0x00000000 +// CHECK-NEXT: (('r_offset', 0x00000001) +// CHECK-NEXT: ('r_sym', 0x00000006) +// CHECK-NEXT: ('r_type', 0x00000004) +// CHECK-NEXT: ('r_addend', 0xfffffffc) +// CHECK-NEXT: ), +// CHECK-NEXT: # Relocation 0x00000001 +// CHECK-NEXT: (('r_offset', 0x00000006) +// CHECK-NEXT: ('r_sym', 0x00000005) +// CHECK-NEXT: ('r_type', 0x00000002) +// CHECK-NEXT: ('r_addend', 0xfffffffc) +// CHECK-NEXT: ), diff --git a/test/MC/ELF/weakref.s b/test/MC/ELF/weakref.s new file mode 100644 index 0000000..212e2c3 --- /dev/null +++ b/test/MC/ELF/weakref.s @@ -0,0 +1,234 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// This is a long test that checks that the aliases created by weakref are +// never in the symbol table and that the only case it causes a symbol to +// be output as a weak undefined symbol is if that variable is not defined +// in this file and all the references to it are done via the alias. + + .weakref foo1, bar1 + + .weakref foo2, bar2 + .long bar2 + + .weakref foo3, bar3 + .long foo3 + + .weakref foo4, bar4 + .long foo4 + .long bar4 + + .weakref foo5, bar5 + .long bar5 + .long foo5 + +bar6: + .weakref foo6, bar6 + +bar7: + .weakref foo7, bar7 + .long bar7 + +bar8: + .weakref foo8, bar8 + .long foo8 + +bar9: + .weakref foo9, bar9 + .long foo9 + .long bar9 + +bar10: + .global bar10 + .weakref foo10, bar10 + .long bar10 + .long foo10 + +bar11: + .global bar11 + .weakref foo11, bar11 + +bar12: + .global bar12 + .weakref foo12, bar12 + .long bar12 + +bar13: + .global bar13 + .weakref foo13, bar13 + .long foo13 + +bar14: + .global bar14 + .weakref foo14, bar14 + .long foo14 + .long bar14 + +bar15: + .global bar15 + .weakref foo15, bar15 + .long bar15 + .long foo15 + +// CHECK: # Symbol 0x00000000 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000001 +// CHECK-NEXT: (('st_name', 0x00000015) # 'bar6' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000018) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000002 +// CHECK-NEXT: (('st_name', 0x0000001a) # 'bar7' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000018) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000003 +// CHECK-NEXT: (('st_name', 0x0000001f) # 'bar8' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x0000001c) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000004 +// CHECK-NEXT: (('st_name', 0x00000024) # 'bar9' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000020) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000005 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000003) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000006 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000003) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000002) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000007 +// CHECK-NEXT: (('st_name', 0x00000000) # '' +// CHECK-NEXT: ('st_bind', 0x00000000) +// CHECK-NEXT: ('st_type', 0x00000003) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000003) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000008 +// CHECK-NEXT: (('st_name', 0x00000029) # 'bar10' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000028) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000009 +// CHECK-NEXT: (('st_name', 0x0000002f) # 'bar11' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000030) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x0000000a +// CHECK-NEXT: (('st_name', 0x00000035) # 'bar12' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000030) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x0000000b +// CHECK-NEXT: (('st_name', 0x0000003b) # 'bar13' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000034) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x0000000c +// CHECK-NEXT: (('st_name', 0x00000041) # 'bar14' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000038) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x0000000d +// CHECK-NEXT: (('st_name', 0x00000047) # 'bar15' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000040) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x0000000e +// CHECK-NEXT: (('st_name', 0x00000001) # 'bar2' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x0000000f +// CHECK-NEXT: (('st_name', 0x00000006) # 'bar3' +// CHECK-NEXT: ('st_bind', 0x00000002) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000010 +// CHECK-NEXT: (('st_name', 0x0000000b) # 'bar4' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000011 +// CHECK-NEXT: (('st_name', 0x00000010) # 'bar5' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000000) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000000) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: ]) diff --git a/test/MC/ELF/zero.s b/test/MC/ELF/zero.s new file mode 100644 index 0000000..adf21f8 --- /dev/null +++ b/test/MC/ELF/zero.s @@ -0,0 +1,16 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s + +.zero 4 +.zero 1,42 + +// CHECK: ('sh_name', 0x00000001) # '.text' +// CHECK: ('sh_type', 0x00000001) +// CHECK: ('sh_flags', 0x00000006) +// CHECK: ('sh_addr', 0x00000000) +// CHECK: ('sh_offset', 0x00000040) +// CHECK: ('sh_size', 0x00000005) +// CHECK: ('sh_link', 0x00000000) +// CHECK: ('sh_info', 0x00000000) +// CHECK: ('sh_addralign', 0x00000004) +// CHECK: ('sh_entsize', 0x00000000) +// CHECK: ('_section_data', '00000000 2a') |