diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-05-12 00:38:17 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-05-12 00:38:17 +0000 |
commit | a5f1d57f65ae601ec181c0f4e36cf0df5e8d79d8 (patch) | |
tree | 99cbdd963a1c49327eda3dd44b4ee76b3d797bd9 | |
parent | 85f4fdaed4fcc6050499579152c45fde679213d3 (diff) | |
download | external_llvm-a5f1d57f65ae601ec181c0f4e36cf0df5e8d79d8.zip external_llvm-a5f1d57f65ae601ec181c0f4e36cf0df5e8d79d8.tar.gz external_llvm-a5f1d57f65ae601ec181c0f4e36cf0df5e8d79d8.tar.bz2 |
MC/Mach-O/x86_64: Add a new hook for checking whether a particular section can
be diced into atoms, and adjust getAtom() to take this into account.
- This fixes relocations to symbols in fixed size literal sections, for
example.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103532 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Target/TargetAsmBackend.h | 8 | ||||
-rw-r--r-- | lib/MC/MCAssembler.cpp | 6 | ||||
-rw-r--r-- | lib/Target/X86/X86AsmBackend.cpp | 20 | ||||
-rw-r--r-- | test/MC/MachO/darwin-x86_64-reloc.s | 194 |
4 files changed, 162 insertions, 66 deletions
diff --git a/include/llvm/Target/TargetAsmBackend.h b/include/llvm/Target/TargetAsmBackend.h index f350ecc..b390ca5 100644 --- a/include/llvm/Target/TargetAsmBackend.h +++ b/include/llvm/Target/TargetAsmBackend.h @@ -90,6 +90,14 @@ public: return false; } + /// isSectionAtomizable - Check whether the given section can be split into + /// atoms. + /// + /// \see MCAssembler::isSymbolLinkerVisible(). + virtual bool isSectionAtomizable(const MCSection &Section) const { + return true; + } + /// isVirtualSection - Check whether the given section is "virtual", that is /// has no actual object file contents. virtual bool isVirtualSection(const MCSection &Section) const = 0; diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 65e3571..8ec927e 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -297,6 +297,12 @@ const MCSymbolData *MCAssembler::getAtom(const MCAsmLayout &Layout, if (!SD->getFragment()) return 0; + // Non-linker visible symbols in sections which can't be atomized have no + // defining atom. + if (!getBackend().isSectionAtomizable( + SD->getFragment()->getParent()->getSection())) + return 0; + // Otherwise, return the atom for the containing fragment. return SD->getFragment()->getAtom(); } diff --git a/lib/Target/X86/X86AsmBackend.cpp b/lib/Target/X86/X86AsmBackend.cpp index b72601a..8ee836e 100644 --- a/lib/Target/X86/X86AsmBackend.cpp +++ b/lib/Target/X86/X86AsmBackend.cpp @@ -259,6 +259,26 @@ public: const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section); return SMO.getType() == MCSectionMachO::S_CSTRING_LITERALS; } + + virtual bool isSectionAtomizable(const MCSection &Section) const { + const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section); + // Fixed sized data sections are uniqued, they cannot be diced into atoms. + switch (SMO.getType()) { + default: + return true; + + case MCSectionMachO::S_4BYTE_LITERALS: + case MCSectionMachO::S_8BYTE_LITERALS: + case MCSectionMachO::S_16BYTE_LITERALS: + case MCSectionMachO::S_LITERAL_POINTERS: + case MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS: + case MCSectionMachO::S_LAZY_SYMBOL_POINTERS: + case MCSectionMachO::S_MOD_INIT_FUNC_POINTERS: + case MCSectionMachO::S_MOD_TERM_FUNC_POINTERS: + case MCSectionMachO::S_INTERPOSING: + return false; + } + } }; } diff --git a/test/MC/MachO/darwin-x86_64-reloc.s b/test/MC/MachO/darwin-x86_64-reloc.s index 20b593f..248c507 100644 --- a/test/MC/MachO/darwin-x86_64-reloc.s +++ b/test/MC/MachO/darwin-x86_64-reloc.s @@ -64,37 +64,56 @@ L4: .long 0 .text movl L4(%rip), %eax + + .section __TEXT,__literal8,8byte_literals + .quad 0 +L5: + .quad 0 +f6: + .quad 0 +L6: + .quad 0 + + .text + movl L5(%rip), %eax + movl f6(%rip), %eax + movl L6(%rip), %eax + .data + .quad L5 + .quad f6 + .quad L6 + // CHECK: ('cputype', 16777223) // CHECK: ('cpusubtype', 3) // CHECK: ('filetype', 1) // CHECK: ('num_load_commands', 1) -// CHECK: ('load_commands_size', 416) +// CHECK: ('load_commands_size', 496) // CHECK: ('flag', 0) // CHECK: ('reserved', 0) // CHECK: ('load_commands', [ // CHECK: # Load Command 0 // CHECK: (('command', 25) -// CHECK: ('size', 312) +// CHECK: ('size', 392) // CHECK: ('segment_name', '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') // CHECK: ('vm_addr', 0) -// CHECK: ('vm_size', 229) -// CHECK: ('file_offset', 448) -// CHECK: ('file_size', 229) +// CHECK: ('vm_size', 303) +// CHECK: ('file_offset', 528) +// CHECK: ('file_size', 303) // CHECK: ('maxprot', 7) // CHECK: ('initprot', 7) -// CHECK: ('num_sections', 3) +// CHECK: ('num_sections', 4) // CHECK: ('flags', 0) // CHECK: ('sections', [ // CHECK: # Section 0 // CHECK: (('section_name', '__data\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') // CHECK: ('segment_name', '__DATA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') // CHECK: ('address', 0) -// CHECK: ('size', 16) -// CHECK: ('offset', 448) +// CHECK: ('size', 40) +// CHECK: ('offset', 528) // CHECK: ('alignment', 0) -// CHECK: ('reloc_offset', 680) -// CHECK: ('num_reloc', 2) +// CHECK: ('reloc_offset', 832) +// CHECK: ('num_reloc', 5) // CHECK: ('flags', 0x0) // CHECK: ('reserved1', 0) // CHECK: ('reserved2', 0) @@ -102,22 +121,31 @@ L4: // CHECK: ), // CHECK: ('_relocations', [ // CHECK: # Relocation 0 +// CHECK: (('word-0', 0x20), +// CHECK: ('word-1', 0x6000004)), +// CHECK: # Relocation 1 +// CHECK: (('word-0', 0x18), +// CHECK: ('word-1', 0xe000006)), +// CHECK: # Relocation 2 +// CHECK: (('word-0', 0x10), +// CHECK: ('word-1', 0x6000004)), +// CHECK: # Relocation 3 // CHECK: (('word-0', 0x8), // CHECK: ('word-1', 0x4d000000)), -// CHECK: # Relocation 1 +// CHECK: # Relocation 4 // CHECK: (('word-0', 0x4), -// CHECK: ('word-1', 0x4d000007)), +// CHECK: ('word-1', 0x4d000008)), // CHECK: ]) -// CHECK: ('_section_data', '\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00') +// CHECK: ('_section_data', "\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x17\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\x01\x00\x00\x00\x00\x00\x00") // CHECK: # Section 1 // 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: ('address', 16) -// CHECK: ('size', 197) -// CHECK: ('offset', 464) +// CHECK: ('address', 40) +// CHECK: ('size', 215) +// CHECK: ('offset', 568) // CHECK: ('alignment', 0) -// CHECK: ('reloc_offset', 696) -// CHECK: ('num_reloc', 28) +// CHECK: ('reloc_offset', 872) +// CHECK: ('num_reloc', 31) // CHECK: ('flags', 0x80000400) // CHECK: ('reserved1', 0) // CHECK: ('reserved2', 0) @@ -125,99 +153,108 @@ L4: // CHECK: ), // CHECK: ('_relocations', [ // CHECK: # Relocation 0 +// CHECK: (('word-0', 0xd3), +// CHECK: ('word-1', 0x15000004)), +// CHECK: # Relocation 1 +// CHECK: (('word-0', 0xcd), +// CHECK: ('word-1', 0x1d000006)), +// CHECK: # Relocation 2 +// CHECK: (('word-0', 0xc7), +// CHECK: ('word-1', 0x15000004)), +// CHECK: # Relocation 3 // CHECK: (('word-0', 0xc1), // CHECK: ('word-1', 0x15000001)), -// CHECK: # Relocation 1 +// CHECK: # Relocation 4 // CHECK: (('word-0', 0xa5), // CHECK: ('word-1', 0x5e000003)), -// CHECK: # Relocation 2 +// CHECK: # Relocation 5 // CHECK: (('word-0', 0xa5), // CHECK: ('word-1', 0xe000000)), -// CHECK: # Relocation 3 +// CHECK: # Relocation 6 // CHECK: (('word-0', 0x9d), // CHECK: ('word-1', 0x5e000003)), -// CHECK: # Relocation 4 +// CHECK: # Relocation 7 // CHECK: (('word-0', 0x9d), // CHECK: ('word-1', 0xe000000)), -// CHECK: # Relocation 5 +// CHECK: # Relocation 8 // CHECK: (('word-0', 0x95), // CHECK: ('word-1', 0xe000003)), -// CHECK: # Relocation 6 +// CHECK: # Relocation 9 // CHECK: (('word-0', 0x8d), // CHECK: ('word-1', 0xe000003)), -// CHECK: # Relocation 7 +// CHECK: # Relocation 10 // CHECK: (('word-0', 0x79), // CHECK: ('word-1', 0x8d000003)), -// CHECK: # Relocation 8 +// CHECK: # Relocation 11 // CHECK: (('word-0', 0x71), // CHECK: ('word-1', 0x7d000003)), -// CHECK: # Relocation 9 +// CHECK: # Relocation 12 // CHECK: (('word-0', 0x69), // CHECK: ('word-1', 0x6d000003)), -// CHECK: # Relocation 10 +// CHECK: # Relocation 13 // CHECK: (('word-0', 0x63), // CHECK: ('word-1', 0x1d000003)), -// CHECK: # Relocation 11 +// CHECK: # Relocation 14 // CHECK: (('word-0', 0x5c), // CHECK: ('word-1', 0x1d000003)), -// CHECK: # Relocation 12 +// CHECK: # Relocation 15 // CHECK: (('word-0', 0x55), // CHECK: ('word-1', 0x5c000002)), -// CHECK: # Relocation 13 +// CHECK: # Relocation 16 // CHECK: (('word-0', 0x55), // CHECK: ('word-1', 0xc000000)), -// CHECK: # Relocation 14 +// CHECK: # Relocation 17 // CHECK: (('word-0', 0x4d), // CHECK: ('word-1', 0x5e000002)), -// CHECK: # Relocation 15 +// CHECK: # Relocation 18 // CHECK: (('word-0', 0x4d), // CHECK: ('word-1', 0xe000000)), -// CHECK: # Relocation 16 +// CHECK: # Relocation 19 // CHECK: (('word-0', 0x45), // CHECK: ('word-1', 0x5e000002)), -// CHECK: # Relocation 17 +// CHECK: # Relocation 20 // CHECK: (('word-0', 0x45), // CHECK: ('word-1', 0xe000000)), -// CHECK: # Relocation 18 +// CHECK: # Relocation 21 // CHECK: (('word-0', 0x3d), // CHECK: ('word-1', 0xe000000)), -// CHECK: # Relocation 19 +// CHECK: # Relocation 22 // CHECK: (('word-0', 0x35), // CHECK: ('word-1', 0xe000000)), -// CHECK: # Relocation 20 +// CHECK: # Relocation 23 // CHECK: (('word-0', 0x2d), // CHECK: ('word-1', 0x8d000000)), -// CHECK: # Relocation 21 +// CHECK: # Relocation 24 // CHECK: (('word-0', 0x26), // CHECK: ('word-1', 0x6d000000)), -// CHECK: # Relocation 22 +// CHECK: # Relocation 25 // CHECK: (('word-0', 0x20), // CHECK: ('word-1', 0x1d000000)), -// CHECK: # Relocation 23 +// CHECK: # Relocation 26 // CHECK: (('word-0', 0x1a), // CHECK: ('word-1', 0x1d000000)), -// CHECK: # Relocation 24 +// CHECK: # Relocation 27 // CHECK: (('word-0', 0x14), // CHECK: ('word-1', 0x4d000000)), -// CHECK: # Relocation 25 +// CHECK: # Relocation 28 // CHECK: (('word-0', 0xe), // CHECK: ('word-1', 0x3d000000)), -// CHECK: # Relocation 26 +// CHECK: # Relocation 29 // CHECK: (('word-0', 0x7), // CHECK: ('word-1', 0x2d000000)), -// CHECK: # Relocation 27 +// CHECK: # Relocation 30 // CHECK: (('word-0', 0x2), // CHECK: ('word-1', 0x2d000000)), // CHECK: ]) -// CHECK: ('_section_data', '\xc3\xe8\x00\x00\x00\x00\xe8\x04\x00\x00\x00H\x8b\x05\x00\x00\x00\x00\xff5\x00\x00\x00\x00\x8b\x05\x00\x00\x00\x00\x8b\x05\x04\x00\x00\x00\xc6\x05\xff\xff\xff\xff\x12\xc7\x05\xfc\xff\xff\xffxV4\x12\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00H\x8d\x05,\x00\x00\x00H\x8d\x05\x14\x00\x00\x00\x83\x05\x13\x00\x00\x00\x06f\x81\x05\x12\x00\x00\x00\xf4\x01\x81\x05\x10\x00\x00\x00\xf4\x01\x00\x00\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90,\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\xe4\xff\xff\xff\xff\xff\xff\xff\xd4\xff\xff\xff\xff\xff\xff\xff,\x00\x00\x00\x00\x00\x00\x00\x83\xc0\x00\x03\x04%\x03\x00\x00\x00\x8b\x057\xff\xff\xff') +// CHECK: ('_section_data', '\xc3\xe8\x00\x00\x00\x00\xe8\x04\x00\x00\x00H\x8b\x05\x00\x00\x00\x00\xff5\x00\x00\x00\x00\x8b\x05\x00\x00\x00\x00\x8b\x05\x04\x00\x00\x00\xc6\x05\xff\xff\xff\xff\x12\xc7\x05\xfc\xff\xff\xffxV4\x12\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00H\x8d\x05,\x00\x00\x00H\x8d\x05\x14\x00\x00\x00\x83\x05\x13\x00\x00\x00\x06f\x81\x05\x12\x00\x00\x00\xf4\x01\x81\x05\x10\x00\x00\x00\xf4\x01\x00\x00\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90,\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\xe4\xff\xff\xff\xff\xff\xff\xff\xd4\xff\xff\xff\xff\xff\xff\xff,\x00\x00\x00\x00\x00\x00\x00\x83\xc0\x00\x03\x04%\x03\x00\x00\x00\x8b\x05\x1f\xff\xff\xff\x8b\x05$\x00\x00\x00\x8b\x05\x00\x00\x00\x00\x8b\x05(\x00\x00\x00') // CHECK: # Section 2 // CHECK: (('section_name', '__debug_frame\x00\x00\x00') // CHECK: ('segment_name', '__DWARF\x00\x00\x00\x00\x00\x00\x00\x00\x00') -// CHECK: ('address', 213) +// CHECK: ('address', 255) // CHECK: ('size', 16) -// CHECK: ('offset', 661) +// CHECK: ('offset', 783) // CHECK: ('alignment', 0) -// CHECK: ('reloc_offset', 920) +// CHECK: ('reloc_offset', 1120) // CHECK: ('num_reloc', 2) // CHECK: ('flags', 0x2000000) // CHECK: ('reserved1', 0) @@ -227,29 +264,46 @@ L4: // CHECK: ('_relocations', [ // CHECK: # Relocation 0 // CHECK: (('word-0', 0x8), -// CHECK: ('word-1', 0xe000006)), +// CHECK: ('word-1', 0xe000007)), // CHECK: # Relocation 1 // CHECK: (('word-0', 0x0), // CHECK: ('word-1', 0x6000002)), // CHECK: ]) -// CHECK: ('_section_data', '\xbd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +// CHECK: ('_section_data', '\xd5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +// CHECK: # Section 3 +// CHECK: (('section_name', '__literal8\x00\x00\x00\x00\x00\x00') +// CHECK: ('segment_name', '__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +// CHECK: ('address', 271) +// CHECK: ('size', 32) +// CHECK: ('offset', 799) +// CHECK: ('alignment', 0) +// CHECK: ('reloc_offset', 0) +// CHECK: ('num_reloc', 0) +// CHECK: ('flags', 0x4) +// CHECK: ('reserved1', 0) +// CHECK: ('reserved2', 0) +// CHECK: ('reserved3', 0) +// CHECK: ), +// CHECK: ('_relocations', [ +// CHECK: ]) +// CHECK: ('_section_data', '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') // CHECK: ]) // CHECK: ), // CHECK: # Load Command 1 // CHECK: (('command', 2) // CHECK: ('size', 24) -// CHECK: ('symoff', 936) -// CHECK: ('nsyms', 8) -// CHECK: ('stroff', 1064) -// CHECK: ('strsize', 48) -// CHECK: ('_string_data', '\x00_foobar\x00_ext_foo\x00_foo\x00_baz\x00_bar\x00_prev\x00_f2\x00_f3\x00\x00') +// CHECK: ('symoff', 1136) +// CHECK: ('nsyms', 9) +// CHECK: ('stroff', 1280) +// CHECK: ('strsize', 52) +// CHECK: ('_string_data', '\x00_foobar\x00_ext_foo\x00_foo\x00_baz\x00_bar\x00_prev\x00_f2\x00_f3\x00f6\x00\x00\x00') // CHECK: ('_symbols', [ // CHECK: # Symbol 0 // CHECK: (('n_strx', 18) // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 2) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 16) +// CHECK: ('n_value', 40) // CHECK: ('_string', '_foo') // CHECK: ), // CHECK: # Symbol 1 @@ -257,7 +311,7 @@ L4: // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 2) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 17) +// CHECK: ('n_value', 41) // CHECK: ('_string', '_baz') // CHECK: ), // CHECK: # Symbol 2 @@ -265,7 +319,7 @@ L4: // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 2) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 77) +// CHECK: ('n_value', 101) // CHECK: ('_string', '_bar') // CHECK: ), // CHECK: # Symbol 3 @@ -273,7 +327,7 @@ L4: // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 2) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 145) +// CHECK: ('n_value', 169) // CHECK: ('_string', '_prev') // CHECK: ), // CHECK: # Symbol 4 @@ -281,7 +335,7 @@ L4: // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 2) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 197) +// CHECK: ('n_value', 221) // CHECK: ('_string', '_f2') // CHECK: ), // CHECK: # Symbol 5 @@ -289,10 +343,18 @@ L4: // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 2) // CHECK: ('n_desc', 0) -// CHECK: ('n_value', 200) +// CHECK: ('n_value', 224) // CHECK: ('_string', '_f3') // CHECK: ), // CHECK: # Symbol 6 +// CHECK: (('n_strx', 47) +// CHECK: ('n_type', 0xe) +// CHECK: ('n_sect', 4) +// CHECK: ('n_desc', 0) +// CHECK: ('n_value', 287) +// CHECK: ('_string', 'f6') +// CHECK: ), +// CHECK: # Symbol 7 // CHECK: (('n_strx', 9) // CHECK: ('n_type', 0x1) // CHECK: ('n_sect', 0) @@ -300,7 +362,7 @@ L4: // CHECK: ('n_value', 0) // CHECK: ('_string', '_ext_foo') // CHECK: ), -// CHECK: # Symbol 7 +// CHECK: # Symbol 8 // CHECK: (('n_strx', 1) // CHECK: ('n_type', 0x1) // CHECK: ('n_sect', 0) @@ -314,10 +376,10 @@ L4: // CHECK: (('command', 11) // CHECK: ('size', 80) // CHECK: ('ilocalsym', 0) -// CHECK: ('nlocalsym', 6) -// CHECK: ('iextdefsym', 6) +// CHECK: ('nlocalsym', 7) +// CHECK: ('iextdefsym', 7) // CHECK: ('nextdefsym', 0) -// CHECK: ('iundefsym', 6) +// CHECK: ('iundefsym', 7) // CHECK: ('nundefsym', 2) // CHECK: ('tocoff', 0) // CHECK: ('ntoc', 0) |