From patchwork Mon Nov 29 12:48:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nelson Chu X-Patchwork-Id: 48250 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 709D73858438 for ; Mon, 29 Nov 2021 12:48:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id 36495385841B for ; Mon, 29 Nov 2021 12:48:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 36495385841B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pg1-x52a.google.com with SMTP id 71so15978329pgb.4 for ; Mon, 29 Nov 2021 04:48:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=iJfDXH/JnZEi44Bo3wPd0MTJ4lh8Fl0jGg0ykAZi3DA=; b=fHmNQGsTkHGmbvhyOxJS6haAG1RTTfH/03YJqIggnguAhMwTwp/XoPPOogtl38fsFt rwiDu5ErznV3Hk2wG+16VGzl+npIg3+4mHxDp/IzgkMibWm4OsuLlgsam1VgRXxHi898 7XQfjWnBYJrPN495Py6MXuK3iS6ZgYoceAIsNkz7UFeiCXLkjjTAo6QA4ki1jYARNz4A xqiMYVxKvesXnuzkbCgrLNS8qQQ/iGeGlG0ys9Tn74Qd89YX/viP5v3b+GSnHo0B/d8/ OtAiNYVliWPfkmlVghCQotTPWqIK0O9jVsEdA0MBQ2a+VaDMd835R6KLQNjNSXOsv+M3 zSjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=iJfDXH/JnZEi44Bo3wPd0MTJ4lh8Fl0jGg0ykAZi3DA=; b=A1fdrSI1ojWJIpkWhBhp7DatFYM46bYYjwZ46LGbBg9aJFnl6HnXh3HNxrFVH43Sms 6J273t1xcj9CWZOyUrnW733fBYZGvywpjm8bC6c1ZKox6IJsxBEVHdSJiyzM3fd9qp7G 12ppRZG8CdCCF+xvHP5iptz/fXOy9BugIam27vs/tQBbh84g6cx2U2+FO1exVrH1pIp7 qPT8wdwitzGlbPlwUgFaanIrDSMiM1hauccv+oPtaUtgGm1YUNwBzOsOk3S/uA4/KCMH +uFwDGfC2CZ+9nKDQ+nXm4QYRfE/ypB2s0X0kSapkgSUpDypw7y12PiIl6/2wKcnrFEh QsUg== X-Gm-Message-State: AOAM530rmZWOnKvQoCTYps0LE8acX78ssx6SZT4sUP6vdW7o6ncVMdJn 2cemtlMYkYWe9Il2uDpX6VOwvCUcYHBaDg== X-Google-Smtp-Source: ABdhPJx0BgC7jFVomyvQZ7fe1erMBJvC/JpkZfcIsSstZjk4rlmZYYmdyFsWxkw1AJGfSjLnTpcwIQ== X-Received: by 2002:a63:ee53:: with SMTP id n19mr21404868pgk.593.1638190102073; Mon, 29 Nov 2021 04:48:22 -0800 (PST) Received: from gamma00.internal.sifive.com ([64.62.193.194]) by smtp.gmail.com with ESMTPSA id nn15sm19221908pjb.11.2021.11.29.04.48.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Nov 2021 04:48:21 -0800 (PST) From: Nelson Chu To: gcc-patches@gcc.gnu.org, jim.wilson.gcc@gmail.com, kito.cheng@sifive.com, maskray@google.com Subject: [PATCH] RISC-V: jal cannot refer to a default visibility symbol for shared object. Date: Mon, 29 Nov 2021 04:48:20 -0800 Message-Id: <1638190100-29898-1-git-send-email-nelson.chu@sifive.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nelson.chu@sifive.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This is the original binutils bugzilla report, https://sourceware.org/bugzilla/show_bug.cgi?id=28509 And this is the first version of the proposed binutils patch, https://sourceware.org/pipermail/binutils/2021-November/118398.html After applying the binutils patch, I get the the unexpected error when building libgcc, /scratch/nelsonc/riscv-gnu-toolchain/riscv-gcc/libgcc/config/riscv/div.S:42: /scratch/nelsonc/build-upstream/rv64gc-linux/build-install/riscv64-unknown-linux-gnu/bin/ld: relocation R_RISCV_JAL against `__udivdi3' which may bind externally can not be used when making a shared object; recompile with -fPIC Therefore, this patch add an extra hidden alias symbol for __udivdi3, and then use HIDDEN_JUMPTARGET to target a non-preemptible symbol instead. The solution is similar to glibc as follows, https://sourceware.org/git/?p=glibc.git;a=commit;h=68389203832ab39dd0dbaabbc4059e7fff51c29b libgcc/ChangeLog: * config/riscv/div.S: Add the hidden alias symbol for __udivdi3, and then use HIDDEN_JUMPTARGET to target it since it is non-preemptible. * config/riscv/riscv-asm.h: Added new macros HIDDEN_JUMPTARGET and HIDDEN_DEF. --- libgcc/config/riscv/div.S | 15 ++++++++------- libgcc/config/riscv/riscv-asm.h | 6 ++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libgcc/config/riscv/div.S b/libgcc/config/riscv/div.S index c9bd787..723c3b8 100644 --- a/libgcc/config/riscv/div.S +++ b/libgcc/config/riscv/div.S @@ -40,7 +40,7 @@ FUNC_BEGIN (__udivsi3) sll a0, a0, 32 sll a1, a1, 32 move t0, ra - jal __udivdi3 + jal HIDDEN_JUMPTARGET(__udivdi3) sext.w a0, a0 jr t0 FUNC_END (__udivsi3) @@ -52,7 +52,7 @@ FUNC_BEGIN (__umodsi3) srl a0, a0, 32 srl a1, a1, 32 move t0, ra - jal __udivdi3 + jal HIDDEN_JUMPTARGET(__udivdi3) sext.w a0, a1 jr t0 FUNC_END (__umodsi3) @@ -95,11 +95,12 @@ FUNC_BEGIN (__udivdi3) .L5: ret FUNC_END (__udivdi3) +HIDDEN_DEF (__udivdi3) FUNC_BEGIN (__umoddi3) /* Call __udivdi3(a0, a1), then return the remainder, which is in a1. */ move t0, ra - jal __udivdi3 + jal HIDDEN_JUMPTARGET(__udivdi3) move a0, a1 jr t0 FUNC_END (__umoddi3) @@ -111,12 +112,12 @@ FUNC_END (__umoddi3) bgtz a1, .L12 /* Compute __udivdi3(-a0, a1), then negate the result. */ neg a1, a1 - j __udivdi3 /* Compute __udivdi3(-a0, -a1). */ + j HIDDEN_JUMPTARGET(__udivdi3) /* Compute __udivdi3(-a0, -a1). */ .L11: /* Compute __udivdi3(a0, -a1), then negate the result. */ neg a1, a1 .L12: move t0, ra - jal __udivdi3 + jal HIDDEN_JUMPTARGET(__udivdi3) neg a0, a0 jr t0 FUNC_END (__divdi3) @@ -126,7 +127,7 @@ FUNC_BEGIN (__moddi3) bltz a1, .L31 bltz a0, .L32 .L30: - jal __udivdi3 /* The dividend is not negative. */ + jal HIDDEN_JUMPTARGET(__udivdi3) /* The dividend is not negative. */ move a0, a1 jr t0 .L31: @@ -134,7 +135,7 @@ FUNC_BEGIN (__moddi3) bgez a0, .L30 .L32: neg a0, a0 - jal __udivdi3 /* The dividend is hella negative. */ + jal HIDDEN_JUMPTARGET(__udivdi3) /* The dividend is hella negative. */ neg a0, a1 jr t0 FUNC_END (__moddi3) diff --git a/libgcc/config/riscv/riscv-asm.h b/libgcc/config/riscv/riscv-asm.h index 8550707..96dd85b 100644 --- a/libgcc/config/riscv/riscv-asm.h +++ b/libgcc/config/riscv/riscv-asm.h @@ -33,3 +33,9 @@ X: #define FUNC_ALIAS(X,Y) \ .globl X; \ X = Y + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a ## b +#define HIDDEN_JUMPTARGET(X) CONCAT1(__hidden_, X) +#define HIDDEN_DEF(X) FUNC_ALIAS(HIDDEN_JUMPTARGET(X), X); \ + .hidden HIDDEN_JUMPTARGET(X)