Skip to content
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

pthread_atfork error on Arm processor #956

Closed
elbarto1980 opened this issue May 29, 2019 · 7 comments
Closed

pthread_atfork error on Arm processor #956

elbarto1980 opened this issue May 29, 2019 · 7 comments

Comments

@elbarto1980
Copy link

Hi,
I finished writing my code that uses nng and I successfully compiled it and run it on my laptop.
Then, I moved the source code to an Odroid-XU4 board, where the code is intended to run, and tried to compiled it there, but I got the following error:

//usr/local/lib/libnng.a(posix_thread.c.o): In function nni_plat_init':
posix_thread.c:(.text+0x5a0): undefined reference to pthread_atfork' collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed.

I had no problem in compiling and installing nng on the Odroid-XU4, so I hope that some cmake flag could solve the problem...

The Odroid board is based on an Arm processor and the O.S. installed is Ubuntu 18.04, without any Desktop Environment.

I hope you can help me solve this "undefined reference" issue.
Thank you!

@gdamore
Copy link
Contributor

gdamore commented May 29, 2019

Wow, that's surprising. For now, I recommend just commenting out the code that calls pthread_atfork() -- it's intended to add some safety (basically preventing attempts to use the library across calls to fork()), but is not actually required for correct operation of the library.

I'll add a CMake test for this in the future.

@elbarto1980
Copy link
Author

Hi,
I commented out the whole if (pthread_atfork(NULL, NULL, nni_atfork_child) != 0) {..} block and it worked!
Thank you so much! :-)

@gdamore
Copy link
Contributor

gdamore commented Jun 3, 2019

Cool.

@elbarto1980
Copy link
Author

Hi,
I noticed that the same thing happens on Ubuntu 18.04.2 LTS (Desktop, x64 version) as well.
So, it seems that the problem is not related to the ARM architecture but to the specific version of the pthread library that is provided with Ubuntu 18.04.

/usr/local/lib/libnng.a(posix_thread.c.o): In function nni_plat_init': posix_thread.c:(.text+0x6dc): undefined reference to pthread_atfork'
collect2: error: ld returned 1 exit status
CMakeFiles/droneManager.dir/build.make:302: recipe for target 'droneManager' failed
make[2]: *** [droneManager] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/droneManager.dir/all' failed
make[1]: *** [CMakeFiles/droneManager.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

@codypiersall
Copy link
Contributor

I've run into this too. It's because on some platforms/versions of libc certain pthread functions are defined in libc and some are defined in libpthread (I think). So a workaround for people running into this is to just link your program with libpthread and everything should work.

The same issue happened in openssl: openssl/openssl#3884

To quote a comment:

Note: pthread_atfork can be in libc rather than libpthreads.

@elbarto1980
Copy link
Author

Thank you!

@gdamore
Copy link
Contributor

gdamore commented Jun 6, 2019

I think there may be separate issues here. As this is a static build, the pthread library should be included on the link line, and must occur after -lnng. My guess is that you probably have other pthread symbols that are missing, unless pthread_atfork() is not in libc, but the other pthread functions are (which would be surprising.) You're using cmake, so this should have been handled automatically.

The other thing is that platform may actually be missing pthread_atfork(). I'll have to research that.

At any rate, I'll see if I can come up with a better fix.

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

No branches or pull requests

3 participants