From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 82EFE3858CDB for ; Fri, 12 May 2023 20:33:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 82EFE3858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dabbelt.com Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-643a1656b79so7386693b3a.3 for ; Fri, 12 May 2023 13:33:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20221208.gappssmtp.com; s=20221208; t=1683923606; x=1686515606; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date:message-id :reply-to; bh=SwHo4IsVczMJ0esCCXx8dflhkrO6VBYKGifU9v4PZNk=; b=xDcQkDxfbv51Ye0rgzAXKP3FUw5by9LtoG0DMH6bgo3srMbqFO38Zd5LlvvRRRdbSY 7u0VahNPZCowDAHyPXCGCAZ1rXRiaBlr9wN3IDKVyVlGy0bQI0kx1IWlMoJXUwBzS7DQ pOG/spWl9ZG3FDMtX1ejaJTNcWB78UedRsGjA3lF1FM75YXlk8B5l/mbmfyEcNvBoVl3 OZ0xn2uEvQsmWsy0ollrZKrleX7C0PS9LCimO+msCSUcz7GJ7xwoXL8Oo2Mmzcn+XISI 8xLCgwGG6LtbGuW1gqrQNNTWFF5D0eHFzCGgGGcwDlw3dmPIxUg2H/Ec85gT3Ic7g6AO zQ3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683923606; x=1686515606; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SwHo4IsVczMJ0esCCXx8dflhkrO6VBYKGifU9v4PZNk=; b=iItub6pSuzFbng9n3eTRYmpV1m/96rkK6wSk9yfWRjuDFzoBp9qdQVCxgVIBWBwzSs 7veX09SdXSnI4/65lLBYMP3KzGTDGe4Y8UkKPftwMysYB8ASCelnXQNdoj2hR2Sgnh1k Wt+NDPmTCjdukvVe5LO+beUPItTQ2Y/3TPRaZ330BrDwM7v67qB76TYPL8a0CEoF+p3z Y4RNGRy5agHR/RvTOlkvNu7cOzaqkYgEcX6Hd+yXPHThQ8xTCeAZw7vP2oKXWweeybfU DqxkcAzHXCl+mioMEo+xcXN4M9JylG2dgRA0ufDxXddqU8W69zfbCYgulGcSNsnNGMCY QoQA== X-Gm-Message-State: AC+VfDxzKP4Mq4o+lJfkrUAu5cJoWPX7KIV3+NAkC462u5htxqc1qgP2 ePC2StZ828vMpuGAkr4cCFEigA== X-Google-Smtp-Source: ACHHUZ6kJSavl0nORBxHBNiRGc2fYKmUKALYNJA0Tapl+fQUEBtwmvx3gfdLqTAe8LqVmJ42f8mjrQ== X-Received: by 2002:a05:6a20:72a2:b0:100:c4f1:72a0 with SMTP id o34-20020a056a2072a200b00100c4f172a0mr24118199pzk.3.1683923606309; Fri, 12 May 2023 13:33:26 -0700 (PDT) Received: from localhost ([50.221.140.188]) by smtp.gmail.com with ESMTPSA id d30-20020a631d5e000000b0051baf3f1b3esm7100809pgm.76.2023.05.12.13.33.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 13:33:25 -0700 (PDT) Date: Fri, 12 May 2023 13:33:25 -0700 (PDT) X-Google-Original-Date: Fri, 12 May 2023 13:33:04 PDT (-0700) Subject: Re: global pointer gets overwritten with dlopen(3) on RISC-V In-Reply-To: <877ctdpaww.fsf@oldenburg3.str.redhat.com> CC: maskray@google.com, l.stelmach@samsung.com, libc-alpha@sourceware.org, schwab@suse.de, adhemerval.zanella@linaro.org, joseph@codesourcery.com, binutils@sourceware.org, m.pikula@partner.samsung.com, m.szyprowski@samsung.com, k.lewandowsk@samsung.com From: Palmer Dabbelt To: fweimer@redhat.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,KAM_INFOUSMEBIZ,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, 12 May 2023 13:11:43 PDT (-0700), fweimer@redhat.com wrote: > * Fangrui Song: > >>>1. Make -mno-relax the default for ld(1) (on Linux?). We have no >>>benchmarks whatsoever, but global variables aren't very popular in >>>application code these days and the gp register allows access to a >>>single memory page (4kB) only. No big deal really. >> >> I do agree that --no-relax-gp is a sensible default choice for GNU ld. >> https://maskray.me/blog/2021-03-14-the-dark-side-of-riscv-linker-relaxation#global-pointer-relaxation >> >> Perhaps you can start a separate topic on binutils? :) >> >> According to a doc from SiFive about -static -mcpu=sifive-u74 builds, >> https://docs.google.com/spreadsheets/d/14V7cPbyc80AcGHzsMaw9hYb232dzRbGCmTApnxj-SpU/edit#gid=0 >> global pointer relaxation saves at best 0.5% size (I guess that refers >> to .text. If we count all allocable sections, the percentage is likely >> even smaller.) > > For a mature toolchain, 0.5% in code size reduction would be *a lot*, > so I wouldn't dismiss that. That's broadly speaking why it sticks around. We've got a bunch of headaches related to relaxation, GP or otherwise, but they improve performance and nobody's figured out how to replace that yet. > Do we have a reproducer? Is the issue actually about gp relaxation for > the main executable? In general we don't reference GP from shared libraries as we don't have a GP save/restore scheme. There may be a bug floating around here somewhere, in which case we should fix it, but the original post sounds like it wasn't a supported use case. > Thanks, > Florian