From 0211a969891b4bc035eb19d01baa071e5e2a213e Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 17 May 2010 20:12:31 +0000 Subject: [PATCH] MC/Mach-O: Fix some differences in symbol flag handling. - Don't clear weak reference flag, 'as' was only "trying" to do this, it wasn't actually succeeding. - Clear the "lazy bound" bit when we mark something external. This corresponds roughly to the lazy clearing of the bit that 'as' implements in symbol_table_lookup. - The exact meaning of these flags appears pretty loose, since 'as' isn't very consistent. For now we just try to match 'as', we will clean this up one day hopefully. llvm-svn: 103964 --- llvm/lib/MC/MCMachOStreamer.cpp | 17 +++- llvm/test/MC/MachO/symbol-flags.s | 134 +++++++++++++++++++++++------- 2 files changed, 120 insertions(+), 31 deletions(-) diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index b27f151f4341..b00e2bf1094b 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -192,8 +192,14 @@ void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) { SD.setFragment(F); SD.setOffset(F->getContents().size()); - // This causes the reference type and weak reference flags to be cleared. - SD.setFlags(SD.getFlags() & ~(SF_WeakReference | SF_ReferenceTypeMask)); + // This causes the reference type flag to be cleared. Darwin 'as' was "trying" + // to clear the weak reference and weak definition bits too, but the + // implementation was buggy. For now we just try to match 'as', for + // diffability. + // + // FIXME: Cleanup this code, these bits should be emitted based on semantic + // properties, not on the order of definition, etc. + SD.setFlags(SD.getFlags() & ~SF_ReferenceTypeMask); Symbol->setSection(*CurSection); } @@ -257,6 +263,13 @@ void MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol, case MCSA_Global: SD.setExternal(true); + // This effectively clears the undefined lazy bit, in Darwin 'as', although + // it isn't very consistent because it implements this as part of symbol + // lookup. + // + // FIXME: Cleanup this code, these bits should be emitted based on semantic + // properties, not on the order of definition, etc. + SD.setFlags(SD.getFlags() & ~SF_ReferenceTypeUndefinedLazy); break; case MCSA_LazyReference: diff --git a/llvm/test/MC/MachO/symbol-flags.s b/llvm/test/MC/MachO/symbol-flags.s index e82b0a0447f8..705fa39fad5d 100644 --- a/llvm/test/MC/MachO/symbol-flags.s +++ b/llvm/test/MC/MachO/symbol-flags.s @@ -5,6 +5,10 @@ sym_ref_def_A: sym_ref_def_C: .reference sym_ref_def_C + .reference sym_ref_def_D + .globl sym_ref_def_D + .globl sym_ref_def_E + .reference sym_ref_def_E .weak_reference sym_weak_ref_A .weak_reference sym_weak_ref_def_A @@ -16,12 +20,22 @@ sym_weak_ref_def_B: .globl sym_weak_def_A .weak_definition sym_weak_def_A sym_weak_def_A: +sym_weak_def_B: + .weak_definition sym_weak_def_B + .globl sym_weak_def_B + .weak_definition sym_weak_def_C +sym_weak_def_C: + .globl sym_weak_def_C .lazy_reference sym_lazy_ref_A .lazy_reference sym_lazy_ref_B sym_lazy_ref_B: sym_lazy_ref_C: .lazy_reference sym_lazy_ref_C + .lazy_reference sym_lazy_ref_D + .globl sym_lazy_ref_D + .globl sym_lazy_ref_E + .lazy_reference sym_lazy_ref_E .private_extern sym_private_ext_A .private_extern sym_private_ext_B @@ -30,6 +44,8 @@ sym_private_ext_C: .private_extern sym_private_ext_C .private_extern sym_private_ext_D .globl sym_private_ext_D + .globl sym_private_ext_E + .private_extern sym_private_ext_E .no_dead_strip sym_no_dead_strip_A @@ -39,7 +55,7 @@ sym_private_ext_C: .desc sym_desc_flags,0x47 sym_desc_flags: - + // CHECK: ('cputype', 7) // CHECK: ('cpusubtype', 3) // CHECK: ('filetype', 1) @@ -73,6 +89,8 @@ sym_desc_flags: // CHECK: ('reserved1', 0) // CHECK: ('reserved2', 0) // CHECK: ), +// CHECK: ('_relocations', [ +// CHECK: ]) // CHECK: # Section 1 // 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') @@ -86,19 +104,21 @@ sym_desc_flags: // CHECK: ('reserved1', 0) // CHECK: ('reserved2', 0) // CHECK: ), +// CHECK: ('_relocations', [ +// CHECK: ]) // CHECK: ]) // CHECK: ), // CHECK: # Load Command 1 // CHECK: (('command', 2) // CHECK: ('size', 24) // CHECK: ('symoff', 324) -// CHECK: ('nsyms', 16) -// CHECK: ('stroff', 516) -// CHECK: ('strsize', 260) -// CHECK: ('_string_data', '\x00sym_ref_A\x00sym_weak_ref_A\x00sym_weak_def_A\x00sym_lazy_ref_A\x00sym_private_ext_A\x00sym_private_ext_B\x00sym_private_ext_C\x00sym_private_ext_D\x00sym_no_dead_strip_A\x00sym_ref_def_A\x00sym_ref_def_C\x00sym_weak_ref_def_A\x00sym_weak_ref_def_B\x00sym_lazy_ref_B\x00sym_lazy_ref_C\x00sym_desc_flags\x00\x00') +// CHECK: ('nsyms', 23) +// CHECK: ('stroff', 600) +// CHECK: ('strsize', 368) +// CHECK: ('_string_data', '\x00sym_ref_A\x00sym_ref_def_D\x00sym_ref_def_E\x00sym_weak_ref_A\x00sym_weak_def_A\x00sym_weak_def_B\x00sym_weak_def_C\x00sym_lazy_ref_A\x00sym_lazy_ref_D\x00sym_lazy_ref_E\x00sym_private_ext_A\x00sym_private_ext_B\x00sym_private_ext_C\x00sym_private_ext_D\x00sym_private_ext_E\x00sym_no_dead_strip_A\x00sym_ref_def_A\x00sym_ref_def_C\x00sym_weak_ref_def_A\x00sym_weak_ref_def_B\x00sym_lazy_ref_B\x00sym_lazy_ref_C\x00sym_desc_flags\x00\x00\x00\x00') // CHECK: ('_symbols', [ // CHECK: # Symbol 0 -// CHECK: (('n_strx', 148) +// CHECK: (('n_strx', 254) // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 1) // CHECK: ('n_desc', 32) @@ -106,7 +126,7 @@ sym_desc_flags: // CHECK: ('_string', 'sym_ref_def_A') // CHECK: ), // CHECK: # Symbol 1 -// CHECK: (('n_strx', 162) +// CHECK: (('n_strx', 268) // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 1) // CHECK: ('n_desc', 32) @@ -114,15 +134,15 @@ sym_desc_flags: // CHECK: ('_string', 'sym_ref_def_C') // CHECK: ), // CHECK: # Symbol 2 -// CHECK: (('n_strx', 176) +// CHECK: (('n_strx', 282) // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 1) -// CHECK: ('n_desc', 0) +// CHECK: ('n_desc', 64) // CHECK: ('n_value', 0) // CHECK: ('_string', 'sym_weak_ref_def_A') // CHECK: ), // CHECK: # Symbol 3 -// CHECK: (('n_strx', 195) +// CHECK: (('n_strx', 301) // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 1) // CHECK: ('n_desc', 0) @@ -130,7 +150,7 @@ sym_desc_flags: // CHECK: ('_string', 'sym_weak_ref_def_B') // CHECK: ), // CHECK: # Symbol 4 -// CHECK: (('n_strx', 214) +// CHECK: (('n_strx', 320) // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 2) // CHECK: ('n_desc', 32) @@ -138,7 +158,7 @@ sym_desc_flags: // CHECK: ('_string', 'sym_lazy_ref_B') // CHECK: ), // CHECK: # Symbol 5 -// CHECK: (('n_strx', 229) +// CHECK: (('n_strx', 335) // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 2) // CHECK: ('n_desc', 32) @@ -146,15 +166,15 @@ sym_desc_flags: // CHECK: ('_string', 'sym_lazy_ref_C') // CHECK: ), // CHECK: # Symbol 6 -// CHECK: (('n_strx', 244) +// CHECK: (('n_strx', 350) // CHECK: ('n_type', 0xe) // CHECK: ('n_sect', 2) -// CHECK: ('n_desc', 0) +// CHECK: ('n_desc', 64) // CHECK: ('n_value', 0) // CHECK: ('_string', 'sym_desc_flags') // CHECK: ), // CHECK: # Symbol 7 -// CHECK: (('n_strx', 74) +// CHECK: (('n_strx', 162) // CHECK: ('n_type', 0x1f) // CHECK: ('n_sect', 2) // CHECK: ('n_desc', 0) @@ -162,7 +182,7 @@ sym_desc_flags: // CHECK: ('_string', 'sym_private_ext_B') // CHECK: ), // CHECK: # Symbol 8 -// CHECK: (('n_strx', 92) +// CHECK: (('n_strx', 180) // CHECK: ('n_type', 0x1f) // CHECK: ('n_sect', 2) // CHECK: ('n_desc', 0) @@ -170,7 +190,7 @@ sym_desc_flags: // CHECK: ('_string', 'sym_private_ext_C') // CHECK: ), // CHECK: # Symbol 9 -// CHECK: (('n_strx', 26) +// CHECK: (('n_strx', 54) // CHECK: ('n_type', 0xf) // CHECK: ('n_sect', 2) // CHECK: ('n_desc', 128) @@ -178,38 +198,78 @@ sym_desc_flags: // CHECK: ('_string', 'sym_weak_def_A') // CHECK: ), // CHECK: # Symbol 10 -// CHECK: (('n_strx', 41) +// CHECK: (('n_strx', 69) +// CHECK: ('n_type', 0xf) +// CHECK: ('n_sect', 2) +// CHECK: ('n_desc', 128) +// CHECK: ('n_value', 0) +// CHECK: ('_string', 'sym_weak_def_B') +// CHECK: ), +// CHECK: # Symbol 11 +// CHECK: (('n_strx', 84) +// CHECK: ('n_type', 0xf) +// CHECK: ('n_sect', 2) +// CHECK: ('n_desc', 128) +// CHECK: ('n_value', 0) +// CHECK: ('_string', 'sym_weak_def_C') +// CHECK: ), +// CHECK: # Symbol 12 +// CHECK: (('n_strx', 99) // CHECK: ('n_type', 0x1) // CHECK: ('n_sect', 0) // CHECK: ('n_desc', 33) // CHECK: ('n_value', 0) // CHECK: ('_string', 'sym_lazy_ref_A') // CHECK: ), -// CHECK: # Symbol 11 -// CHECK: (('n_strx', 128) +// CHECK: # Symbol 13 +// CHECK: (('n_strx', 114) +// CHECK: ('n_type', 0x1) +// CHECK: ('n_sect', 0) +// CHECK: ('n_desc', 32) +// CHECK: ('n_value', 0) +// CHECK: ('_string', 'sym_lazy_ref_D') +// CHECK: ), +// CHECK: # Symbol 14 +// CHECK: (('n_strx', 129) +// CHECK: ('n_type', 0x1) +// CHECK: ('n_sect', 0) +// CHECK: ('n_desc', 33) +// CHECK: ('n_value', 0) +// CHECK: ('_string', 'sym_lazy_ref_E') +// CHECK: ), +// CHECK: # Symbol 15 +// CHECK: (('n_strx', 234) // CHECK: ('n_type', 0x1) // CHECK: ('n_sect', 0) // CHECK: ('n_desc', 32) // CHECK: ('n_value', 0) // CHECK: ('_string', 'sym_no_dead_strip_A') // CHECK: ), -// CHECK: # Symbol 12 -// CHECK: (('n_strx', 56) +// CHECK: # Symbol 16 +// CHECK: (('n_strx', 144) // CHECK: ('n_type', 0x11) // CHECK: ('n_sect', 0) // CHECK: ('n_desc', 0) // CHECK: ('n_value', 0) // CHECK: ('_string', 'sym_private_ext_A') // CHECK: ), -// CHECK: # Symbol 13 -// CHECK: (('n_strx', 110) +// CHECK: # Symbol 17 +// CHECK: (('n_strx', 198) // CHECK: ('n_type', 0x11) // CHECK: ('n_sect', 0) // CHECK: ('n_desc', 0) // CHECK: ('n_value', 0) // CHECK: ('_string', 'sym_private_ext_D') // CHECK: ), -// CHECK: # Symbol 14 +// CHECK: # Symbol 18 +// CHECK: (('n_strx', 216) +// CHECK: ('n_type', 0x11) +// CHECK: ('n_sect', 0) +// CHECK: ('n_desc', 0) +// CHECK: ('n_value', 0) +// CHECK: ('_string', 'sym_private_ext_E') +// CHECK: ), +// CHECK: # Symbol 19 // CHECK: (('n_strx', 1) // CHECK: ('n_type', 0x1) // CHECK: ('n_sect', 0) @@ -217,10 +277,26 @@ sym_desc_flags: // CHECK: ('n_value', 0) // CHECK: ('_string', 'sym_ref_A') // CHECK: ), -// CHECK: # Symbol 15 +// CHECK: # Symbol 20 // CHECK: (('n_strx', 11) // CHECK: ('n_type', 0x1) // CHECK: ('n_sect', 0) +// CHECK: ('n_desc', 32) +// CHECK: ('n_value', 0) +// CHECK: ('_string', 'sym_ref_def_D') +// CHECK: ), +// CHECK: # Symbol 21 +// CHECK: (('n_strx', 25) +// CHECK: ('n_type', 0x1) +// CHECK: ('n_sect', 0) +// CHECK: ('n_desc', 32) +// CHECK: ('n_value', 0) +// CHECK: ('_string', 'sym_ref_def_E') +// CHECK: ), +// CHECK: # Symbol 22 +// CHECK: (('n_strx', 39) +// CHECK: ('n_type', 0x1) +// CHECK: ('n_sect', 0) // CHECK: ('n_desc', 64) // CHECK: ('n_value', 0) // CHECK: ('_string', 'sym_weak_ref_A') @@ -233,9 +309,9 @@ sym_desc_flags: // CHECK: ('ilocalsym', 0) // CHECK: ('nlocalsym', 7) // CHECK: ('iextdefsym', 7) -// CHECK: ('nextdefsym', 3) -// CHECK: ('iundefsym', 10) -// CHECK: ('nundefsym', 6) +// CHECK: ('nextdefsym', 5) +// CHECK: ('iundefsym', 12) +// CHECK: ('nundefsym', 11) // CHECK: ('tocoff', 0) // CHECK: ('ntoc', 0) // CHECK: ('modtaboff', 0)