From patchwork Tue Jan 18 17:20:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 50183 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 114103857805 for ; Tue, 18 Jan 2022 17:21:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id 4BD583858D39 for ; Tue, 18 Jan 2022 17:21:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4BD583858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pg1-x52f.google.com with SMTP id f8so14704080pgf.8 for ; Tue, 18 Jan 2022 09:21:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=subject:date:message-id:mime-version:content-transfer-encoding:cc :from:to; bh=FCx8Qk6JxpcXQ9tFxrXpO+Z0ILNq6vKIPHH1f5k6k2E=; b=ql1IlcyPjv+sv+8M2RkHPkMRtf8E64c9y9PqwAFCxXVx9SepO50twp45F4fEc6GkRS AKOBaazPG6O+gwwuLfTmVEH97cfJ5WsUkQsYXzR/14z9wzFg+GPu/Rq4C8VGXw4qbEfP ACQxTEOcEWbieANoeOTxFgApylAnUvNBPk7r4r+QU4fS9hhFnw43VzKBdcwqUsHW8196 k3tr4POk3Dd98quq2V2Fo6gfgZp+0g2pATP0M5lvykRuJLWDiocV5806sDZLC4X8JbQt XroBUjCl5r9BVHcAf3tyxUW021uJ0rcBpHlGV2QYikOmY0SfiEWrCzhO4z4hTfiEUnj6 RRTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:date:message-id:mime-version :content-transfer-encoding:cc:from:to; bh=FCx8Qk6JxpcXQ9tFxrXpO+Z0ILNq6vKIPHH1f5k6k2E=; b=R7HeAeWOlbzbX845/gGmUO0pqzBK7/j8/YNrUvZWVxvI2/JEnILFFR+PXQ4y9LTFwq rjz0WaiOlL5d0Yxm/a+fOejvnwzMPgZdrdexxNL1xwNIbM+iNVLNEr7TT9VcElvLaJHD 4pZfCOsSjh4SFiYoJ2jjyJSTZd0fxlWkzwtcJeJHTxGAR+uoCacUIogb9G75mzVWNQYk sNLCBFuGx1v8OnwmmgsjqBZTYR0p4HDc5zsKduIUiZWNbri8jD4a6SLQvLGD89+Ifer4 xxBDKepae97k7yACvnMxeB2iCVr+tCZD1xyu7vDeUN93YqLfQeebvjL4DbM9lefLt18A lMHA== X-Gm-Message-State: AOAM530TmFl3jwBm9Snxg6wm1LBli5x6HOQEaID4GkrIKBIUvlGfeysA esmq2CO40wKtvIKH0tNG6rm0Lp4dmahIoQ== X-Google-Smtp-Source: ABdhPJzcDxcM8Fm1l3uXEahCkfhLVcFe9eMAD8g/ZIVAxN4J/IwhFNi4wHtU8O3UqKP4hPqBUk99UA== X-Received: by 2002:a63:61d3:: with SMTP id v202mr10505191pgb.120.1642526494295; Tue, 18 Jan 2022 09:21:34 -0800 (PST) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id v22sm19224934pfu.14.2022.01.18.09.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 09:21:33 -0800 (PST) Subject: [PATCH] RISC-V: Document the degree of position independence that medany affords Date: Tue, 18 Jan 2022 09:20:56 -0800 Message-Id: <20220118172056.9343-1-palmer@rivosinc.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 From: Palmer Dabbelt To: gcc-patches@gcc.gnu.org X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The code generated by -mcmodel=medany is defined to be position-independent, but is not guaranteed to function correctly when linked into position-independent executables or libraries. See the recent discussion at the psABI specification [1] for more details. It would be better to reject these invalid sequences when linking, but as pointed out in a recent LD bug [2] there may be some compatibility issues related to the PCREL_HI20 relocations used to initialize GP. Given the complexity here it's unlikely we'll be able to reject these sequences any time soon, so instead just document that these may not work. [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/245 [2]: https://sourceware.org/bugzilla/show_bug.cgi?id=28789 gcc/ChangeLog: * doc/invoke.texi: Document the degree of position independence that -mcmodel=medany affords. Signed-off-by: Palmer Dabbelt --- Changes since v1: * Fix spelling of "guaranteed", twice. * Reference the binutils bug on rejecting these sequences, for more context. --- gcc/doc/invoke.texi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 5504971ea81..7bca621535f 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -27568,6 +27568,10 @@ Generate code for the medium-any code model. The program and its statically defined symbols must be within any single 2 GiB address range. Programs can be statically or dynamically linked. +The code generated by the medium-any code model is position-independent, but is +not guaranteed to function correctly when linked into position-independent +executables or libraries. + @item -mexplicit-relocs @itemx -mno-exlicit-relocs Use or do not use assembler relocation operators when dealing with symbolic