From 81a239cf3d46f55383bdf8f7cb7ae4833fb73202 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 10 Apr 2024 18:16:44 +0200 Subject: [PATCH] BUILD: makefile: extract ARCH_FLAGS out of LDFLAGS ARCH_FLAGS used to be merged into LDFLAGS so that it was not possible to pass extra options to LDFLAGS without losing ARCH_FLAGS. This commit now splits them apart and leaves LDFLAGS empty by default. The doc explains how to use it for rpath and such occasional use cases. --- INSTALL | 9 +++++++++ Makefile | 27 ++++++++++++++------------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/INSTALL b/INSTALL index 48260e481..2e15c8398 100644 --- a/INSTALL +++ b/INSTALL @@ -622,6 +622,15 @@ and building with the address sanitizer (ASAN) simply requires: $ make TARGET=linux-glibc ARCH_FLAGS="-fsanitize=address -g" +If a particular target requires specific link-time flags, these can be passed +via the LDFLAGS variable. This variable is passed to the linker immediately +after ARCH_FLAGS. One of the common use cases is to add some run time search +paths for a dynamic library that's not part of the default system search path: + + $ make -j $(nproc) TARGET=generic USE_OPENSSL_AWSLC=1 USE_QUIC=1 \ + SSL_INC=/opt/aws-lc/include SSL_LIB=/opt/aws-lc/lib \ + LDFLAGS="-Wl,-rpath,/opt/aws-lc/lib" + Recent systems can resolve IPv6 host names using getaddrinfo(). This primitive is not present in all libcs and does not work in all of them either. Support in glibc was broken before 2.3. Some embedded libs may not properly work either, diff --git a/Makefile b/Makefile index 44d5bd9a8..c308a8fde 100644 --- a/Makefile +++ b/Makefile @@ -290,11 +290,12 @@ ARCH_FLAGS = -g # Just set CFLAGS to the desired ones on the "make" command line. CFLAGS = -#### Common LDFLAGS -# These LDFLAGS are used as the first "ld" options, regardless of any library -# path or any other option. They may be changed to add any linker-specific -# option at the beginning of the ld command line. -LDFLAGS = $(ARCH_FLAGS) -g +#### Extra LDFLAGS +# These LDFLAGS are used as the first "ld" options just after ARCH_FLAGS, +# regardless of any library path or any other option. They may be used to add +# any linker-specific option at the beginning of the ld command line. It may be +# convenient to set a run time search path (-rpath), see INSTALL for more info. +LDFLAGS = #### list of all "USE_*" options. These ones must be updated if new options are # added, so that the relevant options are properly added to the CFLAGS and to @@ -1000,7 +1001,7 @@ else endif # non-empty target haproxy: $(OPTIONS_OBJS) $(OBJS) - $(cmd_LD) $(LDFLAGS) -o $@ $^ $(LDOPTS) + $(cmd_LD) $(ARCH_FLAGS) $(LDFLAGS) -o $@ $^ $(LDOPTS) objsize: haproxy $(Q)objdump -t $^|grep ' g '|grep -F '.text'|awk '{print $$5 FS $$6}'|sort @@ -1009,31 +1010,31 @@ objsize: haproxy $(cmd_CC) $(COPTS) -c -o $@ $< admin/halog/halog: admin/halog/halog.o admin/halog/fgets2.o src/ebtree.o src/eb32tree.o src/eb64tree.o src/ebmbtree.o src/ebsttree.o src/ebistree.o src/ebimtree.o - $(cmd_LD) $(LDFLAGS) -o $@ $^ $(LDOPTS) + $(cmd_LD) $(ARCH_FLAGS) $(LDFLAGS) -o $@ $^ $(LDOPTS) admin/dyncookie/dyncookie: admin/dyncookie/dyncookie.o - $(cmd_LD) $(LDFLAGS) -o $@ $^ $(LDOPTS) + $(cmd_LD) $(ARCH_FLAGS) $(LDFLAGS) -o $@ $^ $(LDOPTS) dev/flags/flags: dev/flags/flags.o - $(cmd_LD) $(LDFLAGS) -o $@ $^ $(LDOPTS) + $(cmd_LD) $(ARCH_FLAGS) $(LDFLAGS) -o $@ $^ $(LDOPTS) dev/haring/haring: dev/haring/haring.o - $(cmd_LD) $(LDFLAGS) -o $@ $^ $(LDOPTS) + $(cmd_LD) $(ARCH_FLAGS) $(LDFLAGS) -o $@ $^ $(LDOPTS) dev/hpack/%: dev/hpack/%.o - $(cmd_LD) $(LDFLAGS) -o $@ $^ $(LDOPTS) + $(cmd_LD) $(ARCH_FLAGS) $(LDFLAGS) -o $@ $^ $(LDOPTS) dev/poll/poll: $(cmd_MAKE) -C dev/poll poll CC='$(CC)' OPTIMIZE='$(COPTS)' V='$(V)' dev/qpack/decode: dev/qpack/decode.o - $(cmd_LD) $(LDFLAGS) -o $@ $^ $(LDOPTS) + $(cmd_LD) $(ARCH_FLAGS) $(LDFLAGS) -o $@ $^ $(LDOPTS) dev/tcploop/tcploop: $(cmd_MAKE) -C dev/tcploop tcploop CC='$(CC)' OPTIMIZE='$(COPTS)' V='$(V)' dev/udp/udp-perturb: dev/udp/udp-perturb.o - $(cmd_LD) $(LDFLAGS) -o $@ $^ $(LDOPTS) + $(cmd_LD) $(ARCH_FLAGS) $(LDFLAGS) -o $@ $^ $(LDOPTS) # rebuild it every time .PHONY: src/version.c dev/poll/poll dev/tcploop/tcploop