[build2] Fix build on older x86 and arm CPUs

Norbert Lange nolange79 at gmail.com
Fri Dec 22 14:11:22 UTC 2017


2017-12-22 14:45 GMT+01:00 Boris Kolpackov <boris at codesynthesis.com>:
> Norbert Lange <nolange79 at gmail.com> writes:
>
>> I tried crosscompiling the debian package, it will error out because
>> the (lowest denominator) CPU does not have built-in instructions for
>> atomics.
>>
>> You can solve this generally by linking with '-latomic
>> -Wl,--as-needed'. libatomic has fallback implemenations, and
>> --as-needed will remove the dependency to the library if its unused.
>
> I did a bit of reading on this and it appears that libatomic provides
> locked implementations of the atomic operations. build2 uses atomics
> pretty heavily which makes me wonder if such a build will be even
> usable on these older CPUs?

I wouldn`t care (much) about performance in a build-system,
compiler/linker will dominate the build.
Also, you only know that atleast ONE operations is missing,
often that's  compare-and-swap.

>
> I think if we really need to support these legacy CPUs (which I am
> not sure about; cross-compiling seems like a much better option),
> then perhaps the right way to do this would be to disable parallelism
> and get rid of atomics. One way to do it without uglyfying the code
> too much would be to provide no-op/serial implementation of the
> interface provided by libatomic. Apparently someone has already
> thought along these lines[1].

This is a valid concern for a C library abstracting the hardware interfaces,
not for user-space apps like build2.
Also, libatomic is just a fallback, most of the time gcc/clang will
just use some inlines.

> What do you think?

Don`t care about it too much, its not your problem.

BTW, I forgot two instances in the bootstrap where -latomic is missing,
see: https://github.com/nolange/deb-build2-toolchain/blob/master/debian/patches/add_atomic_lib.patch

Norbert
>
> [1] http://www.openwall.com/lists/musl/2015/07/23/5
>
> Boris



More information about the users mailing list