[llvm] r209478 - [RuntimeDyld] Teach RuntimeDyldMachO how to handle scattered VANILLA relocs on

David Blaikie dblaikie at gmail.com
Thu May 22 16:07:55 PDT 2014


On Thu, May 22, 2014 at 4:03 PM, Lang Hames <lhames at gmail.com> wrote:
> We don't have an i386 bot, I suspect nobody does (or they've been ignoring
> the fact that these have been red).
>
> Something like that sounds very useful. :)

I'm assuming you've got some kind of i386 machine to test this on - is
it worth baselining (marking as XFAIL) that so at least /someone/
(presumably at least you, maybe other people at some point) can run
make check, get a green result, get an XPASS failure when you fix
things, etc?

>
> - Lang.
>
>
> On Thu, May 22, 2014 at 3:48 PM, David Blaikie <dblaikie at gmail.com> wrote:
>>
>> On Thu, May 22, 2014 at 3:30 PM, Lang Hames <lhames at gmail.com> wrote:
>> > Author: lhames
>> > Date: Thu May 22 17:30:13 2014
>> > New Revision: 209478
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=209478&view=rev
>> > Log:
>> > [RuntimeDyld] Teach RuntimeDyldMachO how to handle scattered VANILLA
>> > relocs on
>> > i386.
>> >
>> > This fixes two more MCJIT regression tests on i386:
>>
>> Do we have a public bot running these tests? (why weren't they XFAIL'd
>> until now?) Do you have one internally at least that's green (how is
>> it green if these tests aren't XFAIL'd on i386?) so you'll know (&
>> presumably tell the community) if these regress?
>>
>> >
>> >   ExecutionEngine/MCJIT/2003-05-06-LivenessClobber.ll
>> >   ExecutionEngine/MCJIT/2013-04-04-RelocAddend.ll
>> >
>> > The implementation of processScatteredVANILLA is tasteless
>> > (*ba-dum-ching*),
>> > but I'm working on a substantial tidy-up of RuntimeDyldMachO that should
>> > improve things.
>> >
>> > This patch also fixes a type-o in
>> > RuntimeDyldMachO::processSECTDIFFRelocation,
>> > and teaches that method to skip over the PAIR reloc following the
>> > SECTDIFF.
>> >
>> > <rdar://problem/16961886>
>> >
>> >
>> > Modified:
>> >     llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
>> >     llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
>> >
>> > Modified:
>> > llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp?rev=209478&r1=209477&r2=209478&view=diff
>> >
>> > ==============================================================================
>> > --- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
>> > (original)
>> > +++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp Thu
>> > May 22 17:30:13 2014
>> > @@ -460,7 +460,7 @@ relocation_iterator RuntimeDyldMachO::pr
>> >
>> >    uint32_t AddrB = MachO->getScatteredRelocationValue(RE2);
>> >    section_iterator SBI = getSectionByAddress(*MachO, AddrB);
>> > -  assert(SBI != MachO->section_end() && "Can't find seciton for address
>> > B");
>> > +  assert(SBI != MachO->section_end() && "Can't find section for address
>> > B");
>> >    uint64_t SectionBBase;
>> >    SBI->getAddress(SectionBBase);
>> >    uint64_t SectionBOffset = AddrB - SectionBBase;
>> > @@ -483,7 +483,48 @@ relocation_iterator RuntimeDyldMachO::pr
>> >    addRelocationForSection(R, SectionAID);
>> >    addRelocationForSection(R, SectionBID);
>> >
>> > -  return RelI;
>> > +  return ++RelI;
>> > +}
>> > +
>> > +relocation_iterator RuntimeDyldMachO::processI386ScatteredVANILLA(
>> > +                                            unsigned SectionID,
>> > +                                            relocation_iterator RelI,
>> > +                                            ObjectImage &Obj,
>> > +                                            ObjSectionToIDMap
>> > &ObjSectionToID) {
>> > +  const MachOObjectFile *MachO =
>> > +    static_cast<const MachOObjectFile*>(Obj.getObjectFile());
>> > +  MachO::any_relocation_info RE =
>> > +    MachO->getRelocation(RelI->getRawDataRefImpl());
>> > +
>> > +  SectionEntry &Section = Sections[SectionID];
>> > +  uint32_t RelocType = MachO->getAnyRelocationType(RE);
>> > +  bool IsPCRel = MachO->getAnyRelocationPCRel(RE);
>> > +  unsigned Size = MachO->getAnyRelocationLength(RE);
>> > +  uint64_t Offset;
>> > +  RelI->getOffset(Offset);
>> > +  uint8_t *LocalAddress = Section.Address + Offset;
>> > +  unsigned NumBytes = 1 << Size;
>> > +  int64_t Addend = 0;
>> > +  memcpy(&Addend, LocalAddress, NumBytes);
>> > +
>> > +  unsigned SymbolBaseAddr = MachO->getScatteredRelocationValue(RE);
>> > +  section_iterator TargetSI = getSectionByAddress(*MachO,
>> > SymbolBaseAddr);
>> > +  assert(TargetSI != MachO->section_end() && "Can't find section for
>> > symbol");
>> > +  uint64_t SectionBaseAddr;
>> > +  TargetSI->getAddress(SectionBaseAddr);
>> > +  SectionRef TargetSection = *TargetSI;
>> > +  bool IsCode;
>> > +  TargetSection.isText(IsCode);
>> > +  uint32_t TargetSectionID = findOrEmitSection(Obj, TargetSection,
>> > IsCode,
>> > +                                               ObjSectionToID);
>> > +
>> > +  Addend -= SectionBaseAddr;
>> > +  RelocationEntry R(SectionID, Offset, RelocType, Addend,
>> > +                    IsPCRel, Size);
>> > +
>> > +  addRelocationForSection(R, TargetSectionID);
>> > +
>> > +  return ++RelI;
>> >  }
>> >
>> >  relocation_iterator RuntimeDyldMachO::processRelocationRef(
>> > @@ -498,17 +539,22 @@ relocation_iterator RuntimeDyldMachO::pr
>> >    uint32_t RelType = MachO->getAnyRelocationType(RE);
>> >
>> >    // FIXME: Properly handle scattered relocations.
>> > -  //        For now, optimistically skip these: they can often be
>> > ignored, as
>> > -  //        the static linker will already have applied the relocation,
>> > and it
>> > -  //        only needs to be reapplied if symbols move relative to one
>> > another.
>> > -  //        Note: This will fail horribly where the relocations *do*
>> > need to be
>> > -  //        applied, but that was already the case.
>> > +  //        Special case the couple of scattered relocations that we
>> > know how
>> > +  //        to handle: SECTDIFF relocations, and scattered VANILLA
>> > relocations
>> > +  //        on I386.
>> > +  //        For all other scattered relocations, just bail out and hope
>> > for the
>> > +  //        best, since the offsets computed by scattered relocations
>> > have often
>> > +  //        been optimisticaly filled in by the compiler. This will
>> > fail
>> > +  //        horribly where the relocations *do* need to be applied, but
>> > that was
>> > +  //        already the case.
>> >    if (MachO->isRelocationScattered(RE)) {
>> >      if (RelType == MachO::GENERIC_RELOC_SECTDIFF ||
>> >          RelType == MachO::GENERIC_RELOC_LOCAL_SECTDIFF)
>> >        return processSECTDIFFRelocation(SectionID, RelI, Obj,
>> > ObjSectionToID);
>> > -
>> > -    return ++RelI;
>> > +    else if (Arch == Triple::x86 && RelType ==
>> > MachO::GENERIC_RELOC_VANILLA)
>> > +      return processI386ScatteredVANILLA(SectionID, RelI, Obj,
>> > ObjSectionToID);
>> > +    else
>> > +      return ++RelI;
>> >    }
>> >
>> >    RelocationValueRef Value;
>> >
>> > Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h?rev=209478&r1=209477&r2=209478&view=diff
>> >
>> > ==============================================================================
>> > --- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
>> > (original)
>> > +++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h Thu
>> > May 22 17:30:13 2014
>> > @@ -71,6 +71,12 @@ private:
>> >                                               ObjectImage &ObjImg,
>> >                                               ObjSectionToIDMap
>> > &ObjSectionToID);
>> >
>> > +  relocation_iterator processI386ScatteredVANILLA(
>> > +                                            unsigned SectionID,
>> > +                                            relocation_iterator RelI,
>> > +                                            ObjectImage &ObjImg,
>> > +                                            ObjSectionToIDMap
>> > &ObjSectionToID);
>> > +
>> >    struct EHFrameRelatedSections {
>> >      EHFrameRelatedSections()
>> >          : EHFrameSID(RTDYLD_INVALID_SECTION_ID),
>> >
>> >
>> > _______________________________________________
>> > 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