Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6009470rwl; Tue, 11 Apr 2023 13:14:29 -0700 (PDT) X-Google-Smtp-Source: AKy350bJovOEOm49l6tJZXCJSt5u2qwkFPMzBa7OUA+tosoPynkNXsNulkire2U83gdJpwNX5HER X-Received: by 2002:aa7:d50d:0:b0:4fb:5fe1:bc3b with SMTP id y13-20020aa7d50d000000b004fb5fe1bc3bmr484151edq.0.1681244069171; Tue, 11 Apr 2023 13:14:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681244069; cv=none; d=google.com; s=arc-20160816; b=Ydi87diqJclb27Mx54fIEGjyToXPtedxbI4hIesLZTgbKmFeFImrdwxlrrcv041n6d HaP4MrAYlnLqJi7njNTJqtxMw7kvgDLvwtvO9avKMJNsKKezOq6G2gohUyEg3o3nHqs1 /dZVzhs3lVuB32LTa2OsWkG9AJsfVUuWNaUAwcLoPLQEkS1sbkUafub3zwpkckrmNhlh FJdk6oaSUnPi0ZvrX6sVgOzNhhYM4L63G2oj1e9e0Z8NATBI9jXVHOHuIBs9yfw+ZKjG SkHUP7eU0+lBLUSt+YQ4dPkksAAfv73014/lpMTKtZICn7pi3rESUNFb1fmdwy1xQvIK 99rA== 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=kAz690gVxE8TfKjgFFdLa3/V7T3THIGi813h83xR35g=; b=sOlYeFxcRQWdbHEKIo7WYHuQR/DVqVaRhiAzXsGYIHq5FQ0No4IHqYxsZodYbqYAeg MYzR7p5GxgHGk7Dir2J3n18OAHvkbpLUYIA/+AKAqT0+29zEJhBPl1hp06KjN6tcGBu9 3dh3pFlHVTorOE0BVCYoWNVMU4XzxIBtE0Ut0uZaQsbimyr30r4FjMtjBN0m68EsdtjJ uA2SqRpf24IATMT0+JXBQfmI5kdeISA525fYGYQaaszlWSMP2IHdmPeGtIJJensEQxPK b7E/vPH2pbj3Sp9/OZHhoDUS601a4e9rulxXeB431DMDHegQEP+lyLdZRq69N8cX557U LFHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=eX9hSaKu; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id by8-20020a0564021b0800b005029d1c28b9si3869724edb.578.2023.04.11.13.13.41; Tue, 11 Apr 2023 13:14:29 -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=20221208 header.b=eX9hSaKu; 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 S229616AbjDKULK (ORCPT + 99 others); Tue, 11 Apr 2023 16:11:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229573AbjDKULJ (ORCPT ); Tue, 11 Apr 2023 16:11:09 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0F1E55AD for ; Tue, 11 Apr 2023 13:10:44 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54c060d7cdfso174198687b3.13 for ; Tue, 11 Apr 2023 13:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681243792; x=1683835792; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=kAz690gVxE8TfKjgFFdLa3/V7T3THIGi813h83xR35g=; b=eX9hSaKuZddrGiRb81kOHRHUQ8d+cRaNseEvFFxq+rbJMpuRDbassOCn41qnbg97xM HRT6Ec7dww6nMhII92UEzKUn+ke7SZ3cgJ+jQSThSNXEiSbJv2Ds5CZ8MqTYpuK2/Glp QpYIafPTmjGwEBZFO+1eL5EHxM/DpuEPBtyoSOxI1bDk69SoBMLBRxbpx7afZ8m2/Ndc Q87xsW8YKx6N56SETlZaYX9fiIoirH4ZBG9E6qy/e/yDX7epe/92zYaBT6akUbIpaAxI ZN1c1CWfFwxhW8OovXCrd9DaQXbXh/0285fKanj8OrLo8SfI0mOKiE7iKIu3viH2C8U5 Aj9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681243792; x=1683835792; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=kAz690gVxE8TfKjgFFdLa3/V7T3THIGi813h83xR35g=; b=Gxrs3nA7TNw4lq1Vsb+sYWWC8jSyk19uwhuJFj3eIrdx2YPQcTQtu3tvKuxE1+oD2m y4mnHRQLzYxrVBs0AnMGPMLoAKwD9YIsLzpQi19iU8sHhPBsyAmnnMQ0pqjFRLh0wqUx QdJmPbqlwOCqys+m2DGnwbsZl93SVRpn8Ux5dx728iLJWcFXjQp9PNqi/7IUsGaZQfDi gzAwUEOHipIwoTP4P3LNCQenQVAZHR6U1g2GfMDft5KRt0Kd9YsUMKaqTZQjHam3yBP8 RcYT2xRufuw52KDI+P+QaLHMtF4Vpi1KwxRzE8ROlphy3EazqM/xJrEKJIv1ctmyy3yB bzkA== X-Gm-Message-State: AAQBX9f/4SAe+Vxa0ZiPSWGzY0VgE+5nWRBkXRjNhxzDNXQ3bREPLGLQ LLCRBKQccmCm9//Fr/D//hQXLmeCBwE1 X-Received: from meowing-l.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3eba]) (user=maskray job=sendgmr) by 2002:a05:690c:d0f:b0:545:f3ed:d251 with SMTP id cn15-20020a05690c0d0f00b00545f3edd251mr380659ywb.1.1681243792318; Tue, 11 Apr 2023 13:09:52 -0700 (PDT) Date: Tue, 11 Apr 2023 20:09:44 +0000 Mime-Version: 1.0 Message-ID: <20230411200944.2591330-1-maskray@google.com> Subject: [PATCH v3] 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,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 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. There is no indication of obsolescence for --pack-dyn-relocs=relr. 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. GNU ld and newer versions of LLD report warnings (instead of errors) for unknown -z options. Only errors lead to non-zero exit codes. Therefore, we should test --pack-dyn-relocs=relr before testing -z pack-relative-relocs. 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(-) diff --git a/Makefile b/Makefile index 5aeea3d98fc0..d9c6d1839cf0 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. -- 2.40.0.577.gac1e443424-goog