Merge "Fix bionic linker to support segments with zero p_filesz"
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index 64dbb70..d1387f6 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -320,16 +320,19 @@
Elf32_Addr file_end = file_start + phdr->p_filesz;
Elf32_Addr file_page_start = PAGE_START(file_start);
+ Elf32_Addr file_length = file_end - file_page_start;
- void* seg_addr = mmap((void*)seg_page_start,
- file_end - file_page_start,
- PFLAGS_TO_PROT(phdr->p_flags),
- MAP_FIXED|MAP_PRIVATE,
- fd_,
- file_page_start);
- if (seg_addr == MAP_FAILED) {
- DL_ERR("couldn't map \"%s\" segment %d: %s", name_, i, strerror(errno));
- return false;
+ if (file_length != 0) {
+ void* seg_addr = mmap((void*)seg_page_start,
+ file_length,
+ PFLAGS_TO_PROT(phdr->p_flags),
+ MAP_FIXED|MAP_PRIVATE,
+ fd_,
+ file_page_start);
+ if (seg_addr == MAP_FAILED) {
+ DL_ERR("couldn't map \"%s\" segment %d: %s", name_, i, strerror(errno));
+ return false;
+ }
}
// if the segment is writable, and does not end on a page boundary,