C FreeBSD 11.2 Does lldb support i386 elf executables on (x86-64) amd64 platform.

I believe this worked on 11.0

I want to run lldb on a 32bit (i386) elf based executable on an amd64 based FreeBSD11.2 platform. I have distilled the problem down as simple as I can.

The environment (both for compiling and executing):
prompt>uname -mKr
11.2-RELEASE amd64 1102000
prompt>

The program:
Code:
prompt>cat hello.cpp
#include<stdio.h>
int main()
{
    printf("Hello World\n");
}
prompt>
The compile command in verbose:
Code:
prompt>clang++ -m32 -v -static hello.cpp
FreeBSD clang version 6.0.0 (tags/RELEASE_600/final 326565) (based on LLVM 6.0.0)
Target: i386-unknown-freebsd11.2
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/clang++" -cc1 -triple i386-unknown-freebsd11.2 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.cpp -static-define -mrelocation-model static -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu i486 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib/clang/6.0.0 -internal-isystem /usr/include/c++/v1 -fdeprecated-macro -fdebug-compilation-dir /srctree/release_11_11_b0_test/ridsbase/batch_params/libbatch_params -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/hello-669b69.o -x c++ hello.cpp
clang -cc1 version 6.0.0 based upon LLVM 6.0.0 default target x86_64-unknown-freebsd11.2
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/v1
 /usr/lib/clang/6.0.0/include
 /usr/include
End of search list.
 "/usr/bin/ld" --eh-frame-hdr -Bstatic -m elf_i386_fbsd -o a.out /usr/lib32/crt1.o /usr/lib32/crti.o /usr/lib32/crtbeginT.o -L/usr/lib32 /tmp/hello-669b69.o -lc++ -lm -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /usr/lib32/crtend.o /usr/lib32/crtn.o
prompt>
Running the program checking the file type:
Code:
prompt>file a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), statically linked, for FreeBSD 11.2, FreeBSD-style, not stripped
prompt>./a.out
Hello World
prompt>
Running the program under lldb:
Code:
prompt>lldb a.out
(lldb) target create "a.out"
Current executable set to 'a.out' (i386).
(lldb) r
Process 25772 launching
Process 25772 launched: './a.out' (i386)
Process 25772 stopped
* thread #1, name = 'a.out', stop reason = signal SIGBUS: hardware error
    frame #0: 0xffffffff
error: Bad address
(lldb)
It seems to work under gdb (although the real life application programs have other issues under gdb):
Code:
prompt>gdb a.out
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
(gdb) r
Starting program: ./a.out 
Hello World
Program exited normally.
(gdb)
When I build without the -m32 switch, all is fine of course:
Code:
prompt>file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), statically linked, for FreeBSD 11.2, FreeBSD-style, not stripped
prompt>lldb a.out
(lldb) target create "a.out"
Current executable set to 'a.out' (x86_64).
(lldb) r
Process 28911 launching
Process 28911 launched: '/srctree/release_11_11_b0_test/ridsbase/batch_params/libbatch_params/a.out' (x86_64)
Hello World
Process 28911 exited with status = 0 (0x00000000) 
(lldb)
Any thoughts would be appreciated.


We are porting a very large application from 32 bit to clang++ 64 bit. For a lot of reasons I don't want to go into we need do an interim port to clang++ 32 bit (i386) running on and amd64. The application has been running live for 20+ years and has spanned FreeBSD 2.x FreeBSD4.X and FreeBSD8.x.


Thanks

JH
 
Last edited by a moderator:
Back
Top