2

I'm trying to write a simple assembly program that does not rely on an I/O, and assemble into a 32-bit native Windows executable (that is using mingw toolchain not cygwin). Here's what I have (I haven't written any assembly in decades, so this may not be correct, that's fine, I am trying to (re)learn). The program tests some register and then jumps to a location given by the register eax

section .text
global _main

_main:
    mov eax, 0x00401000
    cmp eax, 0
    jz .L1
    inc eax
    jmp .L2
    
.L1:
    add eax, 2
.L2:
    jmp eax

Assemble using nasm:

nasm.exe -f win32 -g -o test_branch.o test_branch.asm

I am running 64bit cygwin but am using the 32bit cross linker

i686-w64-mingw32-ld.exe -o test_branch.exe -mi386pe test_branch.o

(tried both with and without -mi386pe) Unfortunately, this is still linking with 64 bit DLLs, not with the 32 bit DLLs as the following run of gdb shows:

$ gdb test_branch.exe
GNU gdb (GDB) (Cygwin 8.3.1-1) 8.3.1
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test_branch.exe...
(No debugging symbols found in test_branch.exe)
(gdb) r
Starting program: test_branch.exe
warning: `/cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll': Shared library architecture i386:x86-64 is not compatible with target architecture i386.
warning: `/cygdrive/c/WINDOWS/System32/wow64.dll': Shared library architecture i386:x86-64 is not compatible with target architecture i386.
warning: `/cygdrive/c/WINDOWS/System32/wow64win.dll': Shared library architecture i386:x86-64 is not compatible with target architecture i386.
warning: dll path for "WOW64_IMAGE_SECTION" can not be evaluated
warning: Could not load shared library symbols for WOW64_IMAGE_SECTION.
Do you need "set solib-search-path" or "set sysroot"?
warning: dll path for "WOW64_IMAGE_SECTION" can not be evaluated
warning: Could not load shared library symbols for WOW64_IMAGE_SECTION.
Do you need "set solib-search-path" or "set sysroot"?
warning: dll path for "WOW64_IMAGE_SECTION" can not be evaluated
warning: Could not load shared library symbols for WOW64_IMAGE_SECTION.
Do you need "set solib-search-path" or "set sysroot"?
warning: `/cygdrive/c/WINDOWS/System32/wow64cpu.dll': Shared library architecture i386:x86-64 is not compatible with target architecture i386.
[New Thread 30828.0x7d8c]

Thread 1 received signal SIGSEGV, Segmentation fault.
0x7783cfa0 in ?? ()
(gdb)

So I guess my question is 1. how do i convince the linker to use the 32 bit DLLs and 2. Assuming I don't have them, which ones will I need to download (would rather know the full list ahead of time rather than discover missing dll's at runtime). I have looked at compile 32bit code from cygwin64 but I didn't get any insights. 3. Why does gdb say there are no debugging symbols even though i used the -g option in nasm?

Motorhead
  • 928
  • 6
  • 16

1 Answers1

0

The problem was with the gdb I had - it was for 64bit code. I determined this by running gdb --configuration. Finding a 32bit gdb for windows wasn't as easy as I thought but I did manage to download it from here http://www.equation.com/servlet/equation.cmd?fa=gdb and now everything is fine.

Motorhead
  • 928
  • 6
  • 16