Live data from Hacker News

Embedding Binary Objects in C

flak.tedunangst.com

1–10 of 141 posts

Re: Embedding Binary Objects in C

#4
Where did they define the symbols `_binary_quine_c_start` and `_binary_quine_c_end`? I would expect that the symbol names would need to be passed to the command that produced the object file from the binary file:

    ld -r -b binary quine.c -o myself.o -m elf_amd64

Re: Embedding Binary Objects in C

#6

Where did they define the symbols `_binary_quine_c_start` and `_binary_quine_c_end`? I would expect that the symbol names would need to be passed to the command that produced the object file from the binary file: ld -r -b binary quine.c -o myself.o -m elf_amd64

> I would expect that the symbol names would need to be passed to the command that produced the object file from the binary file:

It's the other way around. The command produces these symbols basing on the file name:

$ readelf --symbols myself.o

   Symbol table '.symtab' contains 5 entries:
      Num:    Value          Size Type    Bind   Vis      Ndx Name
        0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
        1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1
        2: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT    1 _binary_quine_c_start
        3: 0000000000000113     0 NOTYPE  GLOBAL DEFAULT  ABS _binary_quine_c_size
        4: 0000000000000113     0 NOTYPE  GLOBAL DEFAULT    1 _binary_quine_c_end

Re: Embedding Binary Objects in C

#9

Where did they define the symbols `_binary_quine_c_start` and `_binary_quine_c_end`? I would expect that the symbol names would need to be passed to the command that produced the object file from the binary file: ld -r -b binary quine.c -o myself.o -m elf_amd64

Those are standardized named generated by ld, derived from the file name (in this case "quine", which is treated by the author both as C source and a binary data file). I bet there's a CLI switch to change the defaults.
Post reply on HN