dethrace-labs / dethrace

Reverse engineering the 1997 game "Carmageddon"
https://twitter.com/dethrace_labs
GNU General Public License v3.0
667 stars 38 forks source link

FreeBSD compilation fixes #356

Open PierreMarieBaty opened 8 months ago

PierreMarieBaty commented 8 months ago

In src/BRSRC13/CORE/STD/brstdfile.c line 91

int BrStdioEof(void* f) {
    return feof((FILE*)f); // Pierre-Marie Baty -- added type cast because feof(f) is a macro dereferencing f on some systems
}

in src/BRSRC13/CORE/V1DB/enables.c line 178

        v1db.renderer->dispatch->_partSet(v1db.renderer, BRT_MATRIX, 0, BRT_VIEW_TO_ENVIRONMENT_M34_F, (br_uint_32)&view_to_this); // Pierre-Marie Baty -- FIXME: probably incorrect cast on x64 systems, but necessary to compile without error

in src/harness/include/harness/winsock.h line 25, add

#include <netinet/in.h> // Pierre-Marie Baty -- POSIX location of struct sockaddr_in

After these fixes, dethrace compiles successfully on FreeBSD/arm64 FWIW.

PierreMarieBaty commented 8 months ago

Also a stack trace display improvement that will affect Linux as well, in src/harness/os/linux.c line 66

    sprintf(addr2line_cmd, "addr2line -f -p -e \"%s\" %p", program_name, addr - get_dethrace_offset()); // Pierre-Marie Baty -- support pathnames containing spaces

Replacing %.256s with "%s" ensures addr2line doesn't fail for programs whose full pathname contains spaces (e.g. located in "~/Documents/My Stuff/Some Path/Containing spaces/...").

BTW, looking good: https://i.postimg.cc/qM1V6C53/temp-Imagehx1-Pj4.jpg

interkosmos commented 8 months ago

Also, src/harness/harness.c must be linked against libexecinfo on FreeBSD:

target_link_libraries(harness PRIVATE execinfo)

(Tested with 0.6.0.)

PierreMarieBaty commented 8 months ago

Actually there's a bit more. I don't use the CMake system, but in my bourne shell build script, I have this:

test "$(uname)" = "FreeBSD" && LDFLAGS="-linotify -lusbhid -lexecinfo ${LDFLAGS}"

(libinotify and libusbhid are dependencies of the FreeBSD SDL2 package.)

You might want to add these too.

Message ID: @.***>

madebr commented 8 months ago

What functions, provided by execinfo, is dethrace using?

About your shell script, I suppose you're linking with $(pkg-config --libs sdl2)?

PierreMarieBaty commented 8 months ago

https://man.freebsd.org/cgi/man.cgi?query=backtrace&sektion=3&manpath=FreeBSD+11-current

backtrace() and backtrace_symbols() aren’t in the libc on FreeBSD but in that library.

I don’t use pkg-config either in my build script. It’s very short and crude. The library list is hardcoded per system. Dethrace is a simple enough project to avoid depending on complex and failure-prone build systems. I’m rather a "living off the land" partisan.

interkosmos commented 7 months ago

libinotify and libusbhid are dependencies of the FreeBSD SDL2 package.

Not necessarily, depends on your SDL2 build options.

PierreMarieBaty commented 7 months ago

That's if you rebuild from /usr/ports. But these are the default options, and the precompiled version that you get by "pkg add" installs a libsdl2 with these dependencies. But that's nitpicking :)

Message ID: @.***>