Issue |
127495
|
Summary |
llvm-objcopy MachO: cant find sections in object file when update-section is called
|
Labels |
new issue
|
Assignees |
|
Reporter |
Nechda
|
Hi!
I've noticed that when I try to update a section in Mach-O binaries, I receive a failure message:
```text
/opt/llvm-bins/bin/llvm-objcopy: error: 'out.o': could not find segment with name '__DATA'
```
How to reproduce:
1. Build llvm from source:
```bash
git checkout llvmorg-19.1.7
mkdir build && cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="llvm;clang" ../llvm
ninja clang llvm-readelf llvm-objcopy
```
2. Compile example.cpp with builded tools:
```cpp
#include <stdio.h>
static const char __attribute__((section("__DATA,__storage"))) storage[0x1000] = {0};
int main() {
for(int i = 0; i < 16; ++i) {
int val = storage[i];
printf("0x%02X ", val);
}
return 0;
}
```
```bash
./bin/clang++ example.cpp -c -o out.o --target=arm64-apple-macos11
```
3. Use llvm-readelf to observe sections:
```bash
./bin/llvm-readelf -S out.o
```
Output has:
```text
Section {
Index: 1
Name: __storage (5F 5F 73 74 6F 72 61 67 65 00 00 00 00 00 00 00)
Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
Address: 0x78
Size: 0x1000
Offset: 672
Alignment: 0
RelocationOffset: 0x0
RelocationCount: 0
Type: Regular (0x0)
Attributes [ (0x0)
]
Reserved1: 0x0
Reserved2: 0x0
Reserved3: 0x0
}
```
4. Updating the section content using llvm-objcopy:
```bash
./bin/llvm-objcopy --update-section=__DATA,__storage=example.cpp out.o
```
Error:
```text
./bin/llvm-objcopy: error: 'out.o': could not find segment with name '__DATA'
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs