[ELF] - Implement -z nodefaultlib

This is https://bugs.llvm.org//show_bug.cgi?id=38978

Spec says that:
"Objects may be built with the -z nodefaultlib option to
suppress any search of the default locations at runtime.
Use of this option implies that all the dependencies of an
object can be located using its runpaths.
Without this option, which is the most common case, no
matter how you augment the runtime linker's library
search path, its last element is always /usr/lib for 32-bit
objects and /usr/lib/64 for 64-bit objects."

The patch implements this option.

Differential revision: https://reviews.llvm.org/D54577

llvm-svn: 347647
This commit is contained in:
George Rimar 2018-11-27 09:48:17 +00:00
parent fec4f351d5
commit a1b3ddbfec
5 changed files with 13 additions and 5 deletions

View File

@ -189,6 +189,7 @@ struct Configuration {
bool ZInitfirst; bool ZInitfirst;
bool ZInterpose; bool ZInterpose;
bool ZKeepTextSectionPrefix; bool ZKeepTextSectionPrefix;
bool ZNodefaultlib;
bool ZNodelete; bool ZNodelete;
bool ZNodlopen; bool ZNodlopen;
bool ZNow; bool ZNow;

View File

@ -350,8 +350,8 @@ static bool isKnownZFlag(StringRef S) {
S == "execstack" || S == "global" || S == "hazardplt" || S == "execstack" || S == "global" || S == "hazardplt" ||
S == "initfirst" || S == "interpose" || S == "initfirst" || S == "interpose" ||
S == "keep-text-section-prefix" || S == "lazy" || S == "muldefs" || S == "keep-text-section-prefix" || S == "lazy" || S == "muldefs" ||
S == "nocombreloc" || S == "nocopyreloc" || S == "nodelete" || S == "nocombreloc" || S == "nocopyreloc" || S == "nodefaultlib" ||
S == "nodlopen" || S == "noexecstack" || S == "nodelete" || S == "nodlopen" || S == "noexecstack" ||
S == "nokeep-text-section-prefix" || S == "norelro" || S == "notext" || S == "nokeep-text-section-prefix" || S == "norelro" || S == "notext" ||
S == "now" || S == "origin" || S == "relro" || S == "retpolineplt" || S == "now" || S == "origin" || S == "relro" || S == "retpolineplt" ||
S == "rodynamic" || S == "text" || S == "wxneeded" || S == "rodynamic" || S == "text" || S == "wxneeded" ||
@ -876,6 +876,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
Config->ZInterpose = hasZOption(Args, "interpose"); Config->ZInterpose = hasZOption(Args, "interpose");
Config->ZKeepTextSectionPrefix = getZFlag( Config->ZKeepTextSectionPrefix = getZFlag(
Args, "keep-text-section-prefix", "nokeep-text-section-prefix", false); Args, "keep-text-section-prefix", "nokeep-text-section-prefix", false);
Config->ZNodefaultlib = hasZOption(Args, "nodefaultlib");
Config->ZNodelete = hasZOption(Args, "nodelete"); Config->ZNodelete = hasZOption(Args, "nodelete");
Config->ZNodlopen = hasZOption(Args, "nodlopen"); Config->ZNodlopen = hasZOption(Args, "nodlopen");
Config->ZNow = getZFlag(Args, "now", "lazy", false); Config->ZNow = getZFlag(Args, "now", "lazy", false);

View File

@ -1268,6 +1268,8 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
DtFlags1 |= DF_1_INITFIRST; DtFlags1 |= DF_1_INITFIRST;
if (Config->ZInterpose) if (Config->ZInterpose)
DtFlags1 |= DF_1_INTERPOSE; DtFlags1 |= DF_1_INTERPOSE;
if (Config->ZNodefaultlib)
DtFlags1 |= DF_1_NODEFLIB;
if (Config->ZNodelete) if (Config->ZNodelete)
DtFlags1 |= DF_1_NODELETE; DtFlags1 |= DF_1_NODELETE;
if (Config->ZNodlopen) if (Config->ZNodlopen)

View File

@ -496,6 +496,10 @@ This is a synonym for
Disable combining and sorting multiple relocation sections. Disable combining and sorting multiple relocation sections.
.It Cm nocopyreloc .It Cm nocopyreloc
Disable the creation of copy relocations. Disable the creation of copy relocations.
.It Cm nodefaultlib
Set the
.Dv DF_1_NODEFLIB
flag to indicate that default library search paths should be ignored.
.It Cm nodelete .It Cm nodelete
Set the Set the
.Dv DF_1_NODELETE .Dv DF_1_NODELETE

View File

@ -3,8 +3,8 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld -shared %t -o %t.so # RUN: ld.lld -shared %t -o %t.so
# RUN: ld.lld -z global -z initfirst -z interpose -z now -z nodelete \ # RUN: ld.lld -z global -z initfirst -z interpose -z now -z nodefaultlib \
# RUN: -z nodlopen -z origin -Bsymbolic %t %t.so -o %t1 # RUN: -z nodelete -z nodlopen -z origin -Bsymbolic %t %t.so -o %t1
# RUN: llvm-readobj -dynamic-table %t1 | FileCheck -check-prefix=FLAGS %s # RUN: llvm-readobj -dynamic-table %t1 | FileCheck -check-prefix=FLAGS %s
# RUN: ld.lld %t %t.so -o %t2 # RUN: ld.lld %t %t.so -o %t2
@ -15,7 +15,7 @@
# FLAGS: DynamicSection [ # FLAGS: DynamicSection [
# FLAGS: 0x000000000000001E FLAGS ORIGIN SYMBOLIC BIND_NOW # FLAGS: 0x000000000000001E FLAGS ORIGIN SYMBOLIC BIND_NOW
# FLAGS: 0x000000006FFFFFFB FLAGS_1 NOW GLOBAL NODELETE INITFIRST NOOPEN ORIGIN INTERPOSE # FLAGS: 0x000000006FFFFFFB FLAGS_1 NOW GLOBAL NODELETE INITFIRST NOOPEN ORIGIN INTERPOSE NODEFLIB
# FLAGS: ] # FLAGS: ]
# CHECK: DynamicSection [ # CHECK: DynamicSection [