Jens Staal
2014-12-17 17:00:19 UTC
Background: I have ported busybox-w32 (Win32 port of busybox, normally built
with MinGW) so that it can be (cross-) compiled with Open Watcom (v2). The
resulting binary is about 20-30 % smaller (in the upper range of 400 KiB
whereas the MinGW built one is in the upper range of 600 KiB).
Now I hit something where I can not simply guess based on compiler errors so
I am out on deeper water again ;) (I am a hobbyist with no actual knowledge)
All busybox applets seem to work fine (as far as I have tested them) except
the shell. When the shell is executed I always get a stack dump. Below is an
example:
Z:\home\jens\Devel\github\bbuild>busybox sh
The instruction at 0x00402f31 referenced memory at 0x00000044.
The memory could not be written.
Exception fielded by 0x00456130
EAX=0x00000044 EBX=0x00000004 ECX=0x00476178 EDX=0x00461bfd
ESI=0x00461bfd EDI=0x00000004 EBP=0x00000001 ESP=0x0033fa4c
EIP=0x00402f31 EFL=0x00010206 CS =0x00000023 SS =0x0000002b
DS =0x0000002b ES =0x0000002b FS =0x00000063 GS =0x0000006b
Stack dump (SS:ESP)
0x00000000 0x00342a40 0x0033fd08 0x00000001 0x003412d4 0x00000009
0x00402f74 0x00000000 0x0040c093 0x00000001 0x0033fb4c 0x0033faf8
0x7b84df35 0x0033fc7c 0xf75df8a6 0x0033fab0 0x7b84df35 0xf777c660
0x00000000 0x0033fb4c 0x00000001 0x0033fccc 0x00000001 0x00000000
0x00000000 0xf777c660 0x00000000 0x00000000 0x0033fccc 0x00000000
0x00000000 0x00000001 0x00000000 0x0033fccc 0x0033fb4c 0x00000000
0x2ee3d500 0x00000002 0x7b84dc26 0x0033fb10 0x7ec87000 0x0033fccc
0x00000001 0x0033fba8 0x7ebf8fda 0xf742fca9 0x7bc8e688 0x7ebbd629
0x7ebf8fda 0x00000000 0x00000000 0x0033fb4c 0x00000001 0x0033fccc
0x00000001 0x00000000 0x00000000 0x7ffdf000 0x003400bc 0x0033fb4c
0x00000001 0xfff01000 0x00000400 0x0033fb48 0x00430042 0x02020202
0x536e6957 0x206b636f 0x00302e32 0xf742fca9 0x7ec87000 0x003412d0
I have tried a lot of different things
* A debug build adding -g1+ to the owcc CFLAGS (g2 or higher failed to
compile, also -DDEBUG activating some debug stuff in the code failed to
compile) and "debug watcom all" in the wlink script. This resulted in a huge
binary that I also could run in wdw under Wine. It highlighted an area in
the code, but disabling this part did not do a difference - which makes me
believe that the error might occur "upstream"
- what are your general trick here? Adding printf statements around
suspected areas?
* Since it seemed to be some sort of a memory allocation thing, I tested a
few things around this too:
** increasing stack size to some ridiculus number by adding "option
stack=512k" in the wlink script
** passing -Wc,-sg to owcc (also tested with -Wc,-s if it was just due to
some sort of erroneous error)
** switching from "register" to "stack" based calling convention
** based on what I read, the -Wc,-zu seemed interesting. Interestingly, this
one seems to be incompatible with the stack based calling convention
(perhaps obvious for everybody else). I also noticed that variables of type
"char **" will change type to "char * __far*" (which confuses functions if
they are used as arguments) .
So ... probably totally noob questions for most of you guys, but if you have
some pointers or ideas on where to begin that might help :)
with MinGW) so that it can be (cross-) compiled with Open Watcom (v2). The
resulting binary is about 20-30 % smaller (in the upper range of 400 KiB
whereas the MinGW built one is in the upper range of 600 KiB).
Now I hit something where I can not simply guess based on compiler errors so
I am out on deeper water again ;) (I am a hobbyist with no actual knowledge)
All busybox applets seem to work fine (as far as I have tested them) except
the shell. When the shell is executed I always get a stack dump. Below is an
example:
Z:\home\jens\Devel\github\bbuild>busybox sh
The instruction at 0x00402f31 referenced memory at 0x00000044.
The memory could not be written.
Exception fielded by 0x00456130
EAX=0x00000044 EBX=0x00000004 ECX=0x00476178 EDX=0x00461bfd
ESI=0x00461bfd EDI=0x00000004 EBP=0x00000001 ESP=0x0033fa4c
EIP=0x00402f31 EFL=0x00010206 CS =0x00000023 SS =0x0000002b
DS =0x0000002b ES =0x0000002b FS =0x00000063 GS =0x0000006b
Stack dump (SS:ESP)
0x00000000 0x00342a40 0x0033fd08 0x00000001 0x003412d4 0x00000009
0x00402f74 0x00000000 0x0040c093 0x00000001 0x0033fb4c 0x0033faf8
0x7b84df35 0x0033fc7c 0xf75df8a6 0x0033fab0 0x7b84df35 0xf777c660
0x00000000 0x0033fb4c 0x00000001 0x0033fccc 0x00000001 0x00000000
0x00000000 0xf777c660 0x00000000 0x00000000 0x0033fccc 0x00000000
0x00000000 0x00000001 0x00000000 0x0033fccc 0x0033fb4c 0x00000000
0x2ee3d500 0x00000002 0x7b84dc26 0x0033fb10 0x7ec87000 0x0033fccc
0x00000001 0x0033fba8 0x7ebf8fda 0xf742fca9 0x7bc8e688 0x7ebbd629
0x7ebf8fda 0x00000000 0x00000000 0x0033fb4c 0x00000001 0x0033fccc
0x00000001 0x00000000 0x00000000 0x7ffdf000 0x003400bc 0x0033fb4c
0x00000001 0xfff01000 0x00000400 0x0033fb48 0x00430042 0x02020202
0x536e6957 0x206b636f 0x00302e32 0xf742fca9 0x7ec87000 0x003412d0
I have tried a lot of different things
* A debug build adding -g1+ to the owcc CFLAGS (g2 or higher failed to
compile, also -DDEBUG activating some debug stuff in the code failed to
compile) and "debug watcom all" in the wlink script. This resulted in a huge
binary that I also could run in wdw under Wine. It highlighted an area in
the code, but disabling this part did not do a difference - which makes me
believe that the error might occur "upstream"
- what are your general trick here? Adding printf statements around
suspected areas?
* Since it seemed to be some sort of a memory allocation thing, I tested a
few things around this too:
** increasing stack size to some ridiculus number by adding "option
stack=512k" in the wlink script
** passing -Wc,-sg to owcc (also tested with -Wc,-s if it was just due to
some sort of erroneous error)
** switching from "register" to "stack" based calling convention
** based on what I read, the -Wc,-zu seemed interesting. Interestingly, this
one seems to be incompatible with the stack based calling convention
(perhaps obvious for everybody else). I also noticed that variables of type
"char **" will change type to "char * __far*" (which confuses functions if
they are used as arguments) .
So ... probably totally noob questions for most of you guys, but if you have
some pointers or ideas on where to begin that might help :)