From patchwork Fri Mar 24 21:22:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 74747 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp32579vqo; Fri, 24 Mar 2023 14:33:25 -0700 (PDT) X-Google-Smtp-Source: AKy350ZVBI7Bh2ljxXOE+HN/5LE5+jQ0UY3axwn+z7FS1nwzNLwEF/rYX0RkE14tLzmBtUhCFsYC X-Received: by 2002:a17:907:2d29:b0:8fa:b2b:9de with SMTP id gs41-20020a1709072d2900b008fa0b2b09demr5652641ejc.25.1679693604895; Fri, 24 Mar 2023 14:33:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679693604; cv=none; d=google.com; s=arc-20160816; b=RLuV5UayRdix/koH5kJhcovAMyOSJLvPru0ykXruqRBT2XukyxVSVcgkTkaV2rX7L3 s+pjVtNxSxD0thVqlpXyGsOKtktptEyE6fpF12/ehiDs6kz9cTEaAy9zKSIFdWDPwyy9 oQYePZzQJzmKGJ79+smPpIWAXwmWJhhCnmP6rZSEqz56PcDb66EjQrx0silmAJA36ynq XY96b4Gmlvoc0CDfKScp7XYJIulkO/jS0IM6BwQrGNheDPtJqUT6czrmhT8LG7wk2mxY ecS37fxkxfpUl7/DaJM7uKXUS/d91FHlDFYLgj2JpHAeI/FkVLpu4xyi+IDlDL1kLE40 jOpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=vmW56UJtv5GWWz8DLX1nqTrYB2t1IC9+OwPh+5MLOmQ=; b=0m9jtwozC1fOgQmZySeLGI3R3Rqz7LzT5lhDcfOGFR9F9ry+wzYNWKdSBQmX0gop3a 8P+D/hcCpqeM7Rvnr8b5wCS7+kuR09o7KLwtM1SxUy7RL9eeXeOMsoy7NSaR03AF5wCc jPTuuvc/mYXgBOtDXBZWXCo9KJxLUXpKToRghQZYNMNILYQoy01pW9o50x42/n2GF+Bi mJW0sZ4yd7PUfrjeVx8yizGLMc7GeTNAOcMDm9yB6ioRMM6SeZtiCbxH9iH1LkxFZK6x yH37a3RmV9hv7tI/U8LUjv892kDUYrm5ucdsEf9EX8k3lAP2gimywVCq/h74NdSYvdVE QO3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gC7f0sm8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ux8-20020a170907cf8800b0093dcbf8e8acsi3140236ejc.593.2023.03.24.14.33.01; Fri, 24 Mar 2023 14:33:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gC7f0sm8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231706AbjCXVWR (ORCPT + 99 others); Fri, 24 Mar 2023 17:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbjCXVWQ (ORCPT ); Fri, 24 Mar 2023 17:22:16 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07DFC18140 for ; Fri, 24 Mar 2023 14:22:15 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id 16-20020a056a00071000b00627e9b4871eso1563269pfl.11 for ; Fri, 24 Mar 2023 14:22:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679692934; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=vmW56UJtv5GWWz8DLX1nqTrYB2t1IC9+OwPh+5MLOmQ=; b=gC7f0sm8D563vcLJO7aCR3uMKZ1am83NXi6YLU93KA1gYvU5X7df3p1ruXHgYeNfOO 8sm1VrG0v15sBIymZw0pR1xBz6Q4deoiT0aInwnCAvFCu0n9iYfQnP/UpuQBOTr/jO+y 69ScWoFpsgILRmjwQBM7qBFJJXmk6PgQRtZD65+iKmjLpMVHqWvVO0uuW5IQ5/QYKzKV ESCASqfeIObx8/soPDEB//kWW+Lt5+XNmdctV9/y9ZwETCrh2qBSCXQLII6SKCnRFO8m zEcIXx0WAPx0eNlYEP+MxJBYntk/B22Bg1Ck+WF35ao9zboP36VfAwMDFw3vQJ511zOg fuoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679692934; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=vmW56UJtv5GWWz8DLX1nqTrYB2t1IC9+OwPh+5MLOmQ=; b=xyCNKFo5zZWHqMJIkyxiXwFRongOq+dQfCqdttRJut+EdGnlVCSFyQVcYLUWm7MQXy gfI76lA1Tpv+McXI0Qy0pDtx/SSxDbGiOqN5HGQltILxYsbxPflNWGvXyOgKhoH3n+gI X6Hya+4akNBvhYl3kAAA7n+nFCDIP93o9LIqqBwIpKLK0+N7280EF33W2/S6KTB2DZex 1fFA0jx65Mp/ZzyH55mtV0+NJ49EMqlqm4/6FJR86jYaDBiOVFaYPZ/M1yCVdxB5BfaD uObabGTm0hHFc+bLnv1uakzTiYjGyMH/i/2h1pSnHGhpZZm74z8OAhLYAvvI8tuBT1yZ 6Suw== X-Gm-Message-State: AAQBX9cbDGVQc3vipgPjm45m3wjVD9K1A/TBpdDBTTM+jCvUuz5td8ga wDw1A1mNiYMRXmYPFQGOW8qDd3reCD1e X-Received: from meowing-l.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3eba]) (user=maskray job=sendgmr) by 2002:a17:90a:4a85:b0:240:2ae6:5eb8 with SMTP id f5-20020a17090a4a8500b002402ae65eb8mr1255141pjh.9.1679692934538; Fri, 24 Mar 2023 14:22:14 -0700 (PDT) Date: Fri, 24 Mar 2023 21:22:10 +0000 Mime-Version: 1.0 Message-ID: <20230324212210.1001990-1-maskray@google.com> Subject: [PATCH v2] Makefile: use -z pack-relative-relocs From: Fangrui Song To: Masahiro Yamada , Nick Desaulniers , linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Peter Collingbourne , Will Deacon , Fangrui Song X-Spam-Status: No, score=-7.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761286401500504846?= X-GMAIL-MSGID: =?utf-8?q?1761286401500504846?= Commit 27f2a4db76e8 ("Makefile: fix GDB warning with CONFIG_RELR") added --use-android-relr-tags to fix a GDB warning BFD: /android0/linux-next/vmlinux: unknown type [0x13] section `.relr.dyn' The GDB warning has been fixed in version 11.2. The DT_ANDROID_RELR tag was deprecated since DT_RELR was standardized. Thus, --use-android-relr-tags should be removed. While making the change, try -z pack-relative-relocs, which is supported since LLD 15. Keep supporting --pack-dyn-relocs=relr as well for older LLD versions. As of today, GNU ld supports the latter option for x86 and powerpc64 ports and has no intention to support --pack-dyn-relocs=relr. In the absence of the glibc symbol version GLIBC_ABI_DT_RELR, --pack-dyn-relocs=relr and -z pack-relative-relocs are identical in ld.lld. Link: https://github.com/ClangBuiltLinux/linux/issues/1057 Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=a619b58721f0a03fd91c27670d3e4c2fb0d88f1e Signed-off-by: Fangrui Song Reviewed-by: Nick Desaulniers --- Makefile | 3 ++- scripts/tools-support-relr.sh | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) --- Changes from v1: * Keep supporting --pack-dyn-relocs=relr for older ld.lld versions diff --git a/Makefile b/Makefile index a2c310df2145..e23a85476d5d 100644 --- a/Makefile +++ b/Makefile @@ -1113,7 +1113,8 @@ LDFLAGS_vmlinux += -X endif ifeq ($(CONFIG_RELR),y) -LDFLAGS_vmlinux += --pack-dyn-relocs=relr --use-android-relr-tags +# ld.lld before 15 did not support -z pack-relative-relocs. +LDFLAGS_vmlinux += $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs) endif # We never want expected sections to be placed heuristically by the diff --git a/scripts/tools-support-relr.sh b/scripts/tools-support-relr.sh index cb55878bd5b8..4c121946e517 100755 --- a/scripts/tools-support-relr.sh +++ b/scripts/tools-support-relr.sh @@ -7,8 +7,12 @@ trap "rm -f $tmp_file.o $tmp_file $tmp_file.bin" EXIT cat << "END" | $CC -c -x c - -o $tmp_file.o >/dev/null 2>&1 void *p = &p; END -$LD $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr \ - --use-android-relr-tags -o $tmp_file + +# ld.lld before 15 did not support -z pack-relative-relocs. +if ! $LD $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr -o $tmp_file 2>/dev/null; then + $LD $tmp_file.o -shared -Bsymbolic -z pack-relative-relocs -o $tmp_file 2>&1 | + grep -q pack-relative-relocs && exit 1 +fi # Despite printing an error message, GNU nm still exits with exit code 0 if it # sees a relr section. So we need to check that nothing is printed to stderr.