Bill Schmidt | 22d40dc | 2013-05-13 19:34:37 +0000 | [diff] [blame] | 1 | //===-- PPCTargetObjectFile.cpp - PPC Object Info -------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "PPCTargetObjectFile.h" |
Rafael Espindola | 894843c | 2014-01-07 21:19:40 +0000 | [diff] [blame] | 11 | #include "llvm/IR/Mangler.h" |
Bill Schmidt | 22d40dc | 2013-05-13 19:34:37 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCContext.h" |
| 13 | #include "llvm/MC/MCExpr.h" |
| 14 | #include "llvm/MC/MCSectionELF.h" |
Bill Schmidt | 22d40dc | 2013-05-13 19:34:37 +0000 | [diff] [blame] | 15 | |
| 16 | using namespace llvm; |
| 17 | |
| 18 | void |
| 19 | PPC64LinuxTargetObjectFile:: |
| 20 | Initialize(MCContext &Ctx, const TargetMachine &TM) { |
| 21 | TargetLoweringObjectFileELF::Initialize(Ctx, TM); |
| 22 | InitializeELF(TM.Options.UseInitArray); |
| 23 | } |
| 24 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 25 | MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal( |
Rafael Espindola | fa0f728 | 2014-02-08 14:53:28 +0000 | [diff] [blame] | 26 | const GlobalValue *GV, SectionKind Kind, Mangler &Mang, |
| 27 | const TargetMachine &TM) const { |
Bill Schmidt | 6cda22a | 2013-05-13 19:40:36 +0000 | [diff] [blame] | 28 | // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI |
Bill Schmidt | 22d40dc | 2013-05-13 19:34:37 +0000 | [diff] [blame] | 29 | // when we have a constant that contains global relocations. This is |
| 30 | // necessary because of this ABI's handling of pointers to functions in |
| 31 | // a shared library. The address of a function is actually the address |
| 32 | // of a function descriptor, which resides in the .opd section. Generated |
| 33 | // code uses the descriptor directly rather than going via the GOT as some |
| 34 | // other ABIs do, which means that initialized function pointers must |
| 35 | // reference the descriptor. The linker must convert copy relocs of |
| 36 | // pointers to functions in shared libraries into dynamic relocations, |
| 37 | // because of an ordering problem with initialization of copy relocs and |
| 38 | // PLT entries. The dynamic relocation will be initialized by the dynamic |
Bill Schmidt | 6cda22a | 2013-05-13 19:40:36 +0000 | [diff] [blame] | 39 | // linker, so we must use DataRelROSection instead of ReadOnlySection. |
Bill Schmidt | 22d40dc | 2013-05-13 19:34:37 +0000 | [diff] [blame] | 40 | // For more information, see the description of ELIMINATE_COPY_RELOCS in |
| 41 | // GNU ld. |
Ulrich Weigand | f445399 | 2014-03-14 12:45:22 +0000 | [diff] [blame] | 42 | if (Kind.isReadOnly()) { |
| 43 | const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); |
Bill Schmidt | 22d40dc | 2013-05-13 19:34:37 +0000 | [diff] [blame] | 44 | |
Ulrich Weigand | f445399 | 2014-03-14 12:45:22 +0000 | [diff] [blame] | 45 | if (GVar && GVar->isConstant() && |
| 46 | (GVar->getInitializer()->getRelocationInfo() == |
| 47 | Constant::GlobalRelocations)) |
| 48 | Kind = SectionKind::getReadOnlyWithRel(); |
| 49 | } |
Bill Schmidt | 22d40dc | 2013-05-13 19:34:37 +0000 | [diff] [blame] | 50 | |
Ulrich Weigand | f445399 | 2014-03-14 12:45:22 +0000 | [diff] [blame] | 51 | return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, |
| 52 | Mang, TM); |
Bill Schmidt | 22d40dc | 2013-05-13 19:34:37 +0000 | [diff] [blame] | 53 | } |
Ulrich Weigand | 0f03982 | 2013-07-02 18:47:35 +0000 | [diff] [blame] | 54 | |
| 55 | const MCExpr *PPC64LinuxTargetObjectFile:: |
| 56 | getDebugThreadLocalSymbol(const MCSymbol *Sym) const { |
| 57 | const MCExpr *Expr = |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame^] | 58 | MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_PPC_DTPREL, getContext()); |
| 59 | return MCBinaryExpr::createAdd(Expr, |
| 60 | MCConstantExpr::create(0x8000, getContext()), |
Ulrich Weigand | 0f03982 | 2013-07-02 18:47:35 +0000 | [diff] [blame] | 61 | getContext()); |
| 62 | } |
| 63 | |