Dll 在Windows 10上运行简单汇编程序时出现问题

Dll 在Windows 10上运行简单汇编程序时出现问题,dll,gdb,cygwin,nasm,mingw32,Dll,Gdb,Cygwin,Nasm,Mingw32,我试图编写一个不依赖I/O的简单汇编程序,并将其汇编成32位本机Windows可执行文件(即使用mingw工具链而不是cygwin)。这是我所拥有的(我已经几十年没有写过任何汇编了,所以这可能不正确,没关系,我正在努力(重新)学习)。程序测试一些寄存器,然后跳转到寄存器eax给定的位置 section .text global _main _main: mov eax, 0x00401000 cmp eax, 0 jz .L1 inc eax jmp .

我试图编写一个不依赖I/O的简单汇编程序,并将其汇编成32位本机Windows可执行文件(即使用mingw工具链而不是cygwin)。这是我所拥有的(我已经几十年没有写过任何汇编了,所以这可能不正确,没关系,我正在努力(重新)学习)。程序测试一些寄存器,然后跳转到寄存器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
使用nasm组装:

nasm.exe -f win32 -g -o test_branch.o test_branch.asm
我运行64位cygwin,但使用32位交叉链接器

i686-w64-mingw32-ld.exe -o test_branch.exe -mi386pe test_branch.o
(在使用和不使用-mi386pe的情况下都进行了尝试)不幸的是,这仍然与64位DLL链接,而不是与32位DLL链接,如下面运行的gdb所示:

$ 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)
$gdb test\u branch.exe
GNU gdb(gdb)(Cygwin 8.3.1-1)8.3.1
版权所有(C)2019免费软件基金会。
许可证GPLv3+:GNU GPL版本3或更高版本
这是自由软件:您可以自由更改和重新发布它。
在法律允许的范围内,不存在任何担保。
有关详细信息,请键入“显示复制”和“显示保修”。
此GDB配置为“x86_64-pc-cygwin”。
键入“显示配置”以获取配置详细信息。
有关错误报告说明,请参阅:
.
在线查找GDB手册和其他文档资源,网址为:
.
要获得帮助,请键入“帮助”。
键入“apropos word”以搜索与“word”相关的命令。。。
正在从test_branch.exe读取符号。。。
(在test_branch.exe中未找到调试符号)
(gdb)r
启动程序:test_branch.exe
警告:`/cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll':共享库体系结构i386:x86-64与目标体系结构i386不兼容。
警告:`/cygdrive/c/WINDOWS/System32/wow64.dll':共享库体系结构i386:x86-64与目标体系结构i386不兼容。
警告:`/cygdrive/c/WINDOWS/System32/wow64win.dll':共享库体系结构i386:x86-64与目标体系结构i386不兼容。
警告:“WOW64_图像_节”的dll路径无法计算
警告:无法加载WOW64_图像_节的共享库符号。
您需要“设置solib搜索路径”还是“设置系统根”?
警告:“WOW64_图像_节”的dll路径无法计算
警告:无法加载WOW64_图像_节的共享库符号。
您需要“设置solib搜索路径”还是“设置系统根”?
警告:“WOW64_图像_节”的dll路径无法计算
警告:无法加载WOW64_图像_节的共享库符号。
您需要“设置solib搜索路径”还是“设置系统根”?
警告:`/cygdrive/c/WINDOWS/System32/wow64cpu.dll':共享库体系结构i386:x86-64与目标体系结构i386不兼容。
[新螺纹30828.0x7d8c]
线程1收到信号SIGSEGV,分段故障。
0x7783cfa0英寸??()
(gdb)

所以我想我的问题是1。如何说服链接器使用32位DLL和2。假设我没有它们,我需要下载哪些(宁愿提前知道完整的列表,也不愿在运行时发现丢失的dll)。我已经看过了,但我没有得到任何见解。3.为什么gdb说即使我在nasm中使用了-g选项,也没有调试符号?

问题在于我的gdb,它是用于64位代码的。我通过运行
gdb--configuration
确定了这一点。为windows找到32位gdb并不像我想象的那么容易,但我确实从这里下载了它,现在一切都好了。

wow64是64操作系统的32位接口,很抱歉,我不知道你在说什么。是不是它确实有正确的dll,而gdb被搞糊涂了?