1

I am using following command:

echo 'SOME_DATA' > data.file \
&& objcopy \
     --input-target binary \
     --output-target=elf64-x86-64 \
     --rename-section .data=.my_data_section \
     --add-symbol DATA_SECTION_START=.my_data_section:0 \
     data.file \
     elf.o \
&& readelf -a elf.o

to create "elf.o" file from "data.file" binary file.

In this command ".data" section is created and renamed into ".my_data_section".

At the same time, I am adding symbol/variable "DATA_SECTION_START" pointing it to the beginning of the newly created ".my_data_section" section.

Is it legal to do add and rename section + use such name creating new var at the same time?

I found that "llvm-objcopy" generates wrong "DATA_SECTION_START" variable (Ndx is ABS):

Section Headers:
  [Nr] Name              Type             Address           Offset
...
  [ 1] .my_data_section  PROGBITS         0000000000000000  00000040
...
Symbol table '.symtab' contains 6 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     ...
     5: 000000000000000a     0 NOTYPE  GLOBAL DEFAULT  ABS DATA_SECTION_START

At the same time, I see no problem when using "objcopy" (GCC):

Section Headers:
  [Nr] Name              Type             Address           Offset
...
  [ 1] .my_data_section  PROGBITS         0000000000000000  00000040
...
Symbol table '.symtab' contains 6 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     ...
     5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT    1 DATA_SECTION_START

Can we say that "llvm-objcopy" works in a wrong way?

lol lol
  • 319
  • 3
  • 18

0 Answers0