Skip to content

Commit c0b474f

Browse files
committedSep 14, 2018
lld: add -z interpose support
-z interpose sets the DF_1_INTERPOSE flag, marking the object as an interposer. Via FreeBSD PR 230604, linking Valgrind with lld failed. Differential Revision: https://reviews.llvm.org/D52094 llvm-svn: 342239
1 parent 3c011e1 commit c0b474f

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed
 

‎lld/ELF/Config.h

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ struct Configuration {
184184
bool ZGlobal;
185185
bool ZHazardplt;
186186
bool ZInitfirst;
187+
bool ZInterpose;
187188
bool ZKeepTextSectionPrefix;
188189
bool ZNodelete;
189190
bool ZNodlopen;

‎lld/ELF/Driver.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,10 @@ static bool getZFlag(opt::InputArgList &Args, StringRef K1, StringRef K2,
341341
static bool isKnown(StringRef S) {
342342
return S == "combreloc" || S == "copyreloc" || S == "defs" ||
343343
S == "execstack" || S == "global" || S == "hazardplt" ||
344-
S == "initfirst" || S == "keep-text-section-prefix" || S == "lazy" ||
345-
S == "muldefs" || S == "nocombreloc" || S == "nocopyreloc" ||
346-
S == "nodelete" || S == "nodlopen" || S == "noexecstack" ||
344+
S == "initfirst" || S == "interpose" ||
345+
S == "keep-text-section-prefix" || S == "lazy" || S == "muldefs" ||
346+
S == "nocombreloc" || S == "nocopyreloc" || S == "nodelete" ||
347+
S == "nodlopen" || S == "noexecstack" ||
347348
S == "nokeep-text-section-prefix" || S == "norelro" || S == "notext" ||
348349
S == "now" || S == "origin" || S == "relro" || S == "retpolineplt" ||
349350
S == "rodynamic" || S == "text" || S == "wxneeded" ||
@@ -836,6 +837,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
836837
Config->ZGlobal = hasZOption(Args, "global");
837838
Config->ZHazardplt = hasZOption(Args, "hazardplt");
838839
Config->ZInitfirst = hasZOption(Args, "initfirst");
840+
Config->ZInterpose = hasZOption(Args, "interpose");
839841
Config->ZKeepTextSectionPrefix = getZFlag(
840842
Args, "keep-text-section-prefix", "nokeep-text-section-prefix", false);
841843
Config->ZNodelete = hasZOption(Args, "nodelete");

‎lld/ELF/SyntheticSections.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,8 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
12681268
DtFlags1 |= DF_1_GLOBAL;
12691269
if (Config->ZInitfirst)
12701270
DtFlags1 |= DF_1_INITFIRST;
1271+
if (Config->ZInterpose)
1272+
DtFlags1 |= DF_1_INTERPOSE;
12711273
if (Config->ZNodelete)
12721274
DtFlags1 |= DF_1_NODELETE;
12731275
if (Config->ZNodlopen)

‎lld/docs/ld.lld.1

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.\"
44
.\" This man page documents only lld's ELF linking support, obtained originally
55
.\" from FreeBSD.
6-
.Dd July 30, 2018
6+
.Dd September 14, 2018
77
.Dt LD.LLD 1
88
.Os
99
.Sh NAME
@@ -446,6 +446,12 @@ segment.
446446
Sets the
447447
.Dv DF_1_INITFIRST
448448
flag to indicate the module should be initialized first.
449+
.It Cm interpose
450+
Set the
451+
.Dv DF_1_INTERPOSE
452+
flag to indicate to the runtime linker that the object is an interposer.
453+
During symbol resolution interposers are searched after the application
454+
but before other dependencies.
449455
.It Cm muldefs
450456
Do not error if a symbol is defined multiple times.
451457
The first definition will be used.

‎lld/test/ELF/dt_flags.s

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
44
# RUN: ld.lld -shared %t -o %t.so
55

6-
# RUN: ld.lld -z global -z initfirst -z now -z nodelete -z nodlopen -z origin \
7-
# RUN: -Bsymbolic %t %t.so -o %t1
6+
# RUN: ld.lld -z global -z initfirst -z interpose -z now -z nodelete \
7+
# RUN: -z nodlopen -z origin -Bsymbolic %t %t.so -o %t1
88
# RUN: llvm-readobj -dynamic-table %t1 | FileCheck -check-prefix=FLAGS %s
99

1010
# RUN: ld.lld %t %t.so -o %t2
@@ -15,7 +15,7 @@
1515

1616
# FLAGS: DynamicSection [
1717
# FLAGS: 0x000000000000001E FLAGS ORIGIN SYMBOLIC BIND_NOW
18-
# FLAGS: 0x000000006FFFFFFB FLAGS_1 NOW GLOBAL NODELETE INITFIRST NOOPEN ORIGIN
18+
# FLAGS: 0x000000006FFFFFFB FLAGS_1 NOW GLOBAL NODELETE INITFIRST NOOPEN ORIGIN INTERPOSE
1919
# FLAGS: ]
2020

2121
# CHECK: DynamicSection [

0 commit comments

Comments
 (0)
Please sign in to comment.