Set DF_TEXTREL to executables that need text relocations.

Summary:
If an executable needs text relocations, it should be marked as such so
that the loader can prepare for text relocations. We currently create a
dummy segment with DT_TEXTREL for that purpose.

Generic ABI as of 2000 [1] mentioned that "Its [DT_TEXTREL's] use
has been superseded by the DF_TEXTREL flag". However, it's actually not
superseded even after 18 years. OpenBSD and musl recognize only DT_TEXTREL.
So we still need to set both.

[1] http://www.sco.com/developers/gabi/2000-07-17/ch5.dynamic.html

Reviewers: rafael

Subscribers: emaste, llvm-commits, arichardson

Differential Revision: https://reviews.llvm.org/D43920

llvm-svn: 326503
This commit is contained in:
Rui Ueyama
2018-03-01 22:56:52 +00:00
parent 7373ae5c9a
commit 7c18abf99a
2 changed files with 8 additions and 2 deletions

View File

@@ -1046,6 +1046,8 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
DtFlags |= DF_ORIGIN;
DtFlags1 |= DF_1_ORIGIN;
}
if (!Config->ZText)
DtFlags |= DF_TEXTREL;
if (DtFlags)
addInt(DT_FLAGS, DtFlags);

View File

@@ -18,8 +18,10 @@
# CHECK-NEXT: 0x1010 R_X86_64_PC64 zed 0x0
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK: DynamicSection [
# CHECK: 0x0000000000000016 TEXTREL 0x0
# CHECK: FLAGS TEXTREL
# CHECK: TEXTREL 0x0
# STATIC: Relocations [
# STATIC-NEXT: Section {{.*}} .rela.dyn {
@@ -27,8 +29,10 @@
# STATIC-NEXT: 0x201010 R_X86_64_PC64 zed 0x0
# STATIC-NEXT: }
# STATIC-NEXT: ]
# STATIC: DynamicSection [
# STATIC: 0x0000000000000016 TEXTREL 0x0
# STATIC: FLAGS TEXTREL
# STATIC: TEXTREL 0x0
foo:
.quad foo