Skip to content

Commit

Permalink
Remove relocHandler
Browse files Browse the repository at this point in the history
After removing relocatable resource, relocHandler hasn't been used.
Remove the related code.
  • Loading branch information
AMD-dwang committed Nov 9, 2023
1 parent 30e4be5 commit 4690ea6
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 368 deletions.
1 change: 0 additions & 1 deletion lgc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ target_sources(LLVMlgc PRIVATE
elfLinker/FetchShader.cpp
elfLinker/GlueShader.cpp
elfLinker/NullFragmentShader.cpp
elfLinker/RelocHandler.cpp
)

# lgc/patch
Expand Down
4 changes: 0 additions & 4 deletions lgc/builder/InOutBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,10 +1088,6 @@ Value *BuilderImpl::readCommonBuiltIn(BuiltInKind builtIn, llvm::Type *resultTy,
return CreateGetLaneNumber();

case BuiltInDeviceIndex:
// DeviceId is a constant from the pipeline state normally, or a reloc to get that constant
// at link time for an unlinked shader.
if (m_pipelineState->isUnlinked())
return CreateRelocationConstant(reloc::DeviceIdx);
return getInt32(getPipelineState()->getDeviceIndex());

default:
Expand Down
65 changes: 1 addition & 64 deletions lgc/elfLinker/ElfLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "lgc/ElfLinker.h"
#include "ColorExportShader.h"
#include "GlueShader.h"
#include "RelocHandler.h"
#include "lgc/state/AbiMetadata.h"
#include "lgc/state/PalMetadata.h"
#include "lgc/state/PipelineState.h"
Expand Down Expand Up @@ -198,9 +197,6 @@ class ElfLinkerImpl final : public ElfLinker {
// Processing when all inputs are done.
void doneInputs();

// Get the value of the symbol referenced in a reloc
bool getRelocValue(object::RelocationRef reloc, uint64_t &value);

// Find where an input section contributes to an output section
std::pair<unsigned, unsigned> findInputSection(ElfInput &elfInput, object::SectionRef section);

Expand All @@ -226,7 +222,6 @@ class ElfLinkerImpl final : public ElfLinker {
bool containsASingleShader(ElfInput &elf);

PipelineState *m_pipelineState; // PipelineState object
RelocHandler m_relocHandler; // RelocHandler object
SmallVector<ElfInput, 5> m_elfInputs; // ELF objects to link
SmallVector<std::unique_ptr<GlueShader>, 4> m_glueShaders; // Glue shaders needed for link
SmallVector<StringRef, 5> m_glueStrings; // Strings to return for glue shader cache keys
Expand Down Expand Up @@ -259,7 +254,7 @@ ElfLinker *createElfLinkerImpl(PipelineState *pipelineState, ArrayRef<MemoryBuff
// @param pipelineState : PipelineState object
// @param elfs : Array of unlinked ELF modules to link
ElfLinkerImpl::ElfLinkerImpl(PipelineState *pipelineState, ArrayRef<MemoryBufferRef> elfs)
: m_pipelineState(pipelineState), m_relocHandler(pipelineState) {
: m_pipelineState(pipelineState) {
m_pipelineState->clearPalMetadata();

// Add ELF inputs supplied here.
Expand Down Expand Up @@ -550,10 +545,6 @@ bool ElfLinkerImpl::link(raw_pwrite_stream &outStream) {
std::tie(targetSectionIdx, targetIdxInSection) =
findInputSection(elfInput, *cantFail(section.getRelocatedSection()));
if (targetSectionIdx != UINT_MAX) {
uint64_t value = 0;
if (getRelocValue(reloc, value)) {
continue;
}
(void)(textSectionIdx);
assert(targetSectionIdx == textSectionIdx && "We assume all relocations are applied to the text section");
assert(sectType == ELF::SHT_REL && "We do not output a RELA section yet");
Expand Down Expand Up @@ -587,47 +578,6 @@ bool ElfLinkerImpl::link(raw_pwrite_stream &outStream) {
outputSection.write(outStream, &shdrs[sectionIndex]);
}

// Apply the relocs
for (auto &elfInput : m_elfInputs) {
for (const object::SectionRef section : elfInput.objectFile->sections()) {
unsigned sectType = object::ELFSectionRef(section).getType();
if (sectType == ELF::SHT_REL || sectType == ELF::SHT_RELA) {
for (object::RelocationRef reloc : section.relocations()) {
unsigned outputSectIdx = UINT_MAX;
unsigned withinSectIdx = UINT_MAX;
std::tie(outputSectIdx, withinSectIdx) = findInputSection(elfInput, *cantFail(section.getRelocatedSection()));
if (outputSectIdx != UINT_MAX) {
uint64_t value = 0;
if (!getRelocValue(reloc, value)) {
continue;
}

uint64_t inputOffset = reloc.getOffset();
uint64_t outputOffset = m_outputSections[outputSectIdx].getOutputOffset(withinSectIdx) + inputOffset;
uint64_t addend = 0;
if (sectType == ELF::SHT_RELA)
addend = cantFail(object::ELFRelocationRef(reloc).getAddend());
switch (reloc.getType()) {

case ELF::R_AMDGPU_ABS32: {
StringRef contents = cantFail(cantFail(section.getRelocatedSection())->getContents());
assert(inputOffset + sizeof(uint32_t) <= contents.size() && "Out of range reloc offset");
if (sectType == ELF::SHT_REL)
addend = *reinterpret_cast<const uint32_t *>(contents.data() + inputOffset);
uint32_t inst = addend + value;
outStream.pwrite(reinterpret_cast<const char *>(&inst), sizeof(inst), outputOffset);
break;
}

default:
report_fatal_error("Reloc not supported");
}
}
}
}
}
}

OutputSection &noteOutputSection = m_outputSections[noteSectionIdx];
Align align = std::min(noteOutputSection.getAlignment(), Align(4));

Expand Down Expand Up @@ -694,19 +644,6 @@ unsigned ElfLinkerImpl::findSymbol(StringRef name) {
return findSymbol(nameIndex);
}

// =====================================================================================================================
// Get the value of the symbol referenced in a reloc.
//
// @param reloc : The relocation for which to find the value.
// @param [out] value: The value for the relocation if it is found.
// @returns : True if the value for the relocation was found. False otherwise.
bool ElfLinkerImpl::getRelocValue(object::RelocationRef reloc, uint64_t &value) {
StringRef name = cantFail(reloc.getSymbol()->getName());

// Handle the special case relocs from pipeline state
return m_relocHandler.getValue(name, value);
}

// =====================================================================================================================
// Find where an input section contributes to an output section
//
Expand Down
196 changes: 0 additions & 196 deletions lgc/elfLinker/RelocHandler.cpp

This file was deleted.

54 changes: 0 additions & 54 deletions lgc/elfLinker/RelocHandler.h

This file was deleted.

Loading

0 comments on commit 4690ea6

Please sign in to comment.