From patchwork Tue Dec 1 10:22:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 41240 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 68CC03944810; Tue, 1 Dec 2020 10:23:11 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 336103944433 for ; Tue, 1 Dec 2020 10:23:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 336103944433 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vincent.chen@sifive.com Received: by mail-pl1-x632.google.com with SMTP id u2so874928pls.10 for ; Tue, 01 Dec 2020 02:23:09 -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=KE7rzlMJ6PGL/tiHRc8R0c06HVkhkCkorjV3NMnsfMk=; b=Rno/s1njbKFW+9cRCZiBsv/zSO4+Bk+cvmOxBRTn8p80tf42gbNAsCFT89LOpfubC/ FTwPkvzFnA/j1fzYBRVQY6hv7C2DPhTdUMOYAfLvONuQvgTwa9914vH7c6R8xPPMnK4W SR4HzUi/rvWktLhrzEml6Ry7sgjoKJkiWyCW6LbG+BFDnyCh/x4a9fWfdl2LS1zxa7hE XXCtepEFgeM1qjPQOFMXKbsuHfpUZPgj7QnMSfxa/lgVycGhUrL0BV3OBOXbAI7THSS9 5qymP8NNG5ktGfPr4m9LaU0Q5FP8sGe0NBegR4N9/9mKE/umtm9Nr5rnv4uzKcWh/6A2 vOaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KE7rzlMJ6PGL/tiHRc8R0c06HVkhkCkorjV3NMnsfMk=; b=mpUYwhc5ZRilrBJMTcferTV2lD52cFMurYmJclJuHiHNzWcz+lmyYBave91PARrDVc bumXOkolphqfcQAKuuK2bCtWfnfLJXGtTcK4vZR7UbJ6OwvzJmpHdnnsyHvobEeS6V5s an2eS3p+DlUGUxSvZxDHzn+FWChDKdz02HJkd7Iqw+1pOtbojGdyyQd3+YoLHOWGZYcP U4+LjNxS+KpyU1zdeKzrzrLjsuI7WcB2rKoMLUyFETJVvcmH0OZRT7sbn5OxF+pg48Uo EPkoCn6ecHm1C4SnIlMoWo4ahaON/w5lkbOe1eXwD/EK62HI+mJVpNn93DcFaLsMDoHx eSaw== X-Gm-Message-State: AOAM533i58eZ5U6UK2jLNVq7yiCT4y7L6NEDRLRzS95azwT8XCa4avLi 2wHDzp3ANbq6hEbmc2CR/4qbhvJekatUEqH/ X-Google-Smtp-Source: ABdhPJx+7oBQrybJGLpnmKIDcuTIsaOISwips1QXPxALgPC/jLv5QiVrpvMStGjWhTkrxfGMLRHCtA== X-Received: by 2002:a17:90a:c6:: with SMTP id v6mr1962192pjd.95.1606818188137; Tue, 01 Dec 2020 02:23:08 -0800 (PST) Received: from VincentChen-ThinkPad-T480s.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id y10sm2096785pjm.34.2020.12.01.02.23.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Dec 2020 02:23:07 -0800 (PST) From: Vincent Chen To: libc-alpha@sourceware.org, palmer@dabbelt.com, darius@bluespec.com, dj@redhat.com Subject: [PATCH 0/2] riscv: add support for GNU indirect function Date: Tue, 1 Dec 2020 18:22:58 +0800 Message-Id: <1606818180-17436-1-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: , Cc: vincent.chen@sifive.com, nelson.chu@sifive.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The riscv Binutils supported GNU indirect function in the commit 02dd9d25. In order to make the whole mechanism work properly, the first patch adds the required ports to enable Glibc to address the riscv IRELATIVE relocation. In addition, since the dynamic linker resolves the IRELATIVE relocation before jumping into the executable program, the $gp register has not been initialized when the IFUNC resolver function is executed. It cause that some unexpected error may occur when the dynamic loader resolves the IREALTIVE relocation of the position-dependent executable program. To solve this problem, a new RISCV specific dynamic entry, DT_RISCV_GP, created by Binutils is used to record the gp address. The dynamic linker can use it to initialize $gp register before resolving the IREALTIVE relocation of the PDE program. The related patch of DT_RISCV_GP in Binutils could be found in https://sourceware.org/pipermail/binutils/2020-December/114346.html Vincent Chen (2): riscv: Add support for GNU indirect function riscv: Initialize $gp before resolving the IRELATIVE relocation elf/elf.h | 4 +++ libc-abis | 1 + sysdeps/riscv/dl-dtprocnum.h | 22 +++++++++++++++ sysdeps/riscv/dl-irel.h | 53 ++++++++++++++++++++++++++++++++++++ sysdeps/riscv/dl-machine.h | 31 +++++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 sysdeps/riscv/dl-dtprocnum.h create mode 100644 sysdeps/riscv/dl-irel.h