CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
144 lines
5.0 KiB
C++
144 lines
5.0 KiB
C++
//===-- SparcELFObjectWriter.cpp - Sparc ELF Writer -----------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "MCTargetDesc/SparcFixupKinds.h"
|
|
#include "MCTargetDesc/SparcMCTargetDesc.h"
|
|
#include "llvm/MC/MCContext.h"
|
|
#include "llvm/MC/MCELFObjectWriter.h"
|
|
#include "llvm/MC/MCExpr.h"
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
|
#include "llvm/MC/MCObjectWriter.h"
|
|
#include "llvm/MC/MCValue.h"
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
class SparcELFObjectWriter : public MCELFObjectTargetWriter {
|
|
public:
|
|
SparcELFObjectWriter(bool Is64Bit, bool IsV8Plus, uint8_t OSABI)
|
|
: MCELFObjectTargetWriter(
|
|
Is64Bit, OSABI,
|
|
Is64Bit ? ELF::EM_SPARCV9
|
|
: (IsV8Plus ? ELF::EM_SPARC32PLUS : ELF::EM_SPARC),
|
|
/*HasRelocationAddend*/ true) {}
|
|
|
|
~SparcELFObjectWriter() override = default;
|
|
|
|
protected:
|
|
unsigned getRelocType(const MCFixup &Fixup, const MCValue &Target,
|
|
bool IsPCRel) const override;
|
|
|
|
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
|
|
};
|
|
}
|
|
|
|
unsigned SparcELFObjectWriter::getRelocType(const MCFixup &Fixup,
|
|
const MCValue &Target,
|
|
bool IsPCRel) const {
|
|
switch (Target.getSpecifier()) {
|
|
case ELF::R_SPARC_TLS_GD_HI22:
|
|
case ELF::R_SPARC_TLS_GD_LO10:
|
|
case ELF::R_SPARC_TLS_GD_ADD:
|
|
case ELF::R_SPARC_TLS_LDM_HI22:
|
|
case ELF::R_SPARC_TLS_LDM_LO10:
|
|
case ELF::R_SPARC_TLS_LDM_ADD:
|
|
case ELF::R_SPARC_TLS_LDO_HIX22:
|
|
case ELF::R_SPARC_TLS_LDO_LOX10:
|
|
case ELF::R_SPARC_TLS_LDO_ADD:
|
|
case ELF::R_SPARC_TLS_IE_HI22:
|
|
case ELF::R_SPARC_TLS_IE_LO10:
|
|
case ELF::R_SPARC_TLS_IE_LD:
|
|
case ELF::R_SPARC_TLS_IE_LDX:
|
|
case ELF::R_SPARC_TLS_IE_ADD:
|
|
case ELF::R_SPARC_TLS_LE_HIX22:
|
|
case ELF::R_SPARC_TLS_LE_LOX10:
|
|
if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
|
|
static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// Extract the relocation type from the fixup kind, after applying STT_TLS as
|
|
// needed.
|
|
auto Kind = Fixup.getKind();
|
|
if (mc::isRelocation(Fixup.getKind()))
|
|
return Kind;
|
|
|
|
if (const auto *SExpr = dyn_cast<MCSpecifierExpr>(Fixup.getValue())) {
|
|
if (SExpr->getSpecifier() == ELF::R_SPARC_DISP32)
|
|
return ELF::R_SPARC_DISP32;
|
|
}
|
|
|
|
if (IsPCRel) {
|
|
switch (Kind) {
|
|
default:
|
|
llvm_unreachable("Unimplemented fixup -> relocation");
|
|
case FK_Data_1: return ELF::R_SPARC_DISP8;
|
|
case FK_Data_2: return ELF::R_SPARC_DISP16;
|
|
case FK_Data_4: return ELF::R_SPARC_DISP32;
|
|
case FK_Data_8: return ELF::R_SPARC_DISP64;
|
|
case Sparc::fixup_sparc_call30:
|
|
if (getContext().getObjectFileInfo()->isPositionIndependent())
|
|
return ELF::R_SPARC_WPLT30;
|
|
return ELF::R_SPARC_WDISP30;
|
|
}
|
|
}
|
|
|
|
// clang-format off
|
|
switch(Fixup.getKind()) {
|
|
default:
|
|
llvm_unreachable("Unimplemented fixup -> relocation");
|
|
case FK_NONE: return ELF::R_SPARC_NONE;
|
|
case FK_Data_1: return ELF::R_SPARC_8;
|
|
case FK_Data_2: return ((Fixup.getOffset() % 2)
|
|
? ELF::R_SPARC_UA16
|
|
: ELF::R_SPARC_16);
|
|
case FK_Data_4: return ((Fixup.getOffset() % 4)
|
|
? ELF::R_SPARC_UA32
|
|
: ELF::R_SPARC_32);
|
|
case FK_Data_8: return ((Fixup.getOffset() % 8)
|
|
? ELF::R_SPARC_UA64
|
|
: ELF::R_SPARC_64);
|
|
case Sparc::fixup_sparc_13:
|
|
if (getContext().getObjectFileInfo()->isPositionIndependent())
|
|
return ELF::R_SPARC_GOT13;
|
|
return ELF::R_SPARC_13;
|
|
}
|
|
// clang-format on
|
|
|
|
return ELF::R_SPARC_NONE;
|
|
}
|
|
|
|
bool SparcELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
|
|
unsigned Type) const {
|
|
switch (Type) {
|
|
default:
|
|
return false;
|
|
|
|
// All relocations that use a GOT need a symbol, not an offset, as
|
|
// the offset of the symbol within the section is irrelevant to
|
|
// where the GOT entry is. Don't need to list all the TLS entries,
|
|
// as they're all marked as requiring a symbol anyways.
|
|
case ELF::R_SPARC_GOT10:
|
|
case ELF::R_SPARC_GOT13:
|
|
case ELF::R_SPARC_GOT22:
|
|
case ELF::R_SPARC_GOTDATA_HIX22:
|
|
case ELF::R_SPARC_GOTDATA_LOX10:
|
|
case ELF::R_SPARC_GOTDATA_OP_HIX22:
|
|
case ELF::R_SPARC_GOTDATA_OP_LOX10:
|
|
return true;
|
|
}
|
|
}
|
|
|
|
std::unique_ptr<MCObjectTargetWriter>
|
|
llvm::createSparcELFObjectWriter(bool Is64Bit, bool IsV8Plus, uint8_t OSABI) {
|
|
return std::make_unique<SparcELFObjectWriter>(Is64Bit, IsV8Plus, OSABI);
|
|
}
|