2017-06-17 01:32:43 +08:00
|
|
|
//===- PPC.cpp ------------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2017-06-17 01:32:43 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Symbols.h"
|
|
|
|
#include "Target.h"
|
[lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.
Reviewers: ruiu
Reviewed By: ruiu
Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D39259
llvm-svn: 316624
2017-10-26 06:28:38 +08:00
|
|
|
#include "lld/Common/ErrorHandler.h"
|
2017-06-17 01:32:43 +08:00
|
|
|
#include "llvm/Support/Endian.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::support::endian;
|
|
|
|
using namespace llvm::ELF;
|
|
|
|
using namespace lld;
|
|
|
|
using namespace lld::elf;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class PPC final : public TargetInfo {
|
|
|
|
public:
|
2018-03-19 14:52:51 +08:00
|
|
|
PPC();
|
2017-10-12 06:49:24 +08:00
|
|
|
void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;
|
2017-11-04 05:21:47 +08:00
|
|
|
RelExpr getRelExpr(RelType Type, const Symbol &S,
|
2017-06-17 01:32:43 +08:00
|
|
|
const uint8_t *Loc) const override;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2018-03-19 14:52:51 +08:00
|
|
|
PPC::PPC() {
|
2018-09-26 16:11:34 +08:00
|
|
|
NoneRel = R_PPC_NONE;
|
2018-03-19 14:52:51 +08:00
|
|
|
GotBaseSymOff = 0x8000;
|
|
|
|
GotBaseSymInGotPlt = false;
|
|
|
|
}
|
|
|
|
|
2017-11-04 05:21:47 +08:00
|
|
|
RelExpr PPC::getRelExpr(RelType Type, const Symbol &S,
|
2017-10-12 11:14:06 +08:00
|
|
|
const uint8_t *Loc) const {
|
|
|
|
switch (Type) {
|
2018-12-04 20:26:21 +08:00
|
|
|
case R_PPC_REL14:
|
2017-10-12 11:14:06 +08:00
|
|
|
case R_PPC_REL24:
|
|
|
|
case R_PPC_REL32:
|
|
|
|
return R_PC;
|
2017-12-10 16:42:34 +08:00
|
|
|
case R_PPC_PLTREL24:
|
2017-12-12 06:40:18 +08:00
|
|
|
return R_PLT_PC;
|
2017-10-12 11:14:06 +08:00
|
|
|
default:
|
|
|
|
return R_ABS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-12 06:49:24 +08:00
|
|
|
void PPC::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
|
2017-06-17 01:32:43 +08:00
|
|
|
switch (Type) {
|
|
|
|
case R_PPC_ADDR16_HA:
|
|
|
|
write16be(Loc, (Val + 0x8000) >> 16);
|
|
|
|
break;
|
2017-10-23 07:33:49 +08:00
|
|
|
case R_PPC_ADDR16_HI:
|
|
|
|
write16be(Loc, Val >> 16);
|
|
|
|
break;
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_PPC_ADDR16_LO:
|
|
|
|
write16be(Loc, Val);
|
|
|
|
break;
|
|
|
|
case R_PPC_ADDR32:
|
|
|
|
case R_PPC_REL32:
|
|
|
|
write32be(Loc, Val);
|
|
|
|
break;
|
2018-12-04 20:26:21 +08:00
|
|
|
case R_PPC_REL14:
|
|
|
|
write32be(Loc, read32be(Loc) | (Val & 0xFFFC));
|
|
|
|
break;
|
2017-12-10 16:42:34 +08:00
|
|
|
case R_PPC_PLTREL24:
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_PPC_REL24:
|
|
|
|
write32be(Loc, read32be(Loc) | (Val & 0x3FFFFFC));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-17 04:15:03 +08:00
|
|
|
TargetInfo *elf::getPPCTargetInfo() {
|
|
|
|
static PPC Target;
|
|
|
|
return &Target;
|
|
|
|
}
|