[lld] r219088 - PE/COFF: remove another use of PECOFFLinkingContext::is64bit
Saleem Abdulrasool
compnerd at compnerd.org
Mon Oct 6 18:22:42 PDT 2014
On Mon, Oct 6, 2014 at 2:52 PM, Rui Ueyama <ruiu at google.com> wrote:
> On Sun, Oct 5, 2014 at 2:30 PM, Saleem Abdulrasool <compnerd at compnerd.org>
> wrote:
>
>> Author: compnerd
>> Date: Sun Oct 5 16:30:29 2014
>> New Revision: 219088
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=219088&view=rev
>> Log:
>> PE/COFF: remove another use of PECOFFLinkingContext::is64bit
>>
>> In order to support more than x86/x86_64, we need to change the behaviour
>> to use
>> the actual machine type rather than checking the bitness and assuming
>> that we
>> are on X86. This replaces the use of is64bit in applyAllRelocations with
>> a
>> check on the machine type. This will enable adding support for handling
>> ARM
>> relocations.
>>
>> Rename the existing applyRelocation methods to be similarly named and to
>> make it
>> clear the types of relocations they will process.
>>
>> Modified:
>> lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
>>
>> Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=219088&r1=219087&r2=219088&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
>> +++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Sun Oct 5
>> 16:30:29 2014
>> @@ -216,14 +216,18 @@ public:
>> void appendAtom(const DefinedAtom *atom);
>> void buildAtomRvaMap(std::map<const Atom *, uint64_t> &atomRva) const;
>>
>> - void applyRelocations32(uint8_t *buffer,
>> - std::map<const Atom *, uint64_t> &atomRva,
>> - std::vector<uint64_t> §ionRva,
>> - uint64_t imageBaseAddress);
>> - void applyRelocations64(uint8_t *buffer,
>> - std::map<const Atom *, uint64_t> &atomRva,
>> - std::vector<uint64_t> §ionRva,
>> - uint64_t imageBaseAddress);
>> + void applyRelocationsARM(uint8_t *buffer,
>> + std::map<const Atom *, uint64_t> &atomRva,
>> + std::vector<uint64_t> §ionRva,
>> + uint64_t imageBaseAddress);
>> + void applyRelocationsX86_32(uint8_t *buffer,
>> + std::map<const Atom *, uint64_t> &atomRva,
>> + std::vector<uint64_t> §ionRva,
>> + uint64_t imageBaseAddress);
>> + void applyRelocationsX86_64(uint8_t *buffer,
>> + std::map<const Atom *, uint64_t> &atomRva,
>> + std::vector<uint64_t> §ionRva,
>> + uint64_t imageBaseAddress);
>
>
> I prefer x64 over x86_64 in PE/COFF tree because that seems the official
> terminology used by Microsoft to refer the x86-64 architecture. Also
> s/x86_32/x86/.
>
You know, I really hadn't considered that, even though I used the same
terminology elsewhere. I like both of these suggestions! Committed as
SVN r219179.
Thanks!
>
>
>
>> void printAtomAddresses(uint64_t baseAddr) const;
>> void addBaseRelocations(std::vector<uint64_t> &relocSites) const;
>> @@ -501,10 +505,16 @@ static uint32_t getSectionStartAddr(uint
>> llvm_unreachable("Section missing");
>> }
>>
>> -void AtomChunk::applyRelocations32(uint8_t *buffer,
>> - std::map<const Atom *, uint64_t>
>> &atomRva,
>> - std::vector<uint64_t> §ionRva,
>> - uint64_t imageBaseAddress) {
>> +void AtomChunk::applyRelocationsARM(uint8_t *buffer,
>> + std::map<const Atom *, uint64_t>
>> &atomRva,
>> + std::vector<uint64_t> §ionRva,
>> + uint64_t imageBaseAddress) {
>> +}
>> +
>> +void AtomChunk::applyRelocationsX86_32(uint8_t *buffer,
>> + std::map<const Atom *, uint64_t>
>> &atomRva,
>> + std::vector<uint64_t> §ionRva,
>> + uint64_t imageBaseAddress) {
>> buffer += _fileOffset;
>> for (const auto *layout : _atomLayouts) {
>> const DefinedAtom *atom = cast<DefinedAtom>(layout->_atom);
>> @@ -554,10 +564,10 @@ void AtomChunk::applyRelocations32(uint8
>> }
>> }
>>
>> -void AtomChunk::applyRelocations64(uint8_t *buffer,
>> - std::map<const Atom *, uint64_t>
>> &atomRva,
>> - std::vector<uint64_t> §ionRva,
>> - uint64_t imageBase) {
>> +void AtomChunk::applyRelocationsX86_64(uint8_t *buffer,
>> + std::map<const Atom *, uint64_t>
>> &atomRva,
>> + std::vector<uint64_t> §ionRva,
>> + uint64_t imageBase) {
>> buffer += _fileOffset;
>> for (const auto *layout : _atomLayouts) {
>> const DefinedAtom *atom = cast<DefinedAtom>(layout->_atom);
>> @@ -1100,10 +1110,17 @@ void PECOFFWriter::applyAllRelocations(u
>> uint64_t base = _ctx.getBaseAddress();
>> for (auto &cp : _chunks) {
>> if (AtomChunk *chunk = dyn_cast<AtomChunk>(&*cp)) {
>> - if (_ctx.is64Bit()) {
>> - chunk->applyRelocations64(bufferStart, _atomRva, sectionRva,
>> base);
>> - } else {
>> - chunk->applyRelocations32(bufferStart, _atomRva, sectionRva,
>> base);
>> + switch (_ctx.getMachineType()) {
>> + default: llvm_unreachable("unsupported machine type");
>> + case llvm::COFF::IMAGE_FILE_MACHINE_ARMNT:
>> + chunk->applyRelocationsARM(bufferStart, _atomRva, sectionRva,
>> base);
>> + break;
>> + case llvm::COFF::IMAGE_FILE_MACHINE_I386:
>> + chunk->applyRelocationsX86_32(bufferStart, _atomRva, sectionRva,
>> base);
>> + break;
>> + case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
>> + chunk->applyRelocationsX86_64(bufferStart, _atomRva, sectionRva,
>> base);
>> + break;
>> }
>> }
>> }
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
--
Saleem Abdulrasool
compnerd (at) compnerd (dot) org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141006/64bdb46e/attachment.html>
More information about the llvm-commits
mailing list