Skip to content

Commit d00c83e

Browse files
authored
[BOLT] Skip creation of new segments (#146023)
When all section contents are updated in-place, we can skip creation of new segment(s), save disk space, and free up low memory addresses. Currently, this feature only works with --use-gnu-stack.
1 parent 2282d4f commit d00c83e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4190,6 +4190,11 @@ void RewriteInstance::patchELFPHDRTable() {
41904190
NewWritableSegmentSize = NextAvailableAddress - NewWritableSegmentAddress;
41914191
}
41924192

4193+
if (!NewTextSegmentSize && !NewWritableSegmentSize) {
4194+
BC->outs() << "BOLT-INFO: not adding new segments\n";
4195+
return;
4196+
}
4197+
41934198
const uint64_t SavedPos = OS.tell();
41944199
OS.seek(PHDRTableOffset);
41954200

bolt/test/program-header.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Check that llvm-bolt does not add new segments when writing code in-place.
2+
3+
REQUIRES: system-linux
4+
5+
RUN: %clang %cflags %p/Inputs/hello.c -o %t -no-pie -Wl,-q
6+
RUN: llvm-bolt %t -o %t.bolt --use-old-text --align-functions=1 \
7+
RUN: --no-huge-pages --align-text=1 --use-gnu-stack \
8+
RUN: | FileCheck %s --check-prefix=CHECK-BOLT
9+
RUN: llvm-readelf -WS %t.bolt | FileCheck %s
10+
11+
CHECK-BOLT: rewriting .eh_frame_hdr in-place
12+
CHECK-BOLT: not adding new segments
13+
14+
CHECK-NOT: .bolt.org.eh_frame_hdr

0 commit comments

Comments
 (0)