diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1317,6 +1317,8 @@ dtFlags1 |= DF_1_NODELETE; if (config->zNodlopen) dtFlags1 |= DF_1_NOOPEN; + if (config->pie) + dtFlags1 |= DF_1_PIE; if (config->zNow) { dtFlags |= DF_BIND_NOW; dtFlags1 |= DF_1_NOW; diff --git a/lld/test/ELF/pie.s b/lld/test/ELF/pie.s --- a/lld/test/ELF/pie.s +++ b/lld/test/ELF/pie.s @@ -8,11 +8,11 @@ ## Check -pie. # RUN: ld.lld -pie %t1.o -o %t -# RUN: llvm-readobj --file-headers --sections -l --symbols -r %t | FileCheck %s +# RUN: llvm-readobj --file-headers --sections -l -d --symbols -r %t | FileCheck %s ## Test --pic-executable alias # RUN: ld.lld --pic-executable %t1.o -o %t -# RUN: llvm-readobj --file-headers --sections -l --symbols -r %t | FileCheck %s +# RUN: llvm-readobj --file-headers --sections -l -d --symbols -r %t | FileCheck %s # CHECK: ElfHeader { # CHECK-NEXT: Ident { @@ -47,6 +47,9 @@ # CHECK: Type: PT_DYNAMIC +# CHECK: DynamicSection [ +# CHECK: 0x000000006FFFFFFB FLAGS_1 PIE + ## Check -nopie # RUN: ld.lld -no-pie %t1.o -o %t2 # RUN: llvm-readobj --file-headers -r %t2 | FileCheck %s --check-prefix=NOPIE