32-bit ifuncs

This commit is contained in:
PoroCYon 2020-08-24 04:36:53 +02:00
parent 62406b12e6
commit cdfcedc1ee
2 changed files with 36 additions and 5 deletions

View File

@ -41,7 +41,7 @@ LIBS = $(filter-out -pthread,$(shell pkg-config --libs sdl2)) -lX11 -lm -lc #-lG
PWD ?= . PWD ?= .
SMOLFLAGS = --smolrt "$(PWD)/rt" --smolld "$(PWD)/ld" \ SMOLFLAGS = --smolrt "$(PWD)/rt" --smolld "$(PWD)/ld" \
-falign-stack -fuse-interp -fifunc-support -fskip-zero-value \ -falign-stack -fuse-interp -fifunc-support \
--verbose #--keeptmp --verbose #--keeptmp
# -fuse-dnload-loader -fskip-zero-value -fuse-nx -fskip-entries -fuse-dt-debug # -fuse-dnload-loader -fskip-zero-value -fuse-nx -fskip-entries -fuse-dt-debug
# -fuse-dl-fini -fno-start-arg -funsafe-dynamic # -fuse-dl-fini -fno-start-arg -funsafe-dynamic

View File

@ -46,6 +46,7 @@ _smol_start:
push _symbols push _symbols
%endif %endif
;.loopme: jmp short .loopme
%ifdef USE_DNLOAD_LOADER %ifdef USE_DNLOAD_LOADER
push eax push eax
pop ebp pop ebp
@ -149,17 +150,29 @@ _smol_start:
.hasheq: .hasheq:
mov eax, [edx + ST_VALUE_OFF] mov eax, [edx + ST_VALUE_OFF]
mov cl , [edx + ST_INFO_OFF ]
pop edx pop edx
%ifdef SKIP_ZERO_VALUE %ifdef SKIP_ZERO_VALUE
or eax, eax or eax, eax
jz short .next_link jz short .next_link
%endif %endif
mov esi, [edx + L_ADDR_OFF] ;mov esi, [edx + L_ADDR_OFF]
;cmp eax, esi ;cmp eax, esi
; jb short .hasheqnorel ; jb short .hasheqnorel
add eax, esi ;add eax, esi
add eax, [edx + L_ADDR_OFF] ; TODO: CONDITIONAL!
.hasheqnorel: .hasheqnorel:
;add eax, [edx + L_ADDR_OFF] ; TODO: CONDITIONAL! %ifdef IFUNC_SUPPORT
xchg ecx, eax
and al, ST_INFO__STT_MASK
cmp al, STT_GNU_IFUNC
jne short .no_ifunc
;int3
call ecx
db 0x3c ; cmp al, <next byte == xchg ecx,eax> --> jump over next insn
.no_ifunc:
xchg ecx, eax
%endif
stosd stosd
%ifdef USE_JMP_BYTES %ifdef USE_JMP_BYTES
inc edi ; skip 0xE9 (jmp) offset inc edi ; skip 0xE9 (jmp) offset
@ -169,7 +182,6 @@ _smol_start:
; if USE_DNLOAD_LOADER ; if USE_DNLOAD_LOADER
%else %else
mov [_smol_linkmap], eax mov [_smol_linkmap], eax
mov ebx, eax mov ebx, eax
@ -240,13 +252,32 @@ repne scasd
mov eax, [ebp + L_INFO_DT_SYMTAB_OFF] mov eax, [ebp + L_INFO_DT_SYMTAB_OFF]
mov eax, [eax + D_UN_PTR_OFF] mov eax, [eax + D_UN_PTR_OFF]
lea eax, [eax + ebx * 8] lea eax, [eax + ebx * 8]
%ifdef IFUNC_SUPPORT
mov cl , [eax + ebx * 8 + ST_INFO_OFF ]
%endif
mov eax, [eax + ebx * 8 + ST_VALUE_OFF] mov eax, [eax + ebx * 8 + ST_VALUE_OFF]
%ifdef SKIP_ZERO_VALUE %ifdef SKIP_ZERO_VALUE
or eax, eax or eax, eax
jz short .next_link jz short .next_link
%endif %endif
;mov esi, [edx + L_ADDR_OFF]
;cmp eax, esi
; jb short .hasheqnorel
;add eax, esi
add eax, [ebp + L_ADDR_OFF] add eax, [ebp + L_ADDR_OFF]
.hasheqnorel:
%ifdef IFUNC_SUPPORT
xchg ecx, eax
and al, ST_INFO__STT_MASK
cmp al, STT_GNU_IFUNC
jne short .no_ifunc
;int3
call ecx
db 0x3c ; cmp al, <next byte == xchg ecx,eax> --> jump over next insn
.no_ifunc:
xchg ecx, eax
%endif
stosd stosd
%ifdef USE_JMP_BYTES %ifdef USE_JMP_BYTES
inc edi inc edi