[llvm] [BOLT] support mold linker generated PLT in disassembling (PR #115256)

via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 9 08:49:11 PST 2024


================
@@ -1724,8 +1724,30 @@ void RewriteInstance::disassemblePLTSectionX86(BinarySection &Section,
       InstrOffset += InstrSize;
     }
 
-    if (InstrOffset + InstrSize > EntryOffset + EntrySize)
+    if (InstrOffset + InstrSize > EntryOffset + EntrySize) {
----------------
tcwzxx wrote:

I think you can split the logic of this function into two parts:

1. **Detect the PLT Entry Header:**
   - Since the logic of the header involves a jump to `_dl_runtime_resolve`, it must be at least 16 bytes. If the PLT directly jumps to the PLT header, 16 bytes is sufficient. However, if the PLT uses an indirect jump, the `endbr64` or `endbr32` instruction needs to be inserted at the first position. Therefore, the PLT header is 32 bytes. I suggest checking the first instruction to decide the header size.

2. **Detect the PLT Entry:**
   - The size of a PLT entry is always 16 bytes.

This way, it does not depend on the specific instruction pattern.
I hope I haven't overlooked any cases.

https://github.com/llvm/llvm-project/pull/115256


More information about the llvm-commits mailing list