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

fix problem which don't support 1-byte atomic instructions natively on RISCV64 architecture #1455

Closed
wants to merge 1 commit into from

Conversation

jiangxiaobin96
Copy link

When building on RISCV64 architecture, I met the following error.

/usr/bin/ld: src/cfgparse.o: in function `check_config_validity':
/home/haproxy/src/cfgparse.c:2476: undefined reference to `__atomic_exchange_1'
/usr/bin/ld: src/dns.o: in function `dns_resolve_send':
/home/haproxy/src/dns.c:313: undefined reference to `__atomic_fetch_sub_1'
/usr/bin/ld: /home/haproxy/src/dns.c:354: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: /home/haproxy/src/dns.c:304: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: src/dns.o: in function `dns_session_io_handler':
/home/haproxy/src/dns.c:726: undefined reference to `__atomic_fetch_sub_1'
/usr/bin/ld: /home/haproxy/src/dns.c:713: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: src/dns.o: in function `b_getblk':
/home/haproxy/include/haproxy/buf.h:328: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: src/dns.o: in function `pool_free':
/home/haproxy/include/haproxy/pool.h:291: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: src/dns.o: in function `__pool_alloc':
/home/haproxy/include/haproxy/pool.h:246: undefined reference to `__atomic_fetch_sub_1'
/usr/bin/ld: src/dns.o: in function `pool_free':
/home/haproxy/include/haproxy/pool.h:291: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: src/dns.o: in function `dns_process_req':
/home/haproxy/src/dns.c:1196: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: src/sink.o: in function `sink_forward_oc_io_handler':
/home/haproxy/src/sink.c:515: undefined reference to `__atomic_fetch_sub_1'
/usr/bin/ld: /home/haproxy/src/sink.c:549: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: /home/haproxy/src/sink.c:549: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: /home/haproxy/src/sink.c:501: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: src/sink.o: in function `sink_forward_io_handler':
/home/haproxy/src/sink.c:375: undefined reference to `__atomic_fetch_sub_1'
/usr/bin/ld: src/sink.o: in function `b_peek_ofs':
/home/haproxy/include/haproxy/buf.h:142: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: /home/haproxy/include/haproxy/buf.h:143: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: /home/haproxy/include/haproxy/buf.h:143: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: src/ring.o: in function `ring_detach_appctx':
/home/haproxy/src/ring.c:240: undefined reference to `__atomic_fetch_sub_1'
/usr/bin/ld: src/ring.o: in function `cli_io_handler_show_ring':
/home/haproxy/src/ring.c:320: undefined reference to `__atomic_fetch_sub_1'
/usr/bin/ld: /home/haproxy/src/ring.c:354: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: /home/haproxy/src/ring.c:354: undefined reference to `__atomic_fetch_add_1'
/usr/bin/ld: /home/haproxy/src/ring.c:311: undefined reference to `__atomic_fetch_add_1'
collect2: error: ld returned 1 exit status
make: *** [Makefile:933: haproxy] Error 1

It seems the target platform doesn't support 1-byte atomic instructions natively. So I add -latomic to support when compiling.
The result:

[root@master0 haproxy]# ./haproxy
HAProxy version 2.5-dev13-47940c-45 2021/11/10 - https://haproxy.org/
Status: development branch - not safe for use in production.
Known bugs: https://github.com/haproxy/haproxy/issues?q=is:issue+is:open
Running on: Linux 5.4.61 #20 SMP Thu Aug 26 11:50:01 CST 2021 riscv64
Usage : haproxy [-f <cfgfile|cfgdir>]* [ -vdVD ] [ -n <maxconn> ] [ -N <maxpconn> ]
        [ -p <pidfile> ] [ -m <max megs> ] [ -C <dir> ] [-- <cfgfile>*]
        -v displays version ; -vv shows known build options.
        -d enters debug mode ; -db only disables background mode.
        -dM[<byte>] poisons memory with <byte> (defaults to 0x50)
        -V enters verbose mode (disables quiet mode)
        -D goes daemon ; -C changes to <dir> before loading files.
        -W master-worker mode.
        -q quiet mode : don't display messages
        -c check mode : only check config files and exit
        -cc check condition : evaluate a condition and exit
        -n sets the maximum total # of connections (uses ulimit -n)
        -m limits the usable amount of memory (in MB)
        -N sets the default, per-proxy maximum # of connections (0)
        -L set local peer name (default to hostname)
        -p writes pids of all children to this file
        -de disables epoll() usage even when available
        -dp disables poll() usage even when available
        -dS disables splice usage (broken on old kernels)
        -dG disables getaddrinfo() usage
        -dR disables SO_REUSEPORT usage
        -dr ignores server address resolution failures
        -dV disables SSL verify on servers side
        -dW fails if any warning is emitted
        -dD diagnostic mode : warn about suspicious configuration statements
        -sf/-st [pid ]* finishes/terminates old pids.
        -x <unix_socket> get listening sockets from a unix socket
        -S <bind>[,<bind options>...] new master CLI

My Platform:

[root@master0 haproxy]# uname -a
Linux master0 5.4.61 #20 SMP Thu Aug 26 11:50:01 CST 2021 riscv64 riscv64 riscv64 GNU/Linux

GCC version:

gcc (GCC) 9.3.1
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@lukastribus
Copy link
Member

This is an automated message.

The haproxy project does not review or merge pull requests on GitHub (please see CONTRIBUTING).

Your patch or patchseries will be forwarded to the haproxy mailing list where it can be reviewed (you will be CC'ed).

This PR will be closed automatically.

haproxy-mirror pushed a commit that referenced this pull request Nov 14, 2021
We've had libatomic enabled on arm and aarch64 for some Raspberry PI
while usually it's not needed, but it was a bit arbitrary and in
issue #1455 it was reported that RISCV requires it for single-byte
atomics.

This changes the approach to detect the explicit requirement of
external functions for the builtins, as reported with *_LOCK_FREE=1.
If any of the atomics requires libatomic, it will be used. Older
compilers do not report any such atomic as they use sync_* instead
and will not match it nor include libatomic (which usually is not
present there).

On x86, the rules depend on -march. i386 uses LOCK_FREE=1 for all of
them. i486 uses it only for the 8-byte CAS and i586 doesn't require
it at all. For this reason, the build flags are used during the test.

This was tested with armv7, aarch64, mips, riscv, i
@wtarreau
Copy link
Member

This could have broken other platforms and environments missing libatomic. I've addressed it differently by checking whether or not gcc reports the need for libatomic for certain of them, and it does indeed catch this one in addition to the previous ones. The upcoming 2.5-dev14 should be OK for you. Thank you very much for your useful report!

FireBurn pushed a commit to FireBurn/haproxy that referenced this pull request Nov 16, 2021
We've had libatomic enabled on arm and aarch64 for some Raspberry PI
while usually it's not needed, but it was a bit arbitrary and in
issue haproxy#1455 it was reported that RISCV requires it for single-byte
atomics.

This changes the approach to detect the explicit requirement of
external functions for the builtins, as reported with *_LOCK_FREE=1.
If any of the atomics requires libatomic, it will be used. Older
compilers do not report any such atomic as they use sync_* instead
and will not match it nor include libatomic (which usually is not
present there).

On x86, the rules depend on -march. i386 uses LOCK_FREE=1 for all of
them. i486 uses it only for the 8-byte CAS and i586 doesn't require
it at all. For this reason, the build flags are used during the test.

This was tested with armv7, aarch64, mips, riscv, i

(cherry picked from commit 70c268b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
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

Successfully merging this pull request may close these issues.

None yet

3 participants