I'm trying to make a truly minimal shared "library" that has the least possible size it can be:
.text
.globl test
test:
movb $1, %al
movb $1, %dil
movabs $message, %rsi
movb $7, %dl
syscall
ret
message:
.ascii "hello"
compiling with: gcc -o test.so -fPIC -shared -m64 -nostdlib -s -O3 test.s
And the output is still relatively huge: 4.8KB!! When I look into the binary with radare I can see that after the .text section there are LOTS AND LOTS of seemingly unnecessary code caves produced my gas.
;-- section_end..rela.dyn:
;-- section..text:
;-- test:
/ (fcn) entry0 20
| entry0 ();
| 0x00000268 b001 mov al, 1 ; [6] va=0x00000268 pa=0x00000268 sz=25 vsz=25 rwx=--r-x .text
| 0x0000026a 40b701 mov dil, 1
| 0x0000026d 48be7c020000. movabs rsi, 0x27c ; "hello" ; RELOC 64
| 0x00000277 b207 mov dl, 7
| 0x00000279 0f05 syscall
\ 0x0000027b c3 ret
; DATA XREF from 0x0000026d (entry0)
0x0000027c 68656c6c6f push 0x6f6c6c65
;-- section_end..text:
0x00000281 0000 add byte [rax], al
0x00000283 0000 add byte [rax], al
0x00000285 0000 add byte [rax], al
;-- section..eh_frame:
;-- section_end..eh_frame:
;-- section_end.LOAD0:
0x00000287 ~ 0000 add byte [rax], al
0x00000289 0000 add byte [rax], al
0x0000028b 0000 add byte [rax], al
0x0000028d 0000 add byte [rax], al
0x0000028f 0000 add byte [rax], al
0x00000291 0000 add byte [rax], al
............ and so on, wasting lots of kilobytes......
What are these for, and how can I get rid of them (If I can/shall)?
User contributions licensed under CC BY-SA 3.0