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