-lrt and -lpthread order with static linking

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

-lrt and -lpthread order with static linking

Anatoly Yakovenko
ghc places -lrt after -lpthread, causing pthread.a symbols to be missing
when linking with -static

and just for kicks it generates a .o in /tmp that it deletes on exit, so i
cant relink.  i think whoever added that owes me a beer.

so in one shell i did a

 while true; do cp /tmp/*/*.o .; done

and in another shell i ran the make command to grab that tmp file, then i
was able to stick into the collect command i can grab from -optl--verbose
and fully link the exe.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20130123/d02d538c/attachment.htm>

Reply | Threaded
Open this post in threaded view
|

-lrt and -lpthread order with static linking

Simon Marlow-7
On 24/01/13 05:58, Anatoly Yakovenko wrote:
> ghc places -lrt after -lpthread, causing pthread.a symbols to be missing
> when linking with -static

What platform? -lrt comes before -lpthread for me (x86_64/Linux).

> and just for kicks it generates a .o in /tmp that it deletes on exit, so
> i cant relink.  i think whoever added that owes me a beer.

-keep-tmp-files?

Cheers,
        Simon


Reply | Threaded
Open this post in threaded view
|

-lrt and -lpthread order with static linking

Anatoly Yakovenko

On Jan 24, 2013, at 5:14 AM, Simon Marlow <marlowsd at gmail.com> wrote:

> On 24/01/13 05:58, Anatoly Yakovenko wrote:
>> ghc places -lrt after -lpthread, causing pthread.a symbols to be missing
>> when linking with -static
>
> What platform?


anatolyy at anatolyy-ubuntu12:~/qctp406/pkg/qaicSrc$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.4.1

anatolyy at anatolyy-ubuntu12:~/qctp406/pkg/qaicSrc$ uname -a
Linux anatolyy-ubuntu12 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

> -lrt comes before -lpthread for me (x86_64/Linux).

-lffi -lm -lrt -ldl --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o

appears last on the collect2 line

which is fixed with (added -lpthread after -lrt):

-lffi -lm -lrt -lpthread -ldl --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o


otherwise i get these:

/usr/lib/x86_64-linux-gnu//librt.a(timer_routines.o): In function `__start_helper_thread':
(.text+0x266): undefined reference to `pthread_atfork'
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_eh.a(unwind-dw2.o): In function `uw_init_context_1':
(.text+0x20bd): undefined reference to `pthread_once'
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_bases':
(.text+0x16c4): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_table_bases':
(.text+0x178b): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__deregister_frame_info_bases':
(.text+0x182e): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__deregister_frame_info_bases':
(.text+0x18b6): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `_Unwind_Find_FDE':
(.text+0x1966): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `_Unwind_Find_FDE':
(.text+0x19b7): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_bases':
(.text+0x16e3): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_table_bases':
(.text+0x17aa): undefined reference to `pthread_mutex_unlock'
collect2: ld returned 1 exit status


I think maybe the best solution is to detect if the user supplied the library already and not add it?  this way i can pass -lpthread -lrt -lpthread to get the static linker to work.

>> and just for kicks it generates a .o in /tmp that it deletes on exit, so
>> i cant relink.  i think whoever added that owes me a beer.
>
> -keep-tmp-files?


awesome! thanks.  although i thought my hack was pretty clever :).