Skip to content

[LLD][COFF][NFC] Use getMachineArchType helper. #87495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions lld/COFF/Chunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,19 +437,17 @@ void SectionChunk::applyRelocation(uint8_t *off,
// Compute the RVA of the relocation for relative relocations.
uint64_t p = rva + rel.VirtualAddress;
uint64_t imageBase = file->ctx.config.imageBase;
switch (getMachine()) {
case AMD64:
switch (getArch()) {
case Triple::x86_64:
applyRelX64(off, rel.Type, os, s, p, imageBase);
break;
case I386:
case Triple::x86:
applyRelX86(off, rel.Type, os, s, p, imageBase);
break;
case ARMNT:
case Triple::thumb:
applyRelARM(off, rel.Type, os, s, p, imageBase);
break;
case ARM64:
case ARM64EC:
case ARM64X:
case Triple::aarch64:
applyRelARM64(off, rel.Type, os, s, p, imageBase);
break;
default:
Expand Down Expand Up @@ -516,27 +514,25 @@ void SectionChunk::addAssociative(SectionChunk *child) {
}

static uint8_t getBaserelType(const coff_relocation &rel,
llvm::COFF::MachineTypes machine) {
switch (machine) {
case AMD64:
Triple::ArchType arch) {
switch (arch) {
case Triple::x86_64:
if (rel.Type == IMAGE_REL_AMD64_ADDR64)
return IMAGE_REL_BASED_DIR64;
if (rel.Type == IMAGE_REL_AMD64_ADDR32)
return IMAGE_REL_BASED_HIGHLOW;
return IMAGE_REL_BASED_ABSOLUTE;
case I386:
case Triple::x86:
if (rel.Type == IMAGE_REL_I386_DIR32)
return IMAGE_REL_BASED_HIGHLOW;
return IMAGE_REL_BASED_ABSOLUTE;
case ARMNT:
case Triple::thumb:
if (rel.Type == IMAGE_REL_ARM_ADDR32)
return IMAGE_REL_BASED_HIGHLOW;
if (rel.Type == IMAGE_REL_ARM_MOV32T)
return IMAGE_REL_BASED_ARM_MOV32T;
return IMAGE_REL_BASED_ABSOLUTE;
case ARM64:
case ARM64EC:
case ARM64X:
case Triple::aarch64:
if (rel.Type == IMAGE_REL_ARM64_ADDR64)
return IMAGE_REL_BASED_DIR64;
return IMAGE_REL_BASED_ABSOLUTE;
Expand All @@ -551,7 +547,7 @@ static uint8_t getBaserelType(const coff_relocation &rel,
// Only called when base relocation is enabled.
void SectionChunk::getBaserels(std::vector<Baserel> *res) {
for (const coff_relocation &rel : getRelocs()) {
uint8_t ty = getBaserelType(rel, getMachine());
uint8_t ty = getBaserelType(rel, getArch());
if (ty == IMAGE_REL_BASED_ABSOLUTE)
continue;
Symbol *target = file->getSymbol(rel.SymbolTableIndex);
Expand Down
6 changes: 6 additions & 0 deletions lld/COFF/Chunks.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/ADT/iterator_range.h"
#include "llvm/MC/StringTableBuilder.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/WindowsMachineFlag.h"
#include <utility>
#include <vector>

Expand Down Expand Up @@ -116,6 +117,7 @@ class Chunk {
bool isHotPatchable() const;

MachineTypes getMachine() const;
llvm::Triple::ArchType getArch() const;
std::optional<chpe_range_type> getArm64ECRangeType() const;

protected:
Expand Down Expand Up @@ -437,6 +439,10 @@ inline MachineTypes Chunk::getMachine() const {
return static_cast<const NonSectionChunk *>(this)->getMachine();
}

inline llvm::Triple::ArchType Chunk::getArch() const {
return llvm::getMachineArchType(getMachine());
}

inline std::optional<chpe_range_type> Chunk::getArm64ECRangeType() const {
// Data sections don't need codemap entries.
if (!(getOutputCharacteristics() & llvm::COFF::IMAGE_SCN_MEM_EXECUTE))
Expand Down
1 change: 0 additions & 1 deletion lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "llvm/Object/ArchiveWriter.h"
#include "llvm/Object/COFFImportFile.h"
#include "llvm/Object/COFFModuleDefinition.h"
#include "llvm/Object/WindowsMachineFlag.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
Expand Down
1 change: 0 additions & 1 deletion lld/COFF/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/LTO/LTO.h"
#include "llvm/Object/WindowsMachineFlag.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <utility>
Expand Down