[llvm] fix symbol name offset in parsing chained-fixup entry function (PR #83564)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 1 04:29:00 PST 2024
https://github.com/fengzhichu created https://github.com/llvm/llvm-project/pull/83564
I could not find any symbol name when using objdump to parse chained-fixup entries. Then I found this bug that NameOffset had a wrong value because NameOffset and WeakImport varibles were exchanged and calculation for NameOffset was also wrong.
The definition of dyld_chained_import_addend64 is in MachO.h.
```
struct dyld_chained_import_addend64 {
uint64_t lib_ordinal : 16;
uint64_t weak_import : 1;
uint64_t reserved : 15;
uint64_t name_offset : 32;
uint64_t addend;
};
```
https://github.com/llvm/llvm-project/blame/main/llvm/include/llvm/BinaryFormat/MachO.h#L1109-L1115
>From 0e441f24a56b1b9fe5e2e4bd08262bf58c2fae77 Mon Sep 17 00:00:00 2001
From: Hummer <fengzhichu at me.com>
Date: Fri, 1 Mar 2024 20:26:25 +0800
Subject: [PATCH] fix symbol name offset in parsing chained-fixup entry
function
I could not find any symbol name when using objdump to parse chained-fixup entries. Then I found this bug that NameOffset had a wrong value because NameOffset and WeakImport varibles were exchanged and calculation for NameOffset was also wrong.
The definition of dyld_chained_import_addend64 is in MachO.h.
https://github.com/llvm/llvm-project/blame/main/llvm/include/llvm/BinaryFormat/MachO.h#L1109-L1115
---
llvm/lib/Object/MachOObjectFile.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index 1cfd0a069463e9..fd310d36e65c2e 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -5231,8 +5231,8 @@ MachOObjectFile::getDyldChainedFixupTargets() const {
auto RawValue = getArray<uint64_t, 2>(*this, ImportPtr);
LibOrdinal = getEncodedOrdinal<uint16_t>(RawValue[0] & 0xFFFF);
- NameOffset = (RawValue[0] >> 16) & 1;
- WeakImport = RawValue[0] >> 17;
+ WeakImport = (RawValue[0] >> 16) & 1;
+ NameOffset = RawValue[0] >> 32;
Addend = RawValue[1];
} else {
llvm_unreachable("Import format should have been checked");
More information about the llvm-commits
mailing list