Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nIaQX-0007wI-Gq for mharc-grub-devel@gnu.org; Fri, 11 Feb 2022 13:13:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50020) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3SKcGYgcKCsczn5x4nBt11tyr.p1zt47o-qr8ryt07.14t@flex--maskray.bounces.google.com>) id 1nIaQV-0007ve-M8 for grub-devel@gnu.org; Fri, 11 Feb 2022 13:13:47 -0500 Received: from [2607:f8b0:4864:20::b4a] (port=35368 helo=mail-yb1-xb4a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3SKcGYgcKCsczn5x4nBt11tyr.p1zt47o-qr8ryt07.14t@flex--maskray.bounces.google.com>) id 1nIaQQ-0000ct-Cq for grub-devel@gnu.org; Fri, 11 Feb 2022 13:13:47 -0500 Received: by mail-yb1-xb4a.google.com with SMTP id a19-20020a25ca13000000b0061db44646b3so20499517ybg.2 for ; Fri, 11 Feb 2022 10:13:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=zG2dxlNlZQl1yP7AOxTiEUBDD6ebzQtxByDd+PWcLSY=; b=V47mVj5LDt2NAC4efMBLM6HIAYQJc9pV6BOUZlcWctFYwEFVp1+z6M597tOrTy+ESF f9vpqhnkCxMyaFePT0VJ7Xc9G1n7kYgOnNyytvJT/HiTuYXAS+HT2KTRgqVaV+FO+wXU MDz00MMgNgit5H1Ptac1TsWAd7hJFf/NY1MtzqVlf3+kI4DCcHI3qFG/8cS0IcgW23wY +vh2lsLwRX+jfRSnf6k9tE3eaQ9xEQGmO4ht6OOiCDK0b9xmK9FQD6solQS9OLGl+yg1 id94XDbFuxnT3fScZmFcx1I44vjUJ4eST/h6GpAh5BgqezeoA/v0YRhwOIZiYY6Xc4N+ a8HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=zG2dxlNlZQl1yP7AOxTiEUBDD6ebzQtxByDd+PWcLSY=; b=2pcZnI6XB1dgjcqJ/EhMDx92/iwzOPT9tCJWGbbM8+TouDb92MRXSBDP0Y2Qsqs3xt W9N2SDMKAumq9IFZvwQuWvUKfkzQhLLWNUaXp2RaGEp5wsmU8O9XRSDFCclPVikzMvv0 2cD8+NRQURyMh47HdkHuXPC8DTuzBJhrcmQcuK3KqMQVKKg2Oq9qKRgBy0djue0Xfx1W IttNtZVImyYKsEUz0hPsZPjY+foz92Jo1XSz1wHh9m7SRICvLlkc+aZos9N37p8GOLkX UfR1+nLSaKODxy0OAaA8lJnrAFevi1JVDSqvWcdSjGb+bqxHuUB8SG4T3HNmFs52M0+h C7HA== X-Gm-Message-State: AOAM532p9ailQW8bYrRsqjIRvF13XYi0U6FWCKZkhKOl0P4C2U7uawT8 iUVALDRrPeTFe5Irk5zAPGnXLFpgFYdbJyo3KJTgjHKusl/IXtuInSvcI7AsNOuBqoJygjJeHLZ WYZaWSlHR4Exd7hNPWlEHdfxhEscCtDmxLRzvDzc9PalmOaYrWhM8Z+G3nLU= X-Google-Smtp-Source: ABdhPJyVESlTss0thENzl3UN0YyFBYwuJ/devO9YNC4BRzw63r3a/achF0rhbDbgKypXdybTEw6V5ESgS4Q0 X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:200:f196:9660:6a48:3d09]) (user=maskray job=sendgmr) by 2002:a81:234f:: with SMTP id j76mr2937479ywj.227.1644603208514; Fri, 11 Feb 2022 10:13:28 -0800 (PST) Date: Fri, 11 Feb 2022 10:13:23 -0800 Message-Id: <20220211181323.3234413-1-maskray@google.com> Mime-Version: 1.0 Subject: [PATCH] configure: Replace -Wl,-r,-d with -Wl,-r and add -fno-common From: Fangrui Song To: grub-devel@gnu.org, Daniel Kiper Cc: Fangrui Song Content-Type: text/plain; charset="UTF-8" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b4a (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::b4a; envelope-from=3SKcGYgcKCsczn5x4nBt11tyr.p1zt47o-qr8ryt07.14t@flex--maskray.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -87 X-Spam_score: -8.8 X-Spam_bar: -------- X-Spam_report: (-8.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Feb 2022 18:13:47 -0000 In GNU ld and ld.lld, -d is used with -r to allocate space to COMMON symbols. This behavior is presumably to work around legacy projects which inspect relocatable output by themselves and do not handle COMMON symbols. grub does not do this. See https://github.com/llvm/llvm-project/issues/53660 -d is quite useless and ld.lld 15.0.0 will make -d no-op. COMMON symbols have special symbol resolution semantics which can cause surprise (see https://maskray.me/blog/2022-02-06-all-about-common-symbols). GCC<10 and Clang<11 defaulted to -fcommon. Just use -fno-common to avoid COMMON symbols. --- acinclude.m4 | 2 +- conf/Makefile.common | 2 +- configure.ac | 6 +++--- grub-core/Makefile.core.def | 20 ++++++++++---------- grub-core/genmod.sh.in | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 6e14bb553..fa7840f09 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -430,7 +430,7 @@ link_nopie_needed=no] AC_MSG_CHECKING([whether linker needs disabling of PIE to work]) AC_LANG_CONFTEST([AC_LANG_SOURCE([[]])]) -[if eval "$ac_compile -Wl,-r,-d -nostdlib -Werror -o conftest.o" 2> /dev/null; then] +[if eval "$ac_compile -Wl,-r -nostdlib -Werror -o conftest.o" 2> /dev/null; then] AC_MSG_RESULT([no]) [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'? rm -f conftest.o diff --git a/conf/Makefile.common b/conf/Makefile.common index f0bb6e160..1d7b39599 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -41,7 +41,7 @@ CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) STRIPFLAGS_KERNEL = -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding -LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d +LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r CPPFLAGS_MODULE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) CCASFLAGS_MODULE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) diff --git a/configure.ac b/configure.ac index 5c01af0fa..d1eaafee1 100644 --- a/configure.ac +++ b/configure.ac @@ -85,9 +85,9 @@ fi # Enable support for "restrict" keyword and other # features from gnu99 C language standard. -BUILD_CFLAGS="-std=gnu99 $BUILD_CFLAGS" -HOST_CFLAGS="-std=gnu99 $HOST_CFLAGS" -TARGET_CFLAGS="-std=gnu99 $TARGET_CFLAGS" +BUILD_CFLAGS="-std=gnu99 -fno-common $BUILD_CFLAGS" +HOST_CFLAGS="-std=gnu99 -fno-common $HOST_CFLAGS" +TARGET_CFLAGS="-std=gnu99 -fno-common $TARGET_CFLAGS" # Default HOST_CPPFLAGS HOST_CPPFLAGS="$HOST_CPPFLAGS -Wall -W" diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 8022e1c0a..ac00cc8a2 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -49,26 +49,26 @@ kernel = { nostrip = emu; - emu_ldflags = '-Wl,-r,-d'; - i386_efi_ldflags = '-Wl,-r,-d'; + emu_ldflags = '-Wl,-r'; + i386_efi_ldflags = '-Wl,-r'; i386_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; - x86_64_efi_ldflags = '-Wl,-r,-d'; + x86_64_efi_ldflags = '-Wl,-r'; x86_64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; ia64_efi_cflags = '-fno-builtin -fpic -minline-int-divide-max-throughput'; - ia64_efi_ldflags = '-Wl,-r,-d'; + ia64_efi_ldflags = '-Wl,-r'; ia64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; - arm_efi_ldflags = '-Wl,-r,-d'; + arm_efi_ldflags = '-Wl,-r'; arm_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; - arm64_efi_ldflags = '-Wl,-r,-d'; + arm64_efi_ldflags = '-Wl,-r'; arm64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame'; - riscv32_efi_ldflags = '-Wl,-r,-d'; + riscv32_efi_ldflags = '-Wl,-r'; riscv32_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame'; - riscv64_efi_ldflags = '-Wl,-r,-d'; + riscv64_efi_ldflags = '-Wl,-r'; riscv64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame'; i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; @@ -98,9 +98,9 @@ kernel = { i386_qemu_cppflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; emu_cflags = '$(CFLAGS_GNULIB)'; emu_cppflags = '$(CPPFLAGS_GNULIB)'; - arm_uboot_ldflags = '-Wl,-r,-d'; + arm_uboot_ldflags = '-Wl,-r'; arm_uboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; - arm_coreboot_ldflags = '-Wl,-r,-d'; + arm_coreboot_ldflags = '-Wl,-r'; arm_coreboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; i386_pc_startup = kern/i386/pc/startup.S; diff --git a/grub-core/genmod.sh.in b/grub-core/genmod.sh.in index 1250589b3..e57c4d920 100644 --- a/grub-core/genmod.sh.in +++ b/grub-core/genmod.sh.in @@ -83,9 +83,9 @@ else for dep in $deps; do echo "char moddep_$dep[] __attribute__ ((section(\"_moddeps, _moddeps\"))) = \"$dep\";" >>$t2; done if test -n "$deps"; then - @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $t2 $tmpfile -Wl,-r,-d + @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $t2 $tmpfile -Wl,-r else - @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $tmpfile -Wl,-r,-d + @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $tmpfile -Wl,-r fi rm -f $t1 $t2 $tmpfile mv $tmpfile2 $tmpfile -- 2.35.1.265.g69c8d7142f-goog