-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NFC] Decouple the dependency on both X86 and ARM target builds
to allow for single target build (either X86 or ARM) of llvm-mctoll
- Loading branch information
1 parent
116e832
commit f4b690b
Showing
14 changed files
with
426 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//===- ARMModuleRaiser.h - Binary raiser utility llvm-mctoll --------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file contains the declaration of ARMModuleRaiser class for use by | ||
// llvm-mctoll. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "ARMModuleRaiser.h" | ||
#include "llvm/Object/ELFObjectFile.h" | ||
|
||
using namespace llvm; | ||
|
||
namespace RaiserContext { | ||
extern SmallVector<ModuleRaiser *, 4> ModuleRaiserRegistry; | ||
} | ||
|
||
bool ARMModuleRaiser::collectDynamicRelocations() { | ||
if (!Obj->isELF()) { | ||
return false; | ||
} | ||
|
||
const ELF32LEObjectFile *Elf32LEObjFile = dyn_cast<ELF32LEObjectFile>(Obj); | ||
if (!Elf32LEObjFile) { | ||
return false; | ||
} | ||
|
||
std::vector<SectionRef> DynRelSec = Obj->dynamic_relocation_sections(); | ||
|
||
for (const SectionRef &Section : DynRelSec) { | ||
for (const RelocationRef &Reloc : Section.relocations()) { | ||
DynRelocs.push_back(Reloc); | ||
} | ||
} | ||
|
||
// Get relocations of .got.plt section from .rela.plt if it exists. I do not | ||
// see an API in ObjectFile class to get at these. | ||
|
||
// Find .got.plt and .rel.plt sections Note: A lot of verification and double | ||
// checking done in the following code. | ||
const ELFFile<ELF32LE> *ElfFile = Elf32LEObjFile->getELFFile(); | ||
// Find .rel.plt | ||
SectionRef DotGotDotPltSec, DotRelaDotPltSec; | ||
for (const SectionRef Section : Obj->sections()) { | ||
StringRef SecName; | ||
Section.getName(SecName); | ||
if (SecName.equals(".rel.plt")) { | ||
DotRelaDotPltSec = Section; | ||
} else if (SecName.equals(".got")) { | ||
DotGotDotPltSec = Section; | ||
} | ||
} | ||
|
||
if (DotRelaDotPltSec.getObject() != nullptr) { | ||
// Do some additional sanity checks | ||
assert((DotGotDotPltSec.getObject() != nullptr) && | ||
"Failed to find .got section"); | ||
auto DotRelaDotPltShdr = ElfFile->getSection(DotRelaDotPltSec.getIndex()); | ||
assert(DotRelaDotPltShdr && "Failed to find .rel.plt section"); | ||
for (const RelocationRef &Reloc : DotRelaDotPltSec.relocations()) { | ||
DynRelocs.push_back(Reloc); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
void InitializeARMModuleRaiser() { | ||
ModuleRaiser *m = new ARMModuleRaiser(); | ||
RaiserContext::ModuleRaiserRegistry.push_back(m); | ||
return; | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===- ARMModuleRaiser.h ----------------------------------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file contains the declaration of ARMModuleRaiser class for use by | ||
// llvm-mctoll. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_TOOLS_LLVM_MCTOLL_ARM_ARMMODULERAISER_H | ||
#define LLVM_TOOLS_LLVM_MCTOLL_ARM_ARMMODULERAISER_H | ||
|
||
#include "ModuleRaiser.h" | ||
|
||
using namespace llvm; | ||
|
||
class ARMModuleRaiser : public ModuleRaiser { | ||
public: | ||
ARMModuleRaiser() : ModuleRaiser() { Arch = Triple::arm; } | ||
|
||
// Create a new MachineFunctionRaiser object and add it to the list of | ||
// MachineFunction raiser objects of this module. | ||
MachineFunctionRaiser * | ||
CreateAndAddMachineFunctionRaiser(Function *f, const ModuleRaiser *mr, | ||
uint64_t start, uint64_t end); | ||
bool collectDynamicRelocations(); | ||
}; | ||
|
||
#endif // LLVM_TOOLS_LLVM_MCTOLL_ARM_ARMMODULERAISER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.