Skip to content

Commit

Permalink
Set DF_TEXTREL to executables that need text relocations.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rui314 committed Mar 1, 2018
1 parent 7373ae5 commit 7c18abf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lld/ELF/SyntheticSections.cpp
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions lld/test/ELF/ztext-text-notext.s
Expand Up @@ -18,17 +18,21 @@
# 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 {
# STATIC-NEXT: 0x201008 R_X86_64_64 bar 0x0
# 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
Expand Down

0 comments on commit 7c18abf

Please sign in to comment.