Skip to content

Improve build on FreeBSD #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 14, 2023
Merged

Conversation

illwieckz
Copy link
Member

@illwieckz illwieckz commented Jun 2, 2019

Those commits improves the build of the crunch tool on FreeBSD.

Until now, only the crnlib was buildable on FreeBSD when integrated in another tool (for example, NetRadiant):

Now the crunch command line tool builds as well, if that other MR is merged:

The crunch tool will build but will not run properly until aligned allocation is enforced, see:

We need that other patch to avoid getting those errors at run time:

crunch/crnlib/crn_mem.cpp(125): Assertion failed: "crnlib_free: bad ptr"
crunch/crnlib/crn_mem.cpp(125): Assertion failed: "crnlib_realloc: bad ptr"

Original message:

This is a list of commits aiming to fix crunch build on FreeBSD. The task is not complete yet since I now face this issue and I don't know yet how to fix it:

[ 93%] Building CXX object crnlib/CMakeFiles/crn.dir/crn_threading_pthreads.cpp.o
…/crunch/crnlib/crn_threading_pthreads.cpp: In function 'crnlib::crn_thread_id_t crnlib::crn_get_current_thread_id()':
…/crunch/crnlib/crn_threading_pthreads.cpp:43:53: error: invalid static_cast from type 'pthread_t' {aka 'pthread*'} to type 'crnlib::crn_thread_id_t' {aka 'long long unsigned int'}
   return static_cast<crn_thread_id_t>(pthread_self());

about a code that is already marked as non-portable:

crn_thread_id_t crn_get_current_thread_id() {
// FIXME: Not portable
return static_cast<crn_thread_id_t>(pthread_self());
}

The first commit is enough to allow crn_decomp.h in third-party projects. I did this fix to enable crn support in NetRadiant and q3map2 on FreeBSD, but that would enable crn support in Dæmon engine on FreeBSD too.

@illwieckz
Copy link
Member Author

@devnexen as a FreeBSD user, would you know how to fix this non-portable cast?

@devnexen
Copy link

devnexen commented Jun 2, 2019

a pthread_t is an opaque type in FreeBSD maybe this deserves a try.

@illwieckz
Copy link
Member Author

Thank you for your quick response! What would be thr_self() argument in that case?

@devnexen
Copy link

devnexen commented Jun 2, 2019

Well, theoretically, what can be tried here is something like this
unsigned long tid; thr_self(&tid); return static_cast<crn_thread_id_t>(tid);

@illwieckz
Copy link
Member Author

illwieckz commented Jun 2, 2019

Hmmm, I did that (without unsigned):

  long tid;
  thr_self(&tid);
  return static_cast<crn_thread_id_t>(tid);

And it now builds but crunch does not work and I don't know yet if it fails because of that fix being wrong or one of my other fixes being wrong:

crunch: Advanced DXTn Texture Compressor - https://github.com/BinomialLLC/crunch
Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
crnlib version v1.04 x64 Built Jun  2 2019, 18:23:36

Warning: No files found: /usr/home/illwieckz/dev/crunch/build/water_p.png
Error: No files found to process!
/home/illwieckz/dev/crunch/crnlib/crn_mem.cpp(121): Assertion failed: "crnlib_free: bad ptr"

/home/illwieckz/dev/crunch/crnlib/crn_mem.cpp(121): Assertion failed: "crnlib_free: bad ptr"

As it looks related to memory, I maybe did a mistake with the fopen/fseeko/ftello stuff.

@illwieckz
Copy link
Member Author

The header-only fix was extracted as its own PR: #12
So third-party project can read crn files on FreeBSD even if the tool itself is not available yet on this platform.

@illwieckz illwieckz force-pushed the freebsd branch 3 times, most recently from c585076 to eeabea5 Compare February 11, 2023 23:44
@illwieckz illwieckz changed the title WIP: Freebsd fixes Fix build on FreeBSD Feb 11, 2023
@illwieckz
Copy link
Member Author

illwieckz commented Feb 11, 2023

So, this now looks ready to me.

Those commits fixes the build of the crunch tool on FreeBSD.

Until now, only the crnlib was buildable on FreeBSD when integrated in another tool (for example, NetRadiant):

Now the crunch command line tool builds as well.

The crunch tool will build but will not run properly until aligned allocation is enforced, see:

We need that other patch to avoid getting those errors at run time:

crunch/crnlib/crn_mem.cpp(125): Assertion failed: "crnlib_free: bad ptr"
crunch/crnlib/crn_mem.cpp(125): Assertion failed: "crnlib_realloc: bad ptr"

@illwieckz illwieckz added the enhancement New feature or request label Feb 11, 2023
@illwieckz illwieckz changed the title Fix build on FreeBSD fix build on FreeBSD Feb 11, 2023
@illwieckz illwieckz changed the title fix build on FreeBSD Fix build on FreeBSD Feb 11, 2023
@illwieckz
Copy link
Member Author

I removed one commit that was introducing a specific FreeBSD #ifdef, as it would not be needed at all if we merge this PR first:

@illwieckz
Copy link
Member Author

Those changes are trivial, so let's merge them.

@illwieckz illwieckz changed the title Fix build on FreeBSD Improve build on FreeBSD Feb 14, 2023
@illwieckz illwieckz merged commit b5bc9ee into DaemonEngine:master Feb 14, 2023
@illwieckz illwieckz deleted the freebsd branch February 14, 2023 12:00
@devnexen
Copy link

nice ! I completely forgot about this 🙂

@illwieckz
Copy link
Member Author

illwieckz commented Feb 14, 2023

Hi @devnexen, nice to see you around! Since you seems to know FreeBSD better than me, would you know what is happening there?

Some error only disappear if I use aligned_alloc instead of malloc, but malloc man says it's aligned anyway:

The malloc() function allocates size bytes of uninitialized memory. The allocated space is suitably aligned (after possible pointer coercion) for storage of any type of object.

And the code just works if I disable the checks.

Right now the tool builds but does not run…

@devnexen
Copy link

This is definitively a weird issue, I ve tried crunch on Linux with jemalloc (which is FreeBSD's allocator backend) and still no issue ... I hope you can, at worse, make your change for aligned_alloc getting merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants