2013-05-14 03:34:37 +08:00
|
|
|
//===-- PPCTargetObjectFile.cpp - PPC Object Info -------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "PPCTargetObjectFile.h"
|
2014-01-08 05:19:40 +08:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2013-05-14 03:34:37 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/MC/MCSectionELF.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
void
|
|
|
|
PPC64LinuxTargetObjectFile::
|
|
|
|
Initialize(MCContext &Ctx, const TargetMachine &TM) {
|
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
|
|
InitializeELF(TM.Options.UseInitArray);
|
|
|
|
}
|
|
|
|
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal(
|
2014-02-08 22:53:28 +08:00
|
|
|
const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
|
|
|
|
const TargetMachine &TM) const {
|
2013-05-14 03:40:36 +08:00
|
|
|
// Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI
|
2013-05-14 03:34:37 +08:00
|
|
|
// when we have a constant that contains global relocations. This is
|
|
|
|
// necessary because of this ABI's handling of pointers to functions in
|
|
|
|
// a shared library. The address of a function is actually the address
|
|
|
|
// of a function descriptor, which resides in the .opd section. Generated
|
|
|
|
// code uses the descriptor directly rather than going via the GOT as some
|
|
|
|
// other ABIs do, which means that initialized function pointers must
|
|
|
|
// reference the descriptor. The linker must convert copy relocs of
|
|
|
|
// pointers to functions in shared libraries into dynamic relocations,
|
|
|
|
// because of an ordering problem with initialization of copy relocs and
|
|
|
|
// PLT entries. The dynamic relocation will be initialized by the dynamic
|
2013-05-14 03:40:36 +08:00
|
|
|
// linker, so we must use DataRelROSection instead of ReadOnlySection.
|
2013-05-14 03:34:37 +08:00
|
|
|
// For more information, see the description of ELIMINATE_COPY_RELOCS in
|
|
|
|
// GNU ld.
|
2014-03-14 20:45:22 +08:00
|
|
|
if (Kind.isReadOnly()) {
|
|
|
|
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
|
2013-05-14 03:34:37 +08:00
|
|
|
|
2015-11-17 08:51:23 +08:00
|
|
|
if (GVar && GVar->isConstant() && GVar->getInitializer()->needsRelocation())
|
2014-03-14 20:45:22 +08:00
|
|
|
Kind = SectionKind::getReadOnlyWithRel();
|
|
|
|
}
|
2013-05-14 03:34:37 +08:00
|
|
|
|
2014-03-14 20:45:22 +08:00
|
|
|
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind,
|
|
|
|
Mang, TM);
|
2013-05-14 03:34:37 +08:00
|
|
|
}
|
2013-07-03 02:47:35 +08:00
|
|
|
|
|
|
|
const MCExpr *PPC64LinuxTargetObjectFile::
|
|
|
|
getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
|
|
|
|
const MCExpr *Expr =
|
2016-02-11 02:32:01 +08:00
|
|
|
MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPREL, getContext());
|
2015-05-30 09:25:56 +08:00
|
|
|
return MCBinaryExpr::createAdd(Expr,
|
|
|
|
MCConstantExpr::create(0x8000, getContext()),
|
2013-07-03 02:47:35 +08:00
|
|
|
getContext());
|
|
|
|
}
|
|
|
|
|