Assembler: Darwin variables defined via .set are no-dead-strip.

For gas compatibility.

rdar://12219394

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163854 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Grosbach 2012-09-13 23:11:31 +00:00
parent 45d81bdde8
commit 3f90a4c42d
3 changed files with 167 additions and 4 deletions

View File

@ -247,7 +247,6 @@ void MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
switch (Attribute) {
case MCSA_LazyReference:
case MCSA_Reference:
case MCSA_NoDeadStrip:
case MCSA_SymbolResolver:
case MCSA_PrivateExtern:
case MCSA_WeakDefinition:
@ -256,6 +255,7 @@ void MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
case MCSA_IndirectSymbol:
llvm_unreachable("Invalid symbol attribute for ELF!");
case MCSA_NoDeadStrip:
case MCSA_ELF_TypeGnuUniqueObject:
// Ignore for now.
break;

View File

@ -221,7 +221,8 @@ private:
/// return the contents from the current token up to the end or comma.
StringRef ParseStringToComma();
bool ParseAssignment(StringRef Name, bool allow_redef);
bool ParseAssignment(StringRef Name, bool allow_redef,
bool NoDeadStrip = false);
bool ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc);
bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res, SMLoc &EndLoc);
@ -1697,7 +1698,8 @@ static bool IsUsedIn(const MCSymbol *Sym, const MCExpr *Value) {
llvm_unreachable("Unknown expr kind!");
}
bool AsmParser::ParseAssignment(StringRef Name, bool allow_redef) {
bool AsmParser::ParseAssignment(StringRef Name, bool allow_redef,
bool NoDeadStrip) {
// FIXME: Use better location, we should use proper tokens.
SMLoc EqualLoc = Lexer.getLoc();
@ -1752,6 +1754,9 @@ bool AsmParser::ParseAssignment(StringRef Name, bool allow_redef) {
// Do the assignment.
Out.EmitAssignment(Sym, Value);
if (NoDeadStrip)
Out.EmitSymbolAttribute(Sym, MCSA_NoDeadStrip);
return false;
}
@ -1809,7 +1814,7 @@ bool AsmParser::ParseDirectiveSet(StringRef IDVal, bool allow_redef) {
return TokError("unexpected token in '" + Twine(IDVal) + "'");
Lex();
return ParseAssignment(Name, allow_redef);
return ParseAssignment(Name, allow_redef, true);
}
bool AsmParser::ParseEscapedString(std::string &Data) {

158
test/MC/MachO/absolute.s Normal file
View File

@ -0,0 +1,158 @@
// RUN: llvm-mc -triple x86_64-apple-darwin10 %s -filetype=obj -o - | macho-dump | FileCheck %s
_bar:
nop
_foo:
nop
.set foo_set1, (_foo + 0xffff0000)
.set foo_set2, (_foo - _bar + 0xffff0000)
foo_equals = (_foo + 0xffff0000)
foo_equals2 = (_foo - _bar + 0xffff0000)
.globl foo_set1_global;
.set foo_set1_global, (_foo + 0xffff0000)
.globl foo_set2_global;
.set foo_set2_global, (_foo - _bar + 0xffff0000)
// CHECK: ('cputype', 16777223)
// CHECK: ('cpusubtype', 3)
// CHECK: ('filetype', 1)
// CHECK: ('num_load_commands', 3)
// CHECK: ('load_commands_size', 256)
// CHECK: ('flag', 0)
// CHECK: ('reserved', 0)
// CHECK: ('load_commands', [
// CHECK: # Load Command 0
// CHECK: (('command', 25)
// CHECK: ('size', 152)
// 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', 2)
// CHECK: ('file_offset', 288)
// CHECK: ('file_size', 2)
// CHECK: ('maxprot', 7)
// CHECK: ('initprot', 7)
// CHECK: ('num_sections', 1)
// CHECK: ('flags', 0)
// CHECK: ('sections', [
// CHECK: # Section 0
// 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', 0)
// CHECK: ('size', 2)
// CHECK: ('offset', 288)
// CHECK: ('alignment', 0)
// CHECK: ('reloc_offset', 0)
// CHECK: ('num_reloc', 0)
// CHECK: ('flags', 0x80000400)
// CHECK: ('reserved1', 0)
// CHECK: ('reserved2', 0)
// CHECK: ('reserved3', 0)
// CHECK: ),
// CHECK: ('_relocations', [
// CHECK: ])
// CHECK: ])
// CHECK: ),
// CHECK: # Load Command 1
// CHECK: (('command', 2)
// CHECK: ('size', 24)
// CHECK: ('symoff', 292)
// CHECK: ('nsyms', 8)
// CHECK: ('stroff', 420)
// CHECK: ('strsize', 84)
// CHECK: ('_string_data', '\x00foo_set1_global\x00foo_set2_global\x00_bar\x00_foo\x00foo_set1\x00foo_set2\x00foo_equals\x00foo_equals2\x00')
// CHECK: ('_symbols', [
// CHECK: # Symbol 0
// CHECK: (('n_strx', 33)
// CHECK: ('n_type', 0xe)
// CHECK: ('n_sect', 1)
// CHECK: ('n_desc', 0)
// CHECK: ('n_value', 0)
// CHECK: ('_string', '_bar')
// CHECK: ),
// CHECK: # Symbol 1
// CHECK: (('n_strx', 38)
// CHECK: ('n_type', 0xe)
// CHECK: ('n_sect', 1)
// CHECK: ('n_desc', 0)
// CHECK: ('n_value', 1)
// CHECK: ('_string', '_foo')
// CHECK: ),
// CHECK: # Symbol 2
// CHECK: (('n_strx', 43)
// CHECK: ('n_type', 0xe)
// CHECK: ('n_sect', 1)
// CHECK: ('n_desc', 32)
// CHECK: ('n_value', 4294901761)
// CHECK: ('_string', 'foo_set1')
// CHECK: ),
// CHECK: # Symbol 3
// CHECK: (('n_strx', 52)
// CHECK: ('n_type', 0x2)
// CHECK: ('n_sect', 0)
// CHECK: ('n_desc', 32)
// CHECK: ('n_value', 4294901761)
// CHECK: ('_string', 'foo_set2')
// CHECK: ),
// CHECK: # Symbol 4
// CHECK: (('n_strx', 61)
// CHECK: ('n_type', 0xe)
// CHECK: ('n_sect', 1)
// CHECK: ('n_desc', 0)
// CHECK: ('n_value', 4294901761)
// CHECK: ('_string', 'foo_equals')
// CHECK: ),
// CHECK: # Symbol 5
// CHECK: (('n_strx', 72)
// CHECK: ('n_type', 0x2)
// CHECK: ('n_sect', 0)
// CHECK: ('n_desc', 0)
// CHECK: ('n_value', 4294901761)
// CHECK: ('_string', 'foo_equals2')
// CHECK: ),
// CHECK: # Symbol 6
// CHECK: (('n_strx', 1)
// CHECK: ('n_type', 0xf)
// CHECK: ('n_sect', 1)
// CHECK: ('n_desc', 32)
// CHECK: ('n_value', 4294901761)
// CHECK: ('_string', 'foo_set1_global')
// CHECK: ),
// CHECK: # Symbol 7
// CHECK: (('n_strx', 17)
// CHECK: ('n_type', 0x3)
// CHECK: ('n_sect', 0)
// CHECK: ('n_desc', 32)
// CHECK: ('n_value', 4294901761)
// CHECK: ('_string', 'foo_set2_global')
// CHECK: ),
// CHECK: ])
// CHECK: ),
// CHECK: # Load Command 2
// CHECK: (('command', 11)
// CHECK: ('size', 80)
// CHECK: ('ilocalsym', 0)
// CHECK: ('nlocalsym', 6)
// CHECK: ('iextdefsym', 6)
// CHECK: ('nextdefsym', 2)
// CHECK: ('iundefsym', 8)
// CHECK: ('nundefsym', 0)
// CHECK: ('tocoff', 0)
// CHECK: ('ntoc', 0)
// CHECK: ('modtaboff', 0)
// CHECK: ('nmodtab', 0)
// CHECK: ('extrefsymoff', 0)
// CHECK: ('nextrefsyms', 0)
// CHECK: ('indirectsymoff', 0)
// CHECK: ('nindirectsyms', 0)
// CHECK: ('extreloff', 0)
// CHECK: ('nextrel', 0)
// CHECK: ('locreloff', 0)
// CHECK: ('nlocrel', 0)
// CHECK: ('_indirect_symbols', [
// CHECK: ])
// CHECK: ),
// CHECK: ])