[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: atomic_LIBS



On 09/10/2016 03:22 PM, Muri Nicanor wrote:
> On 09/06/2016 12:44 PM, Christian Seiler wrote:
> [...]
>> I didn't think about adding -latomic to the linker flag list
>> directly via -Wl. I just tested your suggestion and it's really
>> funny; libtool does mangle your line and separate it into:
>>
>>  -Wl,--push-state -Wl,--as-needed -Wl,-latomic -Wl,--pop-state
>>
>> but since there's no direct -l argument, it actually does work
>> and the things are kept together and in order.
>>
>> @Muri: use this line in the patch instead:
>> AC_CHECK_LIB([atomic], [__atomic_add_fetch_8], [atomic_LIBS="-Wl,--push-state,--as-needed,-latomic,--pop-state"], [atomic_LIBS=""]) 
>>
>> That way, the libatomic dependency will only be picked up on
>> platforms where it's necessary.
> 
> i've created a pull request for that change upstream[0], but the ci
> seems not to like the patch:
> https://travis-ci.org/dkopecek/usbguard/builds/158517934 - i'm not sure
> what to make of that, i don't really see a difference in the successfull
> builds and the ones that failed.

Ah, they are apparently using a version of binutils that doesn't
support --push-state. In that case, you should use the following
in configure.ac:

AC_CHECK_LIB([atomic], [__atomic_add_fetch_8], [
  __saved_LIBS="$LIBS"
  LIBS="$LIBS -Wl,--push-state,--as-needed,-latomic,--pop-state"
  AC_LINK_IFELSE([AC_LANG_PROGRAM()],
    [atomic_LIBS="-Wl,--push-state,--as-needed,-latomic,--pop-state"],
    [atomic_LIBS="-latomic"]
  )
  LIBS="$__saved_LIBS"
], [atomic_LIBS=""])
AC_SUBST([atomic_LIBS])

That will check if the linker flags for --as-needed work, and if
they don't, -latomic is just added unconditionally. This is not
ideal on platforms where libatomic is available, but not required
and ld doesn't support --push-state (because then a spurious
dependency on libatomic will be added to the compiled program),
but at the very least will that always produce a working binary.

Regards,
Christian


Reply to: