[llvm] r182092 - [PowerPC] Merge/rename PPC fixup types

David Fang fang at csl.cornell.edu
Wed May 22 15:01:35 PDT 2013


Hi Ulrich,

>> PPCELFObjectWriter now handles it like this:
>>
>>   MCSymbolRefExpr::VariantKind Modifier = Target.isAbsolute() ?
>>     MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
>> [...]
>>     case PPC::fixup_ppc_half16:
>>       switch (Modifier) {
>>       case MCSymbolRefExpr::VK_PPC_GAS_HA16:
>>       case MCSymbolRefExpr::VK_PPC_DARWIN_HA16:
>>         Type = ELF::R_PPC_ADDR16_HA;
>>         break;
>>       case MCSymbolRefExpr::VK_PPC_GAS_LO16:
>>       case MCSymbolRefExpr::VK_PPC_DARWIN_LO16:
>>         Type = ELF::R_PPC_ADDR16_LO;
>>         break;
>>
>> Unfortunately, on Darwin, the VK_PPC_DARWIN_HA16/LO16
>> markers are currently not 100% correct, since in some
>> cases the back-end makes hard-coded assumptions on
>> where lo/ha markers are required.  If you recall my
>> patch you've been testing recently, this was intended to
>> address exactly this problem.  With the patch applied,
>> it should be possible to reliably check for the HA/LO
>> target-specific expressions.
>>
>> However, it seems we cannot in fact use the MCValue
>> object to represent target-specific flags resulting
>> from evaluation of target-specific expressions.
>
> Looks like I was too pessimistic here; in fact, it now
> seems relatively straight-forward to do exactly that.
>
> The attached patch is an updated version of the Darwin
> target-specific MCExpr patch, now including an
> EvaluateAsRelocatableImpl routine that processes
> HA/LO expressions.
>
> With this patch applied, the solution for PPCMachObjectWriter
> outlined above (consult the VariantKind to distinguish
> between HA and LO relocations) should now work reliably.

Thanks for the patch preview.
Now my code (PPCMachObjectWriter.cpp) contains:

if (IsPCRel) {
...
#if 0
     case PPC::fixup_ppc_lo16:
       Type = macho::RIT_PPC_LO16;
       break;
     case PPC::fixup_ppc_ha16:
       Type = macho::RIT_PPC_HA16;
       break;
#else
     case PPC::fixup_ppc_half16:
       switch (Modifier) {
       default: llvm_unreachable("Unsupported Modifier");
       case MCSymbolRefExpr::VK_PPC_ADDR16_HA:
         Type = macho::RIT_PPC_HA16;
         break;
       case MCSymbolRefExpr::VK_PPC_ADDR16_LO:
         Type = macho::RIT_PPC_LO16;
         break;
       }
       break;
#endif
...
} else {
...
#if 0
     case PPC::fixup_ppc_ha16:
         Type = macho::RIT_PPC_HA16_SECTDIFF;
       break;
     case PPC::fixup_ppc_lo16:
         Type = macho::RIT_PPC_LO16_SECTDIFF;
       break;
#else
     case PPC::fixup_ppc_half16:
       switch (Modifier) {
       default: llvm_unreachable("Unsupported Modifier");
       case MCSymbolRefExpr::VK_PPC_ADDR16_HA:
         Type = macho::RIT_PPC_HA16_SECTDIFF;
         break;
       case MCSymbolRefExpr::VK_PPC_ADDR16_LO:
         Type = macho::RIT_PPC_LO16_SECTDIFF;
         break;
       }
       break;
#endif
...
}

The rest is still compiling.
I'll try a few test programs after the build finishes.

> (Note that the patch merges VK_PPC_GAS_HA16 and
> VK_PPC_DARWIN_HA16 into a single VK_PPC_ADDR16_HA and
> likewise for LO, so you'll have to adapt the example.)
>
> Can you try and see if that works for you?  If so,
> I can commit the patch to the repository to make
> merging into your branch easier ...
>
> Bye,
> Ulrich
>
> (See attached file: diff-reloc-mcexpr)

Fang

-- 
David Fang
http://www.csl.cornell.edu/~fang/




More information about the llvm-commits mailing list