From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <37GEUYAcKCgkvj1t0j7pxxpun.lxvurkl-juyqj1x30ln5j0n.x0p@flex--maskray.bounces.google.com> Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id CBF2F3870854 for ; Fri, 29 Jan 2021 19:28:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CBF2F3870854 Received: by mail-yb1-xb49.google.com with SMTP id f127so11065715ybf.12 for ; Fri, 29 Jan 2021 11:28:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Tmh+Bx2E6Tb/penoqG3vgr+CMGPb+fRCDV4l0cMtyHk=; b=CFAHnFy03t3q6HdPSPwUZNaxhfAN5TdaVSwYy0Irb+nKnRZ82/5VyBK7+6oALum2s8 MpagomTrTtujZb1HQNF0cBuuA17tvV7HVILKjPD9rGij7r2NPbTzA/4JfdTLiHSMnSyU FXRwbb+YaOD8kL46M3fDhRj+Jq4xz+wPSGhyZO/5gU3T/nG++oKDp+MA42Eqqpj8C+ws f2XT/liAC+4CFpAoqHiOr+geDQCV1rdy/hklcocxTgWdPGs46u0PTqNBMa3jsiURwxej 7/128BgaDyDVnf/Q0D2Ou89SBs1VwV6fGJ7SAGP2JxrzR8w0ziwYhT79yPHmgZR7N8cv nCUw== X-Gm-Message-State: AOAM531R2Ber2U8ZM+FIGWJeGum6XLxe249EyQE47tGN9zni3I/GB5ru mdNADyR/uFpC4iMCXl+om0eHp1QX9MSdd5CB1Iy5e6Xtq1Zi+deQro3AiNIH86JzHrVyR07NWlN x2nhSB2u+38x4DoadumetipFTuQVChRqr/a9xPv4mCTyhV6DnIbRWY3hBbijUU3SfZn/P X-Google-Smtp-Source: ABdhPJze2KdQW/ArG9Slq5ZDA3fu9P4x9T9XwPMQwTaBJ0CxxILoGQlIRoZ7zNZ9iIfrxHI5BX1CBLz05HiS Sender: "maskray via sendgmr" X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:0:a6ae:11ff:fe11:4abb]) (user=maskray job=sendgmr) by 2002:a25:6c05:: with SMTP id h5mr8162429ybc.450.1611948524257; Fri, 29 Jan 2021 11:28:44 -0800 (PST) Date: Fri, 29 Jan 2021 11:28:24 -0800 In-Reply-To: <56de4bc0-05b1-49f9-32ce-b9eab7fdc510@linaro.org> Message-Id: <20210129192824.804615-1-maskray@google.com> Mime-Version: 1.0 References: <56de4bc0-05b1-49f9-32ce-b9eab7fdc510@linaro.org> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog Subject: [PATCH v2] elf: Replace a --defsym trick with an object file to be compatible with LLD From: Fangrui Song To: libc-alpha@sourceware.org, Adhemerval Zanella Cc: "H.J. Lu" , Fangrui Song Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-19.9 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jan 2021 19:28:50 -0000 The existing code specifies -Wl,--defsym=malloc=0 and other malloc.os definitions before libc_pic.a so that libc_pic.a(malloc.os) is not fetched. This trick is used to avoid multiple definition errors which would happen as a chain result: dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffer_set_array_size.os) libc_pic.a(scratch_buffer_set_array_size.os) has an undefined free free fetches libc_pic.a(malloc.os) libc_pic.a(malloc.os) has an undefined __libc_message __libc_message fetches libc_pic.a(libc_fatal.os) libc_fatal.os will cause a multiple definition error (__GI___libc_fatal) >>> defined at dl-fxstatat64.c >>> /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fatal) >>> defined at libc_fatal.c >>> libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Release/libc_pic.a LLD processes --defsym after all input files, so this trick does not suppress multiple definition errors with LLD. Split the step into two and use an object file to make the intention more obvious and make LLD work. This is conceptually more appropriate because --defsym defines a SHN_ABS symbol while a normal definition is relative to the image base. See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html for discussions about the --defsym semantics. This commit is available on https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/maskray/lld --- elf/Makefile | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/elf/Makefile b/elf/Makefile index 5d666b1b0c..03e4034cc7 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -526,10 +526,6 @@ rtld-stubbed-symbols = \ malloc \ realloc \ -# The GCC arguments that implement $(rtld-stubbed-symbols). -rtld-stubbed-symbols-args = \ - $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols)) - ifeq ($(have-ssp),yes) # rtld is not built with the stack protector, so these references will # go away in the rebuilds. @@ -538,9 +534,10 @@ endif $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a @-rm -f $@T - $(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \ - '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T - rm -f $@.o + printf '$(patsubst %,.globl %\n,$(rtld-stubbed-symbols)) $(patsubst %,%:\n,$(rtld-stubbed-symbols))' | \ + $(CC) -o $@T.o $(ASFLAGS) -c -x assembler - + $(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T + rm -f %@T.o $@.o mv -f $@T $@ # For lld, skip preceding addresses and values before matching the archive and the member. -- 2.30.0.365.g02bc693789-goog