Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/Target/GNULDBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5420,12 +5420,14 @@ bool GNULDBackend::allocateHeaders() {
uint64_t ModifiedAddr =
llvm::alignDown(VAddr.value() - headerSize, abiPageSize());
uint64_t ModifiedPAddr = PAddr.value() + (ModifiedAddr - VAddr.value());
if (m_ehdr) {
if (isEhdrInLayout()) {
m_ehdr->setAddr(ModifiedAddr);
m_ehdr->setPaddr(ModifiedPAddr);
}
m_phdr->setAddr(ModifiedAddr + getOneEhdrSize());
m_phdr->setPaddr(ModifiedPAddr + getOneEhdrSize());
if (isPhdrInLayout()) {
m_phdr->setAddr(ModifiedAddr + getOneEhdrSize());
m_phdr->setPaddr(ModifiedPAddr + getOneEhdrSize());
}
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Headers omitted from the layout have no output section. Allocating space for
# the other header must not try to assign addresses to the omitted header.
# RUN: split-file %s %t
# RUN: %clang %clangg0opts -c %t/input.c -o %t.o
# RUN: %link %linkopts -z max-page-size=4096 %t.o -T %t/phdrs.t -o %t.phdrs.out
# RUN: %readelf -lW %t.phdrs.out | %filecheck %s --check-prefix=PHDRS
# RUN: %link %linkopts -z max-page-size=4096 %t.o -T %t/filehdr.t -o %t.filehdr.out
# RUN: %readelf -lW %t.filehdr.out | %filecheck %s --check-prefix=FILEHDR

# PHDRS: LOAD {{0x0*(34|40)}} {{0x0*(34|40)}} {{0x0*(34|40)}}
# PHDRS: LOAD {{0x[0-9a-f]+}} {{0x0*1000}} {{0x0*1000}}
# FILEHDR: LOAD {{0x0+}} {{0x0+}} {{0x0+}}
# FILEHDR: LOAD {{0x[0-9a-f]+}} {{0x0*1000}} {{0x0*1000}}

#--- input.c
int data = 1;

#--- phdrs.t
PHDRS {
headers PT_LOAD PHDRS;
data PT_LOAD;
}
SECTIONS {
. = 0x1000;
.data 0x1000 : { *(.data*) *(.sdata*) } :data
}

#--- filehdr.t
PHDRS {
headers PT_LOAD FILEHDR;
data PT_LOAD;
}
SECTIONS {
. = 0x1000;
.data 0x1000 : { *(.data*) *(.sdata*) } :data
}
Loading