2016-05-25 04:24:43 +08:00
|
|
|
//===- Relocations.h -------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
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
|
2016-05-25 04:24:43 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_ELF_RELOCATIONS_H
|
|
|
|
#define LLD_ELF_RELOCATIONS_H
|
|
|
|
|
2017-10-03 05:00:41 +08:00
|
|
|
#include "lld/Common/LLVM.h"
|
2017-04-05 18:30:09 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
2016-05-25 04:24:43 +08:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf {
|
2017-11-04 05:21:47 +08:00
|
|
|
class Symbol;
|
2017-02-24 00:49:07 +08:00
|
|
|
class InputSection;
|
2017-02-23 10:28:28 +08:00
|
|
|
class InputSectionBase;
|
2017-02-24 23:07:30 +08:00
|
|
|
class OutputSection;
|
2018-03-10 01:54:43 +08:00
|
|
|
class SectionBase;
|
2016-05-25 04:24:43 +08:00
|
|
|
|
2017-10-12 06:49:24 +08:00
|
|
|
// Represents a relocation type, such as R_X86_64_PC32 or R_ARM_THM_CALL.
|
2019-04-01 08:11:24 +08:00
|
|
|
using RelType = uint32_t;
|
2020-04-07 21:48:18 +08:00
|
|
|
using JumpModType = uint32_t;
|
2017-10-12 06:49:24 +08:00
|
|
|
|
2016-10-21 12:52:11 +08:00
|
|
|
// List of target-independent relocation types. Relocations read
|
|
|
|
// from files are converted to these types so that the main code
|
|
|
|
// doesn't have to know about architecture-specific details.
|
2016-05-25 04:24:43 +08:00
|
|
|
enum RelExpr {
|
|
|
|
R_ABS,
|
2018-02-16 18:01:17 +08:00
|
|
|
R_ADDEND,
|
2019-04-22 11:10:40 +08:00
|
|
|
R_DTPREL,
|
2016-05-25 04:24:43 +08:00
|
|
|
R_GOT,
|
|
|
|
R_GOT_OFF,
|
|
|
|
R_GOT_PC,
|
[ELF] Change GOT*_FROM_END (relative to end(.got)) to GOTPLT* (start(.got.plt))
Summary:
This should address remaining issues discussed in PR36555.
Currently R_GOT*_FROM_END are exclusively used by x86 and x86_64 to
express relocations types relative to the GOT base. We have
_GLOBAL_OFFSET_TABLE_ (GOT base) = start(.got.plt) but end(.got) !=
start(.got.plt)
This can have problems when _GLOBAL_OFFSET_TABLE_ is used as a symbol, e.g.
glibc dl_machine_dynamic assumes _GLOBAL_OFFSET_TABLE_ is start(.got.plt),
which is not true.
extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
return _GLOBAL_OFFSET_TABLE_[0]; // R_X86_64_GOTPC32
In this patch, we
* Change all GOT*_FROM_END to GOTPLT* to fix the problem.
* Add HasGotPltOffRel to denote whether .got.plt should be kept even if
the section is empty.
* Simplify GotSection::empty and GotPltSection::empty by setting
HasGotOffRel and HasGotPltOffRel according to GlobalOffsetTable early.
The change of R_386_GOTPC makes X86::writePltHeader simpler as we don't
have to compute the offset start(.got.plt) - Ebx (it is constant 0).
We still diverge from ld.bfd (at least in most cases) and gold in that
.got.plt and .got are not adjacent, but the advantage doing that is
unclear.
Reviewers: ruiu, sivachandra, espindola
Subscribers: emaste, mehdi_amini, arichardson, dexonsmith, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59594
llvm-svn: 356968
2019-03-26 07:46:19 +08:00
|
|
|
R_GOTONLY_PC,
|
|
|
|
R_GOTPLTONLY_PC,
|
|
|
|
R_GOTPLT,
|
|
|
|
R_GOTPLTREL,
|
|
|
|
R_GOTREL,
|
2017-02-23 14:22:28 +08:00
|
|
|
R_NONE,
|
2016-05-25 04:24:43 +08:00
|
|
|
R_PC,
|
|
|
|
R_PLT,
|
2017-03-26 12:10:43 +08:00
|
|
|
R_PLT_PC,
|
2021-10-26 04:05:17 +08:00
|
|
|
R_PLT_GOTPLT,
|
2016-05-25 22:31:37 +08:00
|
|
|
R_RELAX_GOT_PC,
|
[ELF] - Implemented support for test/binop relaxations from latest ABI.
Patch implements next relaxation from latest ABI:
"Convert memory operand of test and binop into immediate operand, where binop is one of adc, add, and, cmp, or,
sbb, sub, xor instructions, when position-independent code is disabled."
It is described in System V Application Binary Interface AMD64 Architecture Processor
Supplement Draft Version 0.99.8 (https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r249.pdf,
B.2 "B.2 Optimize GOTPCRELX Relocations").
Differential revision: http://reviews.llvm.org/D20793
llvm-svn: 271405
2016-06-02 00:45:30 +08:00
|
|
|
R_RELAX_GOT_PC_NOPIC,
|
2016-05-25 04:24:43 +08:00
|
|
|
R_RELAX_TLS_GD_TO_IE,
|
2016-06-05 07:33:31 +08:00
|
|
|
R_RELAX_TLS_GD_TO_IE_ABS,
|
[PPC64] Thread-local storage general-dynamic to initial-exec relaxation.
Patch adds support for relaxing the general-dynamic tls sequence to
initial-exec.
the relaxation performs the following transformation:
addis r3, r2, x@got@tlsgd@ha --> addis r3, r2, x@got@tprel@ha
addi r3, r3, x@got@tlsgd@l --> ld r3, x@got@tprel@l(r3)
bl __tls_get_addr(x@tlsgd) --> nop
nop --> add r3, r3, r13
and instead of emitting a DTPMOD64/DTPREL64 pair for x, we emit a single
R_PPC64_TPREL64.
Differential Revision: https://reviews.llvm.org/D48090
llvm-svn: 335651
2018-06-27 03:38:18 +08:00
|
|
|
R_RELAX_TLS_GD_TO_IE_GOT_OFF,
|
2019-04-22 10:48:37 +08:00
|
|
|
R_RELAX_TLS_GD_TO_IE_GOTPLT,
|
2016-05-25 04:24:43 +08:00
|
|
|
R_RELAX_TLS_GD_TO_LE,
|
2016-06-05 07:22:34 +08:00
|
|
|
R_RELAX_TLS_GD_TO_LE_NEG,
|
2016-05-25 04:24:43 +08:00
|
|
|
R_RELAX_TLS_IE_TO_LE,
|
|
|
|
R_RELAX_TLS_LD_TO_LE,
|
2018-07-10 00:35:51 +08:00
|
|
|
R_RELAX_TLS_LD_TO_LE_ABS,
|
2016-05-25 04:24:43 +08:00
|
|
|
R_SIZE,
|
2020-12-19 00:24:42 +08:00
|
|
|
R_TPREL,
|
|
|
|
R_TPREL_NEG,
|
2016-06-03 03:49:53 +08:00
|
|
|
R_TLSDESC,
|
2016-10-20 17:59:26 +08:00
|
|
|
R_TLSDESC_CALL,
|
2019-05-29 10:03:56 +08:00
|
|
|
R_TLSDESC_PC,
|
2021-10-29 08:52:03 +08:00
|
|
|
R_TLSDESC_GOTPLT,
|
2018-05-29 22:34:38 +08:00
|
|
|
R_TLSGD_GOT,
|
[ELF] Change GOT*_FROM_END (relative to end(.got)) to GOTPLT* (start(.got.plt))
Summary:
This should address remaining issues discussed in PR36555.
Currently R_GOT*_FROM_END are exclusively used by x86 and x86_64 to
express relocations types relative to the GOT base. We have
_GLOBAL_OFFSET_TABLE_ (GOT base) = start(.got.plt) but end(.got) !=
start(.got.plt)
This can have problems when _GLOBAL_OFFSET_TABLE_ is used as a symbol, e.g.
glibc dl_machine_dynamic assumes _GLOBAL_OFFSET_TABLE_ is start(.got.plt),
which is not true.
extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
return _GLOBAL_OFFSET_TABLE_[0]; // R_X86_64_GOTPC32
In this patch, we
* Change all GOT*_FROM_END to GOTPLT* to fix the problem.
* Add HasGotPltOffRel to denote whether .got.plt should be kept even if
the section is empty.
* Simplify GotSection::empty and GotPltSection::empty by setting
HasGotOffRel and HasGotPltOffRel according to GlobalOffsetTable early.
The change of R_386_GOTPC makes X86::writePltHeader simpler as we don't
have to compute the offset start(.got.plt) - Ebx (it is constant 0).
We still diverge from ld.bfd (at least in most cases) and gold in that
.got.plt and .got are not adjacent, but the advantage doing that is
unclear.
Reviewers: ruiu, sivachandra, espindola
Subscribers: emaste, mehdi_amini, arichardson, dexonsmith, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59594
llvm-svn: 356968
2019-03-26 07:46:19 +08:00
|
|
|
R_TLSGD_GOTPLT,
|
2016-05-25 04:24:43 +08:00
|
|
|
R_TLSGD_PC,
|
2018-08-21 23:13:53 +08:00
|
|
|
R_TLSIE_HINT,
|
2018-06-01 02:44:12 +08:00
|
|
|
R_TLSLD_GOT,
|
[ELF] Change GOT*_FROM_END (relative to end(.got)) to GOTPLT* (start(.got.plt))
Summary:
This should address remaining issues discussed in PR36555.
Currently R_GOT*_FROM_END are exclusively used by x86 and x86_64 to
express relocations types relative to the GOT base. We have
_GLOBAL_OFFSET_TABLE_ (GOT base) = start(.got.plt) but end(.got) !=
start(.got.plt)
This can have problems when _GLOBAL_OFFSET_TABLE_ is used as a symbol, e.g.
glibc dl_machine_dynamic assumes _GLOBAL_OFFSET_TABLE_ is start(.got.plt),
which is not true.
extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
return _GLOBAL_OFFSET_TABLE_[0]; // R_X86_64_GOTPC32
In this patch, we
* Change all GOT*_FROM_END to GOTPLT* to fix the problem.
* Add HasGotPltOffRel to denote whether .got.plt should be kept even if
the section is empty.
* Simplify GotSection::empty and GotPltSection::empty by setting
HasGotOffRel and HasGotPltOffRel according to GlobalOffsetTable early.
The change of R_386_GOTPC makes X86::writePltHeader simpler as we don't
have to compute the offset start(.got.plt) - Ebx (it is constant 0).
We still diverge from ld.bfd (at least in most cases) and gold in that
.got.plt and .got are not adjacent, but the advantage doing that is
unclear.
Reviewers: ruiu, sivachandra, espindola
Subscribers: emaste, mehdi_amini, arichardson, dexonsmith, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59594
llvm-svn: 356968
2019-03-26 07:46:19 +08:00
|
|
|
R_TLSLD_GOTPLT,
|
2018-06-27 21:55:41 +08:00
|
|
|
R_TLSLD_GOT_OFF,
|
2018-07-10 00:35:51 +08:00
|
|
|
R_TLSLD_HINT,
|
2016-10-21 12:52:11 +08:00
|
|
|
R_TLSLD_PC,
|
2019-02-15 02:50:59 +08:00
|
|
|
|
|
|
|
// The following is abstract relocation types used for only one target.
|
|
|
|
//
|
|
|
|
// Even though RelExpr is intended to be a target-neutral representation
|
|
|
|
// of a relocation type, there are some relocations whose semantics are
|
|
|
|
// unique to a target. Such relocation are marked with R_<TARGET_NAME>.
|
|
|
|
R_AARCH64_GOT_PAGE_PC,
|
2021-01-14 01:29:16 +08:00
|
|
|
R_AARCH64_GOT_PAGE,
|
2019-02-15 02:50:59 +08:00
|
|
|
R_AARCH64_PAGE_PC,
|
|
|
|
R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC,
|
|
|
|
R_AARCH64_TLSDESC_PAGE,
|
2020-02-24 03:46:46 +08:00
|
|
|
R_ARM_PCA,
|
2019-02-20 08:01:21 +08:00
|
|
|
R_ARM_SBREL,
|
2019-02-15 02:50:59 +08:00
|
|
|
R_MIPS_GOTREL,
|
|
|
|
R_MIPS_GOT_GP,
|
|
|
|
R_MIPS_GOT_GP_PC,
|
|
|
|
R_MIPS_GOT_LOCAL_PAGE,
|
|
|
|
R_MIPS_GOT_OFF,
|
|
|
|
R_MIPS_GOT_OFF32,
|
|
|
|
R_MIPS_TLSGD,
|
|
|
|
R_MIPS_TLSLD,
|
[PPC32] Improve the 32-bit PowerPC port
Many -static/-no-pie/-shared/-pie applications linked against glibc or musl
should work with this patch. This also helps FreeBSD PowerPC64 to migrate
their lib32 (PR40888).
* Fix default image base and max page size.
* Support new-style Secure PLT (see below). Old-style BSS PLT is not
implemented, so it is not suitable for FreeBSD rtld now because it doesn't
support Secure PLT yet.
* Support more initial relocation types:
R_PPC_ADDR32, R_PPC_REL16*, R_PPC_LOCAL24PC, R_PPC_PLTREL24, and R_PPC_GOT16.
The addend of R_PPC_PLTREL24 is special: it decides the call stub PLT type
but it should be ignored for the computation of target symbol VA.
* Support GNU ifunc
* Support .glink used for lazy PLT resolution in glibc
* Add a new thunk type: PPC32PltCallStub that is similar to PPC64PltCallStub.
It is used by R_PPC_REL24 and R_PPC_PLTREL24.
A PLT stub used in -fPIE/-fPIC usually loads an address relative to
.got2+0x8000 (-fpie/-fpic code uses _GLOBAL_OFFSET_TABLE_ relative
addresses).
Two .got2 sections in two object files have different addresses, thus a PLT stub
can't be shared by two object files. To handle this incompatibility,
change the parameters of Thunk::isCompatibleWith to
`const InputSection &, const Relocation &`.
PowerPC psABI specified an old-style .plt (BSS PLT) that is both
writable and executable. Linkers don't make separate RW- and RWE segments,
which causes all initially writable memory (think .data) executable.
This is a big security concern so a new PLT scheme (secure PLT) was developed to
address the security issue.
TLS will be implemented in D62940.
glibc older than ~2012 requires .rela.dyn to include .rela.plt, it can
not handle the DT_RELA+DT_RELASZ == DT_JMPREL case correctly. A hack
(not included in this patch) in LinkerScript.cpp addOrphanSections() to
work around the issue:
if (Config->EMachine == EM_PPC) {
// Older glibc assumes .rela.dyn includes .rela.plt
Add(In.RelaDyn);
if (In.RelaPlt->isLive() && !In.RelaPlt->Parent)
In.RelaDyn->getParent()->addSection(In.RelaPlt);
}
Reviewed By: ruiu
Differential Revision: https://reviews.llvm.org/D62464
llvm-svn: 362721
2019-06-07 01:03:00 +08:00
|
|
|
R_PPC32_PLTREL,
|
2019-06-03 14:21:33 +08:00
|
|
|
R_PPC64_CALL,
|
|
|
|
R_PPC64_CALL_PLT,
|
[PPC64] toc-indirect to toc-relative relaxation
This is based on D54720 by Sean Fertile.
When accessing a global symbol which is not defined in the translation unit,
compilers will generate instructions that load the address from the toc entry.
If the symbol is defined, non-preemptable, and addressable with a 32-bit
signed offset from the toc pointer, the address can be computed
directly. e.g.
addis 3, 2, .LC0@toc@ha # R_PPC64_TOC16_HA
ld 3, .LC0@toc@l(3) # R_PPC64_TOC16_LO_DS, load the address from a .toc entry
ld/lwa 3, 0(3) # load the value from the address
.section .toc,"aw",@progbits
.LC0: .tc var[TC],var
can be relaxed to
addis 3,2,var@toc@ha # this may be relaxed to a nop,
addi 3,3,var@toc@l # then this becomes addi 3,2,var@toc
ld/lwa 3, 0(3) # load the value from the address
We can delete the test ppc64-got-indirect.s as its purpose is covered by
newly added ppc64-toc-relax.s and ppc64-toc-relax-constants.s
Reviewed By: ruiu, sfertile
Differential Revision: https://reviews.llvm.org/D60958
llvm-svn: 360112
2019-05-07 12:26:05 +08:00
|
|
|
R_PPC64_RELAX_TOC,
|
2019-06-03 14:21:33 +08:00
|
|
|
R_PPC64_TOCBASE,
|
2020-08-17 22:30:14 +08:00
|
|
|
R_PPC64_RELAX_GOT_PC,
|
[ELF][RISCV] Treat R_RISCV_{ADD,SET,SUB}* as link-time constants
R_RISCV_{ADD,SET,SUB}* are used for local label computation.
Add a new RelExpr member R_RISCV_ADD to represent them.
R_RISCV_ADD is treated as a link-time constant because otherwise
R_RISCV_{ADD,SET,SUB}* are not allowed in -pie/-shared mode.
In glibc Scrt1.o, .rela.eh_frame contains such relocations.
Because .eh_frame is not writable, we get this error:
ld.lld: error: can't create dynamic relocation R_RISCV_ADD32 against symbol: .L0 in readonly segment; recompil object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
>>> defined in ..../riscv64-linux-gnu/lib/Scrt1.o
With D63076 and this patch, I can run -pie/-shared programs linked against glibc.
Note llvm-mc cannot currently produce R_RISCV_SET* so they are not tested.
Reviewed By: ruiu
Differential Revision: https://reviews.llvm.org/D63183
llvm-svn: 363128
2019-06-12 15:53:06 +08:00
|
|
|
R_RISCV_ADD,
|
2019-02-15 02:50:59 +08:00
|
|
|
R_RISCV_PC_INDIRECT,
|
2016-05-25 04:24:43 +08:00
|
|
|
};
|
|
|
|
|
2016-10-21 12:52:11 +08:00
|
|
|
// Architecture-neutral representation of relocation.
|
2016-09-08 04:37:34 +08:00
|
|
|
struct Relocation {
|
2016-05-25 04:24:43 +08:00
|
|
|
RelExpr expr;
|
2017-10-12 06:49:24 +08:00
|
|
|
RelType type;
|
2016-05-25 04:24:43 +08:00
|
|
|
uint64_t offset;
|
2017-02-16 08:12:34 +08:00
|
|
|
int64_t addend;
|
2017-11-04 05:21:47 +08:00
|
|
|
Symbol *sym;
|
2016-05-25 04:24:43 +08:00
|
|
|
};
|
|
|
|
|
2020-04-07 21:48:18 +08:00
|
|
|
// Manipulate jump instructions with these modifiers. These are used to relax
|
|
|
|
// jump instruction opcodes at basic block boundaries and are particularly
|
|
|
|
// useful when basic block sections are enabled.
|
|
|
|
struct JumpInstrMod {
|
|
|
|
JumpModType original;
|
|
|
|
uint64_t offset;
|
|
|
|
unsigned size;
|
|
|
|
};
|
|
|
|
|
2019-06-21 02:25:57 +08:00
|
|
|
// This function writes undefined symbol diagnostics to an internal buffer.
|
|
|
|
// Call reportUndefinedSymbols() after calling scanRelocations() to emit
|
|
|
|
// the diagnostics.
|
2017-02-23 10:28:28 +08:00
|
|
|
template <class ELFT> void scanRelocations(InputSectionBase &);
|
2021-12-15 08:28:41 +08:00
|
|
|
void postScanRelocations();
|
2016-07-02 16:50:03 +08:00
|
|
|
|
2019-06-21 02:25:57 +08:00
|
|
|
template <class ELFT> void reportUndefinedSymbols();
|
|
|
|
|
2020-02-11 07:27:53 +08:00
|
|
|
void hexagonTLSSymbolUpdate(ArrayRef<OutputSection *> outputSections);
|
|
|
|
bool hexagonNeedsTLSSymbol(ArrayRef<OutputSection *> outputSections);
|
|
|
|
|
2017-04-05 18:30:09 +08:00
|
|
|
class ThunkSection;
|
|
|
|
class Thunk;
|
2020-09-09 17:48:21 +08:00
|
|
|
class InputSectionDescription;
|
2017-04-05 18:30:09 +08:00
|
|
|
|
2017-05-17 15:10:59 +08:00
|
|
|
class ThunkCreator {
|
2017-04-05 18:30:09 +08:00
|
|
|
public:
|
|
|
|
// Return true if Thunks have been added to OutputSections
|
2017-07-28 03:22:43 +08:00
|
|
|
bool createThunks(ArrayRef<OutputSection *> outputSections);
|
2017-04-05 18:30:09 +08:00
|
|
|
|
2017-06-16 21:10:08 +08:00
|
|
|
// The number of completed passes of createThunks this permits us
|
|
|
|
// to do one time initialization on Pass 0 and put a limit on the
|
|
|
|
// number of times it can be called to prevent infinite loops.
|
|
|
|
uint32_t pass = 0;
|
|
|
|
|
2017-04-05 18:30:09 +08:00
|
|
|
private:
|
2017-10-27 16:56:20 +08:00
|
|
|
void mergeThunks(ArrayRef<OutputSection *> outputSections);
|
2017-10-27 17:04:11 +08:00
|
|
|
|
|
|
|
ThunkSection *getISDThunkSec(OutputSection *os, InputSection *isec,
|
2021-02-26 21:14:21 +08:00
|
|
|
InputSectionDescription *isd,
|
|
|
|
const Relocation &rel, uint64_t src);
|
2017-10-27 17:04:11 +08:00
|
|
|
|
2017-09-12 17:17:39 +08:00
|
|
|
ThunkSection *getISThunkSec(InputSection *isec);
|
2017-10-27 16:56:20 +08:00
|
|
|
|
2017-10-27 16:58:28 +08:00
|
|
|
void createInitialThunkSections(ArrayRef<OutputSection *> outputSections);
|
|
|
|
|
[PPC32] Improve the 32-bit PowerPC port
Many -static/-no-pie/-shared/-pie applications linked against glibc or musl
should work with this patch. This also helps FreeBSD PowerPC64 to migrate
their lib32 (PR40888).
* Fix default image base and max page size.
* Support new-style Secure PLT (see below). Old-style BSS PLT is not
implemented, so it is not suitable for FreeBSD rtld now because it doesn't
support Secure PLT yet.
* Support more initial relocation types:
R_PPC_ADDR32, R_PPC_REL16*, R_PPC_LOCAL24PC, R_PPC_PLTREL24, and R_PPC_GOT16.
The addend of R_PPC_PLTREL24 is special: it decides the call stub PLT type
but it should be ignored for the computation of target symbol VA.
* Support GNU ifunc
* Support .glink used for lazy PLT resolution in glibc
* Add a new thunk type: PPC32PltCallStub that is similar to PPC64PltCallStub.
It is used by R_PPC_REL24 and R_PPC_PLTREL24.
A PLT stub used in -fPIE/-fPIC usually loads an address relative to
.got2+0x8000 (-fpie/-fpic code uses _GLOBAL_OFFSET_TABLE_ relative
addresses).
Two .got2 sections in two object files have different addresses, thus a PLT stub
can't be shared by two object files. To handle this incompatibility,
change the parameters of Thunk::isCompatibleWith to
`const InputSection &, const Relocation &`.
PowerPC psABI specified an old-style .plt (BSS PLT) that is both
writable and executable. Linkers don't make separate RW- and RWE segments,
which causes all initially writable memory (think .data) executable.
This is a big security concern so a new PLT scheme (secure PLT) was developed to
address the security issue.
TLS will be implemented in D62940.
glibc older than ~2012 requires .rela.dyn to include .rela.plt, it can
not handle the DT_RELA+DT_RELASZ == DT_JMPREL case correctly. A hack
(not included in this patch) in LinkerScript.cpp addOrphanSections() to
work around the issue:
if (Config->EMachine == EM_PPC) {
// Older glibc assumes .rela.dyn includes .rela.plt
Add(In.RelaDyn);
if (In.RelaPlt->isLive() && !In.RelaPlt->Parent)
In.RelaDyn->getParent()->addSection(In.RelaPlt);
}
Reviewed By: ruiu
Differential Revision: https://reviews.llvm.org/D62464
llvm-svn: 362721
2019-06-07 01:03:00 +08:00
|
|
|
std::pair<Thunk *, bool> getThunk(InputSection *isec, Relocation &rel,
|
2019-05-29 12:06:01 +08:00
|
|
|
uint64_t src);
|
2017-10-27 16:58:28 +08:00
|
|
|
|
2017-10-27 16:56:20 +08:00
|
|
|
ThunkSection *addThunkSection(OutputSection *os, InputSectionDescription *,
|
|
|
|
uint64_t off);
|
2017-10-27 17:07:10 +08:00
|
|
|
|
|
|
|
bool normalizeExistingThunk(Relocation &rel, uint64_t src);
|
2017-10-27 16:58:28 +08:00
|
|
|
|
2019-11-23 16:57:54 +08:00
|
|
|
// Record all the available Thunks for a (Symbol, addend) pair, where Symbol
|
|
|
|
// is represented as a (section, offset) pair. There may be multiple
|
|
|
|
// relocations sharing the same (section, offset + addend) pair. We may revert
|
|
|
|
// a relocation back to its original non-Thunk target, and restore the
|
|
|
|
// original addend, so we cannot fold offset + addend. A nested pair is used
|
|
|
|
// because DenseMapInfo is not specialized for std::tuple.
|
|
|
|
llvm::DenseMap<std::pair<std::pair<SectionBase *, uint64_t>, int64_t>,
|
|
|
|
std::vector<Thunk *>>
|
|
|
|
thunkedSymbolsBySectionAndAddend;
|
|
|
|
llvm::DenseMap<std::pair<Symbol *, int64_t>, std::vector<Thunk *>>
|
|
|
|
thunkedSymbols;
|
2017-04-05 18:30:09 +08:00
|
|
|
|
2017-06-16 21:10:08 +08:00
|
|
|
// Find a Thunk from the Thunks symbol definition, we can use this to find
|
|
|
|
// the Thunk from a relocation to the Thunks symbol definition.
|
2017-11-04 05:21:47 +08:00
|
|
|
llvm::DenseMap<Symbol *, Thunk *> thunks;
|
2017-06-16 21:10:08 +08:00
|
|
|
|
2017-07-05 17:53:33 +08:00
|
|
|
// Track InputSections that have an inline ThunkSection placed in front
|
|
|
|
// an inline ThunkSection may have control fall through to the section below
|
|
|
|
// so we need to make sure that there is only one of them.
|
|
|
|
// The Mips LA25 Thunk is an example of an inline ThunkSection.
|
2017-04-05 18:30:09 +08:00
|
|
|
llvm::DenseMap<InputSection *, ThunkSection *> thunkedSections;
|
|
|
|
};
|
2016-07-21 01:58:07 +08:00
|
|
|
|
2017-02-16 08:12:34 +08:00
|
|
|
// Return a int64_t to make sure we get the sign extension out of the way as
|
|
|
|
// early as possible.
|
2016-07-02 16:50:03 +08:00
|
|
|
template <class ELFT>
|
2017-02-16 08:12:34 +08:00
|
|
|
static inline int64_t getAddend(const typename ELFT::Rel &rel) {
|
2016-07-02 16:50:03 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
template <class ELFT>
|
2017-02-16 08:12:34 +08:00
|
|
|
static inline int64_t getAddend(const typename ELFT::Rela &rel) {
|
2016-07-02 16:50:03 +08:00
|
|
|
return rel.r_addend;
|
|
|
|
}
|
2021-04-29 23:51:09 +08:00
|
|
|
|
|
|
|
template <typename RelTy>
|
|
|
|
ArrayRef<RelTy> sortRels(ArrayRef<RelTy> rels, SmallVector<RelTy, 0> &storage) {
|
|
|
|
auto cmp = [](const RelTy &a, const RelTy &b) {
|
|
|
|
return a.r_offset < b.r_offset;
|
|
|
|
};
|
|
|
|
if (!llvm::is_sorted(rels, cmp)) {
|
|
|
|
storage.assign(rels.begin(), rels.end());
|
|
|
|
llvm::stable_sort(storage, cmp);
|
|
|
|
rels = storage;
|
|
|
|
}
|
|
|
|
return rels;
|
|
|
|
}
|
2017-07-18 19:55:35 +08:00
|
|
|
} // namespace elf
|
|
|
|
} // namespace lld
|
2016-05-25 04:24:43 +08:00
|
|
|
|
|
|
|
#endif
|