[RFC] objcopy, elf: Align Header Offset [PR 32324]

Andre Vieira (lists) andre.simoesdiasvieira@arm.com
Tue Dec 3 16:30:54 GMT 2024


OK so I have a binary reproducer for you, it's just a nonsensical hello 
world with a loop to make it run for long enough for perf to create a 
record that actually captures something. I compressed it using gzip, so 
hopefully the mailing list accepts it.

This binary was built on an aarch64-none-linux-gnu target, using a top 
of the trunk build of llvm-bolt and a gcc 11.4 with the following commands:
$ gcc hello.c fn.c -O2 -g -Wl,--emit-relocs 
-fno-reorder-blocks-and-partition
$ perf record -e cycles:u -o perf.data -- ./a.out
$ ./bolt_build/bin/perf2bolt -p perf.data -o perf.fdata -nl  ./a.out
$ ./bolt_build/bin/llvm-bolt ./a.out -o ./a-bolted.out -data perf.fdata 
-reorder-blocks=ext-tsp -reorder-functions=hfsort -split-functions 
-split-all-cold -split-eh -dyno-stats

To reproduce the issue with GNU strip/objcopy it is sufficient to call:
$ objcopy a-bolted.out bad_copy
objcopy: bad_copy: section `.eh_frame' can't be allocated in segment 2
LOAD: .text .text.cold .eh_frame .eh_frame_hdr
objcopy: bad_copy: section `.eh_frame_hdr' can't be allocated in segment 2
LOAD: .text .text.cold .eh_frame .eh_frame_hdr
$ ./bad_copy
Illegal Instruction

The sources used to create the binary are ...

hello.c:
#include <stdio.h>

extern int fn (int *, int *, int);

#  define N 2230000
int a[N];
int b[N];

int main (void)
{
   for (int i = 0; i < N; ++i)
     {
       a[i] = i % 10;
       b[i] = i % 2;
     }
   printf ("Hello World! %d\n", fn(&a[0], &b[0], N));
   return 0;
}

... and ...

fn.c:
int fn (int *a, int *b, int n)
{
   int sum = 0;
   for (int i = 0; i < n; ++ i)
     sum += a[i] * b[i];
   return sum;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a-bolted.out.gz
Type: application/x-gzip
Size: 26873 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20241203/dbef0ba9/attachment-0001.bin>


More information about the Binutils mailing list