Re: Why is my nasm program killing itself?



Herbert Kleebauer wrote:
Frank Kotler wrote:
Herbert Kleebauer wrote:

If this bug was present such a long time, then assembly programming
in Linux is even more dead than I thought.
I can add a new kernel!!! 2.4.3.33 - what I'm currently running - is
"killed", too!!!

The binary should be killed in any kernel version (it is not conforming
to the elf standard). The question is, how many Linux distributions used this buggy linker (or maybe the linker doesn't have a bug but the object file generated by the assembler isn't correct and newer versions of the
linker can handle the incorrect object files).

Newer and older versions - 2.17 and 2.18 seem to work. 2.17.50.0.17.20070615 is one version we know *doesn't* like object files built by Nasm, either 0.98.39 (what Slackware 12.0 comes with), or 2.02, or Gas (same version as ld, I assume). Haven't tried Fasm... I probably should. It may be that Nasm and Gas are producing faulty output, and every version of ld but this one (or some fairly narrow range) "fixes our mistake". Maybe I should say "unsuitable version", rather than "buggy linker"... We'll know computers are becoming more human when we see "error: the other computer did it".

[binutils 2.11 and 2.13 won't build]
FWIW, 2.16.1 *does* build... and will even link HLA's output! :)

I can't read C code written by C (C++) programmer. It's completely different
from C code written by assembly programmer.

Possibly that's my problem. :)

(We *can* do dynamic
linking! Have you looked at Stephen Pelc's example at all?)

I have read one article about doing it manually by using a trivial
hash table, but I think I would prefer to modify the assembler
so it would generate a real hash table.

Okay. What's wrong with the "trivial" one? I'll have to look at Stephen's code again - he does "fudge" the hash table, IIRC. Eliminating the pesky linker is looking better and better to me!

Here's one more way to fix a broken executable. More complicated than it needs to be - I was inspired by Almas! :) I don't know if it's even "right". Works on the few I've tried it on... I'll have to boot to 12.0 and make a few more. Or, hmmm, what if I copied over the missing libraries...

Best,
Frank


; fetches byte 48h, rounds up to a multiple of 4
; and stuffs it into byte 58h

; nasm unkiller.asm
; chmod +x unkiller

;[map all]
;===========================================================================
bits 32
ORIGIN equ 8048000h
org ORIGIN
section .text
code_offset equ 0
code_addr:
;--------------------------- ELF header -----------------------------------
dd $464c457f,$00010101,0,0,$00030002,1,main,$34,0,0,$00200034,2,0
dd 1,code_offset,code_addr,code_addr,code_filez,code_memsz,5,4096
dd 1,data_offset,data_addr,data_addr,data_filez,data_memsz,6,4096
main:
;--------- your code goes here ------------------------------------------

IN_OFF equ 48h
OUT_OFF equ 58h

xor edi, edi
top:
call getc
cmp edi, IN_OFF
jnz not_inbyte
mov bl, al
add bl, 3
and bl, 0FCh ; -4
not_inbyte:
cmp edi, OUT_OFF
jnz not_outbyte
mov al, bl
not_outbyte:
call putc
inc edi
jmp short top

exit:
mov eax, 1
int 80h

getc:
push edx
push ecx
push ebx
push eax

mov edx, 1
mov ecx, esp
xor ebx, ebx
mov eax, 3
int 80h

cmp eax, 1
jnz exit

pop eax
pop ebx
pop ecx
pop edx
ret

putc:
push edx
push ecx
push ebx
push eax

mov edx, 1
mov ecx, esp
mov ebx, 1
mov eax, 4
int 80h

pop eax
pop ebx
pop ecx
pop edx
ret


;------------ constant data ---------------------------------
; (note that we're in .text, not .rdata)
align 4

; we have none

;---------------------------------------------------------------------------
align 4
code_memsz equ $ - $$
code_filez equ code_memsz
data_addr equ (ORIGIN+code_memsz+4095)/4096*4096 + (code_filez % 4096)
data_offset equ code_filez
section .data vstart=data_addr
;------------ initialized data ------------------------------

; we have none

; maybe we'd better add one, for the benefit
; of the "last section must be writeable" kernels
dummy db 0

;---------------------------------------------------------------------------
idat_memsz equ $ - $$
bss_addr equ data_addr + ($ - $$)
section .bss vstart=bss_addr
;--------------------------- uninitialized data ------------------------

; we have none

;---------------------------------------------------------------------------
udat_memsz equ $ - $$
data_memsz equ idat_memsz + udat_memsz
data_filez equ idat_memsz
;===========================================================================


.



Relevant Pages

  • Re: Macro2D
    ... õ1, eax", 0 ... db "push striIIi", NL ... db ".2: cmp edi, ebp", NL ... db ".4: mov eax, edi", NL ...
    (alt.lang.asm)
  • One RosAsm Pre-parser
    ... cmp eax 0 | ja L0<< ... mov ecx, D ...
    (alt.lang.asm)
  • Re: Macro2D
    ... mov, eax ... cmp eax, -1 ... push STD_INPUT_HANDLE ...
    (alt.lang.asm)
  • ascii to st0
    ... push IDC_ARROW ... cmp eax, 0 ... mov ebp, esp ... cmp dword @Message, WM_CLOSE ...
    (alt.lang.asm)
  • Re: Insert a byte
    ... push ebx ... mov ebx, dword ... cmp dword, 0 ... ..e0: xor eax, eax ...
    (alt.lang.asm)