2017-06-16 17:32:43 +00:00
|
|
|
//===- AMDGPU.cpp ---------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 08:50:56 +00: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-16 17:32:43 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "InputFiles.h"
|
|
|
|
#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-25 22:28:38 +00:00
|
|
|
#include "lld/Common/ErrorHandler.h"
|
2017-06-16 17:32:43 +00:00
|
|
|
#include "llvm/Object/ELF.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 AMDGPU final : public TargetInfo {
|
|
|
|
public:
|
|
|
|
AMDGPU();
|
2017-10-24 19:05:32 +00:00
|
|
|
uint32_t calcEFlags() const override;
|
2017-10-11 22:49:24 +00:00
|
|
|
void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;
|
2017-11-03 21:21:47 +00:00
|
|
|
RelExpr getRelExpr(RelType Type, const Symbol &S,
|
2017-06-16 17:32:43 +00:00
|
|
|
const uint8_t *Loc) const override;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
AMDGPU::AMDGPU() {
|
2017-10-16 20:46:53 +00:00
|
|
|
RelativeRel = R_AMDGPU_RELATIVE64;
|
2017-06-16 17:32:43 +00:00
|
|
|
GotRel = R_AMDGPU_ABS64;
|
2018-09-26 08:11:34 +00:00
|
|
|
NoneRel = R_AMDGPU_NONE;
|
2017-06-16 17:32:43 +00:00
|
|
|
GotEntrySize = 8;
|
|
|
|
}
|
|
|
|
|
2017-10-24 19:40:03 +00:00
|
|
|
static uint32_t getEFlags(InputFile *File) {
|
|
|
|
return cast<ObjFile<ELF64LE>>(File)->getObj().getHeader()->e_flags;
|
|
|
|
}
|
2017-10-24 19:05:32 +00:00
|
|
|
|
2017-10-24 19:40:03 +00:00
|
|
|
uint32_t AMDGPU::calcEFlags() const {
|
|
|
|
assert(!ObjectFiles.empty());
|
|
|
|
uint32_t Ret = getEFlags(ObjectFiles[0]);
|
2017-10-24 19:05:32 +00:00
|
|
|
|
|
|
|
// Verify that all input files have the same e_flags.
|
2017-10-24 19:40:03 +00:00
|
|
|
for (InputFile *F : makeArrayRef(ObjectFiles).slice(1)) {
|
|
|
|
if (Ret == getEFlags(F))
|
|
|
|
continue;
|
|
|
|
error("incompatible e_flags: " + toString(F));
|
|
|
|
return 0;
|
2017-10-24 19:05:32 +00:00
|
|
|
}
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2017-10-11 22:49:24 +00:00
|
|
|
void AMDGPU::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
|
2017-06-16 17:32:43 +00:00
|
|
|
switch (Type) {
|
|
|
|
case R_AMDGPU_ABS32:
|
|
|
|
case R_AMDGPU_GOTPCREL:
|
|
|
|
case R_AMDGPU_GOTPCREL32_LO:
|
|
|
|
case R_AMDGPU_REL32:
|
|
|
|
case R_AMDGPU_REL32_LO:
|
|
|
|
write32le(Loc, Val);
|
|
|
|
break;
|
|
|
|
case R_AMDGPU_ABS64:
|
2018-06-11 21:42:53 +00:00
|
|
|
case R_AMDGPU_REL64:
|
2017-06-16 17:32:43 +00:00
|
|
|
write64le(Loc, Val);
|
|
|
|
break;
|
|
|
|
case R_AMDGPU_GOTPCREL32_HI:
|
|
|
|
case R_AMDGPU_REL32_HI:
|
|
|
|
write32le(Loc, Val >> 32);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 21:21:47 +00:00
|
|
|
RelExpr AMDGPU::getRelExpr(RelType Type, const Symbol &S,
|
2017-10-12 03:14:06 +00:00
|
|
|
const uint8_t *Loc) const {
|
2017-06-16 17:32:43 +00:00
|
|
|
switch (Type) {
|
|
|
|
case R_AMDGPU_ABS32:
|
|
|
|
case R_AMDGPU_ABS64:
|
|
|
|
return R_ABS;
|
|
|
|
case R_AMDGPU_REL32:
|
|
|
|
case R_AMDGPU_REL32_LO:
|
|
|
|
case R_AMDGPU_REL32_HI:
|
2018-06-11 21:42:53 +00:00
|
|
|
case R_AMDGPU_REL64:
|
2017-06-16 17:32:43 +00:00
|
|
|
return R_PC;
|
|
|
|
case R_AMDGPU_GOTPCREL:
|
|
|
|
case R_AMDGPU_GOTPCREL32_LO:
|
|
|
|
case R_AMDGPU_GOTPCREL32_HI:
|
|
|
|
return R_GOT_PC;
|
|
|
|
default:
|
2017-10-12 03:14:06 +00:00
|
|
|
return R_INVALID;
|
2017-06-16 17:32:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-16 20:15:03 +00:00
|
|
|
TargetInfo *elf::getAMDGPUTargetInfo() {
|
|
|
|
static AMDGPU Target;
|
|
|
|
return &Target;
|
|
|
|
}
|