2025-10-25 22:30:05 -04:00

65 lines
1.7 KiB
C++

//===-- Foot.cpp -------------------------------------------------------===//
//
// 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 "InputFiles.h"
#include "OutputSections.h"
#include "Symbols.h"
#include "SyntheticSections.h"
#include "Target.h"
#include "Thunks.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Support/ELFAttributes.h"
#include "llvm/Support/Endian.h"
using namespace llvm;
using namespace llvm::object;
using namespace llvm::support::endian;
using namespace llvm::ELF;
using namespace lld;
using namespace lld::elf;
namespace {
class Foot final : public TargetInfo {
public:
Foot(Ctx &);
RelExpr getRelExpr(RelType type, const Symbol &s,
const uint8_t *loc) const override;
void relocate(uint8_t *loc, const Relocation &rel,
uint64_t val) const override;
};
} // namespace
Foot::Foot(Ctx &ctx) : TargetInfo(ctx) {
defaultImageBase = 0;
}
RelExpr Foot::getRelExpr(RelType type, const Symbol &s,
const uint8_t *loc) const {
return R_ABS;
}
void Foot::relocate(uint8_t *loc, const Relocation &rel,
uint64_t val) const {
switch (rel.type) {
case R_FOOT_CNST16:
checkUInt(ctx, loc, val, 16, rel);
write16le(loc, val / 4); // foot is 32-bit addressable
break;
default:
llvm_unreachable("Unknown relocation type");
}
}
void lld::elf::setFootTargetInfo(Ctx &ctx) {
ctx.target.reset(new Foot(ctx));
}