[llvm-commits] [llvm] r163853 - in /llvm/trunk: include/llvm/MC/MCMachObjectWriter.h lib/MC/MachObjectWriter.cpp

Jim Grosbach grosbach at apple.com
Wed Sep 19 14:09:57 PDT 2012


Huh. I thought I had, but there's certainly not one there. Probably pilot error on the "git add" on my end or something.

Thanks for the reminder! Will fix.

-Jim

On Sep 19, 2012, at 1:53 PM, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:

> Can you add a test?
> 
> On 13 September 2012 19:11, Jim Grosbach <grosbach at apple.com> wrote:
>> Author: grosbach
>> Date: Thu Sep 13 18:11:25 2012
>> New Revision: 163853
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=163853&view=rev
>> Log:
>> MachO: Correctly mark symbol-difference variables as N_ABS.
>> 
>> .set a, b - c + CONSTANT
>> d = b - c + CONSTANT
>> 
>> Both 'a' and 'd' should be marked as absolute symbols (N_ABS).
>> 
>> rdar://12219394
>> 
>> Modified:
>>    llvm/trunk/include/llvm/MC/MCMachObjectWriter.h
>>    llvm/trunk/lib/MC/MachObjectWriter.cpp
>> 
>> Modified: llvm/trunk/include/llvm/MC/MCMachObjectWriter.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCMachObjectWriter.h?rev=163853&r1=163852&r2=163853&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/MC/MCMachObjectWriter.h (original)
>> +++ llvm/trunk/include/llvm/MC/MCMachObjectWriter.h Thu Sep 13 18:11:25 2012
>> @@ -233,6 +233,8 @@
>>   void computeSectionAddresses(const MCAssembler &Asm,
>>                                const MCAsmLayout &Layout);
>> 
>> +  void markAbsoluteVariableSymbols(MCAssembler &Asm,
>> +                                   const MCAsmLayout &Layout);
>>   void ExecutePostLayoutBinding(MCAssembler &Asm, const MCAsmLayout &Layout);
>> 
>>   virtual bool IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
>> 
>> Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=163853&r1=163852&r2=163853&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
>> +++ llvm/trunk/lib/MC/MachObjectWriter.cpp Thu Sep 13 18:11:25 2012
>> @@ -68,6 +68,11 @@
>> 
>>   // If this is a variable, then recursively evaluate now.
>>   if (S.isVariable()) {
>> +    if (const MCConstantExpr *C =
>> +          dyn_cast<const MCConstantExpr>(S.getVariableValue()))
>> +      return C->getValue();
>> +
>> +
>>     MCValue Target;
>>     if (!S.getVariableValue()->EvaluateAsRelocatable(Target, Layout))
>>       report_fatal_error("unable to evaluate offset for variable '" +
>> @@ -315,11 +320,7 @@
>> 
>>   // Compute the symbol address.
>>   if (Symbol.isDefined()) {
>> -    if (Symbol.isAbsolute()) {
>> -      Address = cast<MCConstantExpr>(Symbol.getVariableValue())->getValue();
>> -    } else {
>> -      Address = getSymbolAddress(&Data, Layout);
>> -    }
>> +    Address = getSymbolAddress(&Data, Layout);
>>   } else if (Data.isCommon()) {
>>     // Common symbols are encoded with the size in the address
>>     // field, and their alignment in the flags.
>> @@ -557,6 +558,26 @@
>>   }
>> }
>> 
>> +void MachObjectWriter::markAbsoluteVariableSymbols(MCAssembler &Asm,
>> +                                                   const MCAsmLayout &Layout) {
>> +  for (MCAssembler::symbol_iterator i = Asm.symbol_begin(),
>> +                                    e = Asm.symbol_end();
>> +      i != e; ++i) {
>> +    MCSymbolData &SD = *i;
>> +    if (!SD.getSymbol().isVariable())
>> +      continue;
>> +
>> +    // Is the variable is a symbol difference (SA - SB + C) expression,
>> +    // and neither symbol is external, mark the variable as absolute.
>> +    const MCExpr *Expr = SD.getSymbol().getVariableValue();
>> +    MCValue Value;
>> +    if (Expr->EvaluateAsRelocatable(Value, Layout)) {
>> +      if (Value.getSymA() && Value.getSymB())
>> +        const_cast<MCSymbol*>(&SD.getSymbol())->setAbsolute();
>> +    }
>> +  }
>> +}
>> +
>> void MachObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
>>                                                 const MCAsmLayout &Layout) {
>>   computeSectionAddresses(Asm, Layout);
>> @@ -564,6 +585,10 @@
>>   // Create symbol data for any indirect symbols.
>>   BindIndirectSymbols(Asm);
>> 
>> +  // Mark symbol difference expressions in variables (from .set or = directives)
>> +  // as absolute.
>> +  markAbsoluteVariableSymbols(Asm, Layout);
>> +
>>   // Compute symbol table information and bind symbol indices.
>>   ComputeSymbolTable(Asm, StringTable, LocalSymbolData, ExternalSymbolData,
>>                      UndefinedSymbolData);
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list