From patchwork Fri Aug 9 13:08:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Yann E. MORIN" X-Patchwork-Id: 1970939 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=buildroot.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=buildroot-bounces@buildroot.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WgPP14jrTz1yYl for ; Fri, 9 Aug 2024 23:08:36 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E94CD40163; Fri, 9 Aug 2024 13:08:32 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id f2WPpzKMFCNd; Fri, 9 Aug 2024 13:08:31 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.166.34; helo=ash.osuosl.org; envelope-from=buildroot-bounces@buildroot.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 24E8E4036A Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp2.osuosl.org (Postfix) with ESMTP id 24E8E4036A; Fri, 9 Aug 2024 13:08:31 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 52EC01BF296 for ; Fri, 9 Aug 2024 13:08:29 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 40E314036A for ; Fri, 9 Aug 2024 13:08:29 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id U8CazcDsBJ27 for ; Fri, 9 Aug 2024 13:08:27 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=80.12.126.236; helo=smtp-out.orange.com; envelope-from=yann.morin@orange.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org 512D040163 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 512D040163 Received: from smtp-out.orange.com (smtp-out.orange.com [80.12.126.236]) by smtp2.osuosl.org (Postfix) with ESMTPS id 512D040163 for ; Fri, 9 Aug 2024 13:08:26 +0000 (UTC) Received: from unknown (HELO opfedv3rlp0e.nor.fr.ftgroup) ([x.x.x.x]) by smtp-out.orange.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 15:08:24 +0200 Received: from unknown (HELO OPE16NORMBX305.corporate.adroot.infra.ftgroup) ([x.x.x.x]) by opfedv3rlp0e.nor.fr.ftgroup with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 09 Aug 2024 15:08:24 +0200 Received: from tl-lnx-nyma7486-2 [x.x.x.x] by OPE16NORMBX305.corporate.adroot.infra.ftgroup [x.x.x.x] with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 9 Aug 2024 15:08:22 +0200 Received: by tl-lnx-nyma7486-2 (sSMTP sendmail emulation); Fri, 09 Aug 2024 15:08:22 +0200 X-IronPort-AV: E=Sophos;i="6.09,276,1716242400"; d="scan'208";a="184993974" From: To: Date: Fri, 9 Aug 2024 15:08:22 +0200 Message-ID: <0907a7f51a6681bf626ab27febd4a32ddd7e617d.1723208902.git.yann.morin@orange.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.115.27.51] X-ClientProxiedBy: OPE16NORMBX305.corporate.adroot.infra.ftgroup (10.115.27.10) To OPE16NORMBX305.corporate.adroot.infra.ftgroup (10.115.27.10) X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.com; i=@orange.com; q=dns/txt; s=orange002; t=1723208908; x=1754744908; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=0DdboqC/f6ZB/aQVdVDwcTGp2KEJSi+Til10pimwCGE=; b=fKZX3iYwZTfjKvVnpMiAOwjEuNcnV24vBGLNyjkTVTXvKNyUhgN2AXrk apf9Cy5mYMKFunzPzcLl+Zwt8cA4eZeZKW+7xpZY1gYRD5pHHbKw4KukQ +yeDAN/BViPdRy+w9vu496911bvj4Wm56OqL4lT6GegnhPfbq5OMJXkuN RPUbMzyUjF480c3OIuOKZMABuoESmzRyLt48HV0WcJjm7/hwtk9w6b9SQ i9ivwrV6C6E3kONpUz9AoFXgvzMqLKQg7AVYdEWdHir7tZbj0RHMj4f3q XvCCXX2Rayk81c7qZ11pPoEklTQXj/Br8D0lONI08ZNEfvZEwVAglvrtK w==; X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=none dis=none) header.from=orange.com X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=orange.com header.i=@orange.com header.a=rsa-sha256 header.s=orange002 header.b=fKZX3iYw Subject: [Buildroot] [PATCH] package/Makefile.in: work around buggy filesystem wrt LDFLAGS X-BeenThere: buildroot@buildroot.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yann.morin@orange.com, =?utf-8?b?SiAuIE5ldXNjaMOkZmVy?= Errors-To: buildroot-bounces@buildroot.org Sender: "buildroot" From: "Yann E. MORIN" Some buildsystems (or their use of it by packages) will cause flags in LDFLAGS to be re-orderded, or even dropped, causing some incompremsible mayhem... For example, gpsd [0] has this in its SConscript [1](typoes not mines, for once): 591 # scons uses gcc, or clang, to link. Thus LDFLAGS does not serve its 592 # traditional function of providing arguments to ln. LDFLAGS set in the 593 # environment before running scons get moved into CCFLAGS by scons. 594 # LDFLAGS set while running scons get ignored. [--SNIP--] 611 for i in ["ARFLAGS", 612 "CCFLAGS", 613 "CFLAGS", 614 "CPPFLAGS", 615 "CXXFLAGS", 616 "LDFLAGS", 617 "LINKFLAGS", 618 "SHLINKFLAGS", 619 ]: 620 if i in os.environ: 621 # MergeFlags() puts the options where scons wants them, not 622 # where you asked them to go. 623 env.MergeFlags(Split(os.getenv(i))) So, when LDFLAGS (our TARGET_LDFLAGS) contains "-z text" (without the quotes), that gets turned into a command line like (line-splitted for readability): [...]/buildroot/output/host/bin/aarch64_be-buildroot-linux-musl-gcc \ -o gpsd-3.25/drivers/driver_rtcm2.os \ -c \ --sysroot=[...]/buildroot/output/host/aarch64_be-buildroot-linux-musl/sysroot \ -O3 -g0 \ -z \ -fPIC -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 \ gpsd-3.25/drivers/driver_rtcm2.c Notice how there is a lone "-z" without any following keyword. This then causes a build failure that looks totally unrelated [2]: In file included from gpsd-3.25/drivers/../include/gpsd.h:36, from gpsd-3.25/drivers/driver_rtcm2.c:65: gpsd-3.25/drivers/../include/os_compat.h:40:8: error: redefinition of ‘struct timespec’ 40 | struct timespec { | ^~~~~~~~ In file included from [...]/buildroot/output/host/aarch64_be-buildroot-linux-musl/sysroot/usr/include/sys/select.h:16, from gpsd-3.25/drivers/../include/gpsd.h:31: [...]/buildroot/output/host/aarch64_be-buildroot-linux-musl/sysroot/usr/include/bits/alltypes.h:237:8: note: originally defined here 237 | struct timespec { time_t tv_sec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER==4321); long tv_nsec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER!=4321); }; | ^~~~~~~~ gpsd-3.25/drivers/../include/os_compat.h:48:5: error: conflicting types for ‘clock_gettime’; have ‘int(clockid_t, struct timespec *)’ {aka ‘int(int, struct timespec *)’} 48 | int clock_gettime(clockid_t, struct timespec *); | ^~~~~~~~~~~~~ In file included from gpsd-3.25/drivers/../include/gpsd.h:33: [...]/buildroot/output/host/aarch64_be-buildroot-linux-musl/sysroot/usr/include/time.h:104:5: note: previous declaration of ‘clock_gettime’ with type ‘int(clockid_t, struct timespec *)’ {aka ‘int(int, struct timespec *)’} 104 | int clock_gettime (clockid_t, struct timespec *); | ^~~~~~~~~~~~~ scons: *** [gpsd-3.25/drivers/driver_rtcm2.os] Error 1 scons: building terminated because of errors. make[1]: *** [package/pkg-generic.mk:289: [...]/buildroot/output/build/gpsd-3.25/.stamp_built] Error 2 make: *** [Makefile:83: _all] Error 2 Although undocumented, neither in gcc not ld (clang unchecked by lack of a clang toolchain here, and by lack of clang knowledge), -z accepts the keyword to be snatch-glued onto it, like -zkeyword, rather than be spearated with a space. So, use that to pass -ztext. Fixes: http://autobuild.buildroot.org/results/c03/c039989947b960ac6af17c87090366abc26dcb6d/ http://autobuild.buildroot.net/results/bc35d3e7b0e8c59c776652070650af3c749250ee/ [0] Our other scons-based package, mongodb, does not build for another reason that probably hides the same issue as seen with gpsd. [1] As explained in gpsd's SConscript (se above), Scons does play tricks with variables: https://scons.org/doc/production/HTML/scons-man.html#f-MergeFlags https://scons.org/doc/production/HTML/scons-man.html#f-ParseFlags Quoting: Flag values are translated according to the prefix found, and added to the following construction variables: [...] -Wl, LINKFLAGS [...] - CCFLAGS [...] Any other strings not associated with options are assumed to be the names of libraries and added to the $LIBS construction variable. So in our case, it finds that -z is an unknown option that matches the '-' prefix, so it is added to CFLAGS, while 'text' is a string on its own, so added to LIBS, and thus it would try to link with -ltext (supposedly, because we do not even go that far). Funnily enough, we can se that "-Wl," is a known option prefix, that is added to LINKFLAGS (to properly be used with gcc or clang, not ld). As a consequence, gpsd's buildsystem does drop -ztext from the link flags, and only passes it to the compile flags, which brings us back to before we banned textrels in a1a2f498d7ec (package/Makefile.in: ban textrels on musl toolchains). Fixing gpsd is a task for another, separate patch... [2] I spent quite some time to look at recent, time-related changes in Buildroot, especially due to the infamous time64_t issues... Alas, that was not related, and only a git-bisect pinpointed the actual issue. Poor polar bears... Signed-off-by: Yann E. MORIN Cc: J. Neuschäfer Reviewed-by: J. Neuschäfer --- package/Makefile.in | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/package/Makefile.in b/package/Makefile.in index 43a5c279c0..808b71a93e 100644 --- a/package/Makefile.in +++ b/package/Makefile.in @@ -155,12 +155,17 @@ TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS)) # # See also: https://www.openwall.com/lists/musl/2020/09/25/4 # -# NOTE: We're using "-z text" instead of "-Wl,-z,text" here, because some +# NOTE: We're using "-ztext" instead of "-Wl,-z,text" here, because some # packages pass TARGET_LDFLAGS directly to ld rather than gcc, and ld doesn't # support -Wl,[...]. -z is supported by both gcc and clang, so it probably # won't cause us problems. +# +# We're using "-ztext" instead of "-z text" here, because some buildsystems +# (like scons, for gpsd) will reorder and/or drop LDFLAGS, causing a lone +# "-z" to be passed and the "text" keyword to be dropped otherwise. Both +# gcc and ld supports that, so it probably won't cause us problems. ifeq ($(BR2_TOOLCHAIN_USES_MUSL):$(BR2_STATIC_LIBS),y:) -TARGET_LDFLAGS += -z text +TARGET_LDFLAGS += -ztext endif # By design, _FORTIFY_SOURCE requires gcc optimization to be enabled.