[llvm-commits] [llvm] r103092 - in /llvm/trunk: include/llvm/MC/MCSectionMachO.h lib/MC/MachObjectWriter.cpp test/MC/MachO/darwin-x86_64-reloc.s
Daniel Dunbar
daniel at zuster.org
Wed May 5 10:22:39 PDT 2010
Author: ddunbar
Date: Wed May 5 12:22:39 2010
New Revision: 103092
URL: http://llvm.org/viewvc/llvm-project?rev=103092&view=rev
Log:
MC/Mach-O/x86_64: Relocations in debug sections should use local relocations
when possible.
- <rdar://problem/7934873>
Modified:
llvm/trunk/include/llvm/MC/MCSectionMachO.h
llvm/trunk/lib/MC/MachObjectWriter.cpp
llvm/trunk/test/MC/MachO/darwin-x86_64-reloc.s
Modified: llvm/trunk/include/llvm/MC/MCSectionMachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionMachO.h?rev=103092&r1=103091&r2=103092&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSectionMachO.h (original)
+++ llvm/trunk/include/llvm/MC/MCSectionMachO.h Wed May 5 12:22:39 2010
@@ -136,6 +136,9 @@
unsigned getStubSize() const { return Reserved2; }
unsigned getType() const { return TypeAndAttributes & SECTION_TYPE; }
+ bool hasAttribute(unsigned Value) const {
+ return (TypeAndAttributes & Value) != 0;
+ }
/// ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
/// This is a string that can appear after a .section directive in a mach-o
Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=103092&r1=103091&r2=103092&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Wed May 5 12:22:39 2010
@@ -548,6 +548,17 @@
MCSymbolData &SD = Asm.getSymbolData(*Symbol);
const MCSymbolData *Base = Asm.getAtom(Layout, &SD);
+ // Relocations inside debug sections always use local relocations when
+ // possible. This seems to be done because the debugger doesn't fully
+ // understand x86_64 relocation entries, and expects to find values that
+ // have already been fixed up.
+ if (Symbol->isDefined()) {
+ const MCSectionMachO &Section = static_cast<const MCSectionMachO&>(
+ Fragment->getParent()->getSection());
+ if (Section.hasAttribute(MCSectionMachO::S_ATTR_DEBUG))
+ Base = 0;
+ }
+
// x86_64 almost always uses external relocations, except when there is no
// symbol to use as a base address (a local symbol with no preceeding
// non-local symbol).
Modified: llvm/trunk/test/MC/MachO/darwin-x86_64-reloc.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/darwin-x86_64-reloc.s?rev=103092&r1=103091&r2=103092&view=diff
==============================================================================
--- llvm/trunk/test/MC/MachO/darwin-x86_64-reloc.s (original)
+++ llvm/trunk/test/MC/MachO/darwin-x86_64-reloc.s Wed May 5 12:22:39 2010
@@ -42,25 +42,29 @@
.long _foobar at GOTPCREL+4
.long _foo at GOTPCREL+4
+ .section __DWARF,__debug_frame,regular,debug
+ .quad L1
+ .quad _ext_foo
+
// CHECK: ('cputype', 16777223)
// CHECK: ('cpusubtype', 3)
// CHECK: ('filetype', 1)
// CHECK: ('num_load_commands', 1)
-// CHECK: ('load_commands_size', 336)
+// CHECK: ('load_commands_size', 416)
// CHECK: ('flag', 0)
// CHECK: ('reserved', 0)
// CHECK: ('load_commands', [
// CHECK: # Load Command 0
// CHECK: (('command', 25)
-// CHECK: ('size', 232)
+// CHECK: ('size', 312)
// 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', 189)
-// CHECK: ('file_offset', 368)
-// CHECK: ('file_size', 189)
+// CHECK: ('vm_size', 205)
+// CHECK: ('file_offset', 448)
+// CHECK: ('file_size', 205)
// CHECK: ('maxprot', 7)
// CHECK: ('initprot', 7)
-// CHECK: ('num_sections', 2)
+// CHECK: ('num_sections', 3)
// CHECK: ('flags', 0)
// CHECK: ('sections', [
// CHECK: # Section 0
@@ -68,9 +72,9 @@
// CHECK: ('segment_name', '__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
// CHECK: ('address', 0)
// CHECK: ('size', 181)
-// CHECK: ('offset', 368)
+// CHECK: ('offset', 448)
// CHECK: ('alignment', 0)
-// CHECK: ('reloc_offset', 560)
+// CHECK: ('reloc_offset', 656)
// CHECK: ('num_reloc', 27)
// CHECK: ('flags', 0x80000400)
// CHECK: ('reserved1', 0)
@@ -166,9 +170,9 @@
// CHECK: ('segment_name', '__DATA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
// CHECK: ('address', 181)
// CHECK: ('size', 8)
-// CHECK: ('offset', 549)
+// CHECK: ('offset', 629)
// CHECK: ('alignment', 0)
-// CHECK: ('reloc_offset', 776)
+// CHECK: ('reloc_offset', 872)
// CHECK: ('num_reloc', 2)
// CHECK: ('flags', 0x0)
// CHECK: ('reserved1', 0)
@@ -181,22 +185,45 @@
// CHECK: ('word-1', 0x4d000000)),
// CHECK: # Relocation 1
// CHECK: (('word-0', 0x0),
-// CHECK: ('word-1', 0x4d000004)),
+// CHECK: ('word-1', 0x4d000005)),
// CHECK: ])
// CHECK: ('_section_data', '\x04\x00\x00\x00\x04\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', 189)
+// CHECK: ('size', 16)
+// CHECK: ('offset', 637)
+// CHECK: ('alignment', 0)
+// CHECK: ('reloc_offset', 888)
+// CHECK: ('num_reloc', 2)
+// CHECK: ('flags', 0x2000000)
+// CHECK: ('reserved1', 0)
+// CHECK: ('reserved2', 0)
+// CHECK: ('reserved3', 0)
+// CHECK: ),
+// CHECK: ('_relocations', [
+// CHECK: # Relocation 0
+// CHECK: (('word-0', 0x8),
+// CHECK: ('word-1', 0xe000004)),
+// CHECK: # Relocation 1
+// CHECK: (('word-0', 0x0),
+// CHECK: ('word-1', 0x6000001)),
+// CHECK: ])
+// CHECK: ('_section_data', '\xad\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', 792)
-// CHECK: ('nsyms', 5)
-// CHECK: ('stroff', 872)
-// CHECK: ('strsize', 32)
-// CHECK: ('_string_data', '\x00_foobar\x00_foo\x00_baz\x00_bar\x00_prev\x00\x00\x00')
+// CHECK: ('symoff', 904)
+// CHECK: ('nsyms', 6)
+// CHECK: ('stroff', 1000)
+// CHECK: ('strsize', 40)
+// CHECK: ('_string_data', '\x00_foobar\x00_ext_foo\x00_foo\x00_baz\x00_bar\x00_prev\x00\x00')
// CHECK: ('_symbols', [
// CHECK: # Symbol 0
-// CHECK: (('n_strx', 9)
+// CHECK: (('n_strx', 18)
// CHECK: ('n_type', 0xe)
// CHECK: ('n_sect', 1)
// CHECK: ('n_desc', 0)
@@ -204,7 +231,7 @@
// CHECK: ('_string', '_foo')
// CHECK: ),
// CHECK: # Symbol 1
-// CHECK: (('n_strx', 14)
+// CHECK: (('n_strx', 23)
// CHECK: ('n_type', 0xe)
// CHECK: ('n_sect', 1)
// CHECK: ('n_desc', 0)
@@ -212,7 +239,7 @@
// CHECK: ('_string', '_baz')
// CHECK: ),
// CHECK: # Symbol 2
-// CHECK: (('n_strx', 19)
+// CHECK: (('n_strx', 28)
// CHECK: ('n_type', 0xe)
// CHECK: ('n_sect', 1)
// CHECK: ('n_desc', 0)
@@ -220,7 +247,7 @@
// CHECK: ('_string', '_bar')
// CHECK: ),
// CHECK: # Symbol 3
-// CHECK: (('n_strx', 24)
+// CHECK: (('n_strx', 33)
// CHECK: ('n_type', 0xe)
// CHECK: ('n_sect', 1)
// CHECK: ('n_desc', 0)
@@ -228,6 +255,14 @@
// CHECK: ('_string', '_prev')
// CHECK: ),
// CHECK: # Symbol 4
+// CHECK: (('n_strx', 9)
+// CHECK: ('n_type', 0x1)
+// CHECK: ('n_sect', 0)
+// CHECK: ('n_desc', 0)
+// CHECK: ('n_value', 0)
+// CHECK: ('_string', '_ext_foo')
+// CHECK: ),
+// CHECK: # Symbol 5
// CHECK: (('n_strx', 1)
// CHECK: ('n_type', 0x1)
// CHECK: ('n_sect', 0)
@@ -245,7 +280,7 @@
// CHECK: ('iextdefsym', 4)
// CHECK: ('nextdefsym', 0)
// CHECK: ('iundefsym', 4)
-// CHECK: ('nundefsym', 1)
+// CHECK: ('nundefsym', 2)
// CHECK: ('tocoff', 0)
// CHECK: ('ntoc', 0)
// CHECK: ('modtaboff', 0)
More information about the llvm-commits
mailing list