[PATCH] D146215: [BOLT] Reject symbols pointing to section end
Vladislav Khmelevsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 21 03:00:32 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG54ab9541492d: [BOLT] Reject symbols pointing to section end (authored by jobnoorman, committed by yota9).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146215/new/
https://reviews.llvm.org/D146215
Files:
bolt/lib/Rewrite/RewriteInstance.cpp
bolt/test/X86/section-end-sym.s
Index: bolt/test/X86/section-end-sym.s
===================================================================
--- /dev/null
+++ bolt/test/X86/section-end-sym.s
@@ -0,0 +1,29 @@
+## Check that BOLT doesn't consider end-of-section symbols (e.g., _etext) as
+## functions.
+
+# REQUIRES: system-linux
+
+# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t.exe -q
+# RUN: llvm-bolt %t.exe -o /dev/null --print-cfg --debug-only=bolt 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: considering symbol etext for function
+# CHECK-NEXT: rejecting as symbol points to end of its section
+# CHECK-NOT: Binary Function "etext{{.*}}" after building cfg
+
+
+ .text
+ .globl _start
+ .type _start, at function
+_start:
+ retq
+ .size _start, .-_start
+
+ .align 0x1000
+ .globl etext
+etext:
+
+ .data
+.Lfoo:
+ .word 0
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1050,6 +1050,16 @@
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: considering symbol " << UniqueName
<< " for function\n");
+ if (Address == Section->getAddress() + Section->getSize()) {
+ assert(SymbolSize == 0 &&
+ "unexpect non-zero sized symbol at end of section");
+ LLVM_DEBUG(
+ dbgs()
+ << "BOLT-DEBUG: rejecting as symbol points to end of its section\n");
+ registerName(SymbolSize);
+ continue;
+ }
+
if (!Section->isText()) {
assert(SymbolType != SymbolRef::ST_Function &&
"unexpected function inside non-code section");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146215.506888.patch
Type: text/x-patch
Size: 1678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230321/bb91da43/attachment.bin>
More information about the llvm-commits
mailing list