Message ID | 20240205101427.2862503-1-syq@gcc.gnu.org |
---|---|
State | Accepted |
Headers |
Return-Path: <binutils-bounces+ouuuleilei=gmail.com@sourceware.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp779530dyb; Mon, 5 Feb 2024 02:15:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHUI2et6vxMiJAs+biHo9FEzcGqYAJIyxkWIkbLarODDRf2PiElC3N8oMv3DV51ZxWnHFLJ X-Received: by 2002:a05:620a:459f:b0:781:3e18:c640 with SMTP id bp31-20020a05620a459f00b007813e18c640mr10657711qkb.19.1707128102293; Mon, 05 Feb 2024 02:15:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707128102; cv=pass; d=google.com; s=arc-20160816; b=cgKGGPnu/eB0WULoldYN4JUjVP4N/5/73/TIgXmytPso3DLJI2br1lKUTGtImgFekv EBlmRB45yuhC7WpZV0G+ymm5lMG1SjnSSjo0sLfTKPjAEmIIHM6QCKYTEkybYhcgATro PgSkdBOjxib00sDy8Y1/hlzIsLo2alICHmAGWhcaBYmNwBv4nCiUZK1UkVKy6WRQGKvN HzYny8ivkM7bTQCUEB6VL3z1Xa+wcX7UyM3fsRQ4H+Alggr0xhven5GaH5d83dJ9Vx7h JRtqA7mEn34XnYdLYC0IRxSvUjwiDnAfPhVeBbjBwQHlQ/YgVs/k8U76LexVKU5eMrlI s9Kw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=QQIZkZFWSUlA0Uubh6hgKTKlYWh2Zk0ajlXV7HlETV8=; fh=/y4OuepztHckP83qanCu3F0EbXXl4ziBu0aJOiVM46Q=; b=UPF2sXZ0mDOYks66/W5tJsLECmICHapWvE1/e4wvebGOf9m/TzwDBe/gm/DNZvkrJh qAXced/fmNItzcjGQAmKzVWxC6tLDOZjWq3dz8gMWvW4fcsxTb8AqJq+Eipe4mF11s93 FkNtETG3akQ2nwRvaKwRdffyqRuCZKmo+HoVYCUBEoLxh/2SCImNLoWaEfwCsU5scjN2 o7ZSbmeHSwXYAwG5xQEuUtt1aB+HqNyQXvpud6132Ouyy5QNsk4GLr2HpSUy9f3wKi/M zcH5cjvYPo5b1oElkkCB+qxl7ItIwLkAG1KYONP4mXXrl534E711N3xN9rH9oIcNv5Io OC1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=srYavPpY; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org X-Forwarded-Encrypted: i=1; AJvYcCU6Xl1R5Kf3d4uTljVT4R3HdLXf4SnmNfBHdq7UKBsmkJpnYcWtDEpCv7HZwGjkBOnJYAUYOIvhfZBAqwHh7WNkeJTm8Q== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o12-20020a05620a110c00b0078341846c86si8009085qkk.414.2024.02.05.02.15.02 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 02:15:02 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=srYavPpY; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EDEA53858283 for <ouuuleilei@gmail.com>; Mon, 5 Feb 2024 10:15:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDEA53858283 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707128102; bh=QQIZkZFWSUlA0Uubh6hgKTKlYWh2Zk0ajlXV7HlETV8=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=srYavPpYyXdI5d+oWe2la6M99meIk1ORnXCgeCiS+Z2WaXhkkZOLjSvV4rfp1dp/R bn9cmXhaOpeeJTJE9qvC3+7KJ9tcIZZxW/yfJdVDnWs/3Q6YGJsebmsQADc/CrvmM6 lK84gj1u9LDSLS8ybAByU0ciTPBrpiphO6cM+EeY= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by sourceware.org (Postfix) with ESMTPS id 8F1BE3858CDB for <binutils@sourceware.org>; Mon, 5 Feb 2024 10:14:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F1BE3858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8F1BE3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707128090; cv=none; b=UCWIj5Px8xn3xhAIFR7MljBAgEcKYAhbhjXyk1ky18igc2sPNg0L0ATNgm0Ly9krz8YGIius+pxAyoOx1VWPftXekDQ+dB463tVbUIkxbPfjBDDZvLFtf0IqmvigoxgK3VgHqee5btQVRVcMMfssocN6seGS157z7224OBoJU1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707128090; c=relaxed/simple; bh=WhDJ/GRJ6vfnLABteDJGpU80w5EWTmBREFS7nTCcDhU=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=rmYUKtn0THQt8kSj0bBcB68t/AY3uWdouKYxINLn/RT5L1JRsi83zKcEO0YLJt+flg5eAEJ6gJO7W3E2zj0/7PBS3zrBTyWZ9DH3BuXyeX32bRZdJQa1C6Y3tSoCZeRDATlzoTVvVHqADk7jAim1fkf0AfVkSAJ+U8xo7gJb04g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1d958e0d73dso22799355ad.1 for <binutils@sourceware.org>; Mon, 05 Feb 2024 02:14:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707128087; x=1707732887; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QQIZkZFWSUlA0Uubh6hgKTKlYWh2Zk0ajlXV7HlETV8=; b=eQwJbUfYT84t8qGjzNqDwkiJNPr1HEQe6tMoYJRqSReZW0neYAbSyRNO4fhBurqHVX YjohWOQ+9Bj4rMvMhDVcj1OrTxM8D+fGPrFW+WMJLaR7Yz6Vzz8g6ibsMezmHHG3aG1T x8t6/bMU2fTv6zvhxagM125RRk0ZgWFUOS3rmCEiu2xxpe9O1c7TDfvuB2onuPiZA5W3 p70pDxaZO8oxXredb4KqEByVccBTMpHXnrNP1alT9q35b6iwJSQ47ZhIMz8KIy7km3V4 0pnmKvN/Mo5TqypFc8hNy7ZeoionAEn3RxX5eR7jnNaSftj5E8OsrlN9XS7j2Xk/nOYg 4cPQ== X-Gm-Message-State: AOJu0YwfalBDWP0V84pEsFzbPSj2xFirQPm0uCPG1hSQkex9tauWAzli +bN6XYyiEBp5jpiIPnlt7ftgehHpQcOHrRW1pMNSqRpbVc1WNkCM X-Received: by 2002:a17:903:18b:b0:1d5:8cbc:863c with SMTP id z11-20020a170903018b00b001d58cbc863cmr7095969plg.27.1707128087431; Mon, 05 Feb 2024 02:14:47 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVR42ltA+FoaJMESnIv721NXUwatH5tyhakB3QY00OhYbpbbb6uVT2Byn96UXajYYmSMNwaPxtDM9SvlY6SOOpOnGRFqockBF/h6/akad41DXJ8t7ax Received: from localhost.localdomain ([149.248.38.156]) by smtp.gmail.com with ESMTPSA id u11-20020a170903308b00b001d71a0b1109sm5957716plc.116.2024.02.05.02.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 02:14:47 -0800 (PST) From: YunQiang Su <syq@gcc.gnu.org> To: nickc@redhat.com Cc: binutils@sourceware.org, macro@orcam.me.uk, xry111@xry111.site Subject: [PATCH] MIPS/Gas: Support .L/$ as the mark of local symbol Date: Mon, 5 Feb 2024 18:14:27 +0800 Message-Id: <20240205101427.2862503-1-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790053556964389420 X-GMAIL-MSGID: 1790053556964389420 |
Series |
MIPS/Gas: Support .L/$ as the mark of local symbol
|
|
Checks
Context | Check | Description |
---|---|---|
snail/binutils-gdb-check | success | Github commit url |
Commit Message
YunQiang Su
Feb. 5, 2024, 10:14 a.m. UTC
In as.texi, there are lines: A local symbol is any symbol beginning with certain local label prefixes. By default, the local label prefix is @samp{.L} for ELF systems or @samp{L} for traditional a.out systems, but each target may have its own set of local label prefixes. Let's support it for MIPS: 1) For OldABI, GCC uses "$" to mark local symbols, and for NewABI, ".L" is used. So let's support both for OldABI, and ".L" only for NewABI. 2) Emit an fatal error, if a local symbol is used, while not defined, just like LLVM does. --- gas/config/tc-mips.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
Comments
YunQiang Su <syq@gcc.gnu.org> 于2024年2月5日周一 18:14写道: > > In as.texi, there are lines: > A local symbol is any symbol beginning with certain local > label prefixes. By default, the local label prefix is > @samp{.L} for ELF systems or @samp{L} for traditional a.out > systems, but each target may have its own set of local > label prefixes. > > Let's support it for MIPS: > 1) For OldABI, GCC uses "$" to mark local symbols, and > for NewABI, ".L" is used. So let's support both for > OldABI, and ".L" only for NewABI. > 2) Emit an fatal error, if a local symbol is used, while > not defined, just like LLVM does. @Maciej W. Rozycki ping. > --- > gas/config/tc-mips.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c > index 43c12de2c8a..a84b13e1815 100644 > --- a/gas/config/tc-mips.c > +++ b/gas/config/tc-mips.c > @@ -17725,6 +17725,16 @@ pic_need_relax (symbolS *sym) > if (symbol_section_p (sym)) > return true; > > + if (strstr (S_GET_NAME (sym), ".L") == S_GET_NAME (sym) > + || ((mips_abi == O64_ABI || mips_abi == O32_ABI) > + && strstr (S_GET_NAME (sym), "$") == S_GET_NAME (sym))) > + { > + if (!S_IS_DEFINED (sym)) > + as_fatal (_("undefined temporary symbol: %s"), > + S_GET_NAME (sym)); > + return true; > + } > + > symsec = S_GET_SEGMENT (sym); > > /* This must duplicate the test in adjust_reloc_syms. */ > -- > 2.39.2 >
On Mon, 5 Feb 2024, YunQiang Su wrote: > In as.texi, there are lines: > A local symbol is any symbol beginning with certain local > label prefixes. By default, the local label prefix is > @samp{.L} for ELF systems or @samp{L} for traditional a.out > systems, but each target may have its own set of local > label prefixes. > > Let's support it for MIPS: > 1) For OldABI, GCC uses "$" to mark local symbols, and > for NewABI, ".L" is used. So let's support both for > OldABI, and ".L" only for NewABI. > 2) Emit an fatal error, if a local symbol is used, while > not defined, just like LLVM does. I gather you want to avoid a case of an undefined reference making it to output for a symbol whose name suggests its a local label, right? But that seems like material for the generic part of GAS rather than the MIPS backend only (and then specifically SVR4 PIC only and not non-PIC or VxWorks, according to your code as submitted), so that all targets behave consistently, and I can't see e.g. i386 GAS doing it. So a question raises: what problem are you trying to solve? Can you give us a piece of code that you think is handled incorrectly by GAS, and why? Maciej
Maciej W. Rozycki <macro@orcam.me.uk> 于2024年2月21日周三 21:33写道: > > On Mon, 5 Feb 2024, YunQiang Su wrote: > > > In as.texi, there are lines: > > A local symbol is any symbol beginning with certain local > > label prefixes. By default, the local label prefix is > > @samp{.L} for ELF systems or @samp{L} for traditional a.out > > systems, but each target may have its own set of local > > label prefixes. > > > > Let's support it for MIPS: > > 1) For OldABI, GCC uses "$" to mark local symbols, and > > for NewABI, ".L" is used. So let's support both for > > OldABI, and ".L" only for NewABI. > > 2) Emit an fatal error, if a local symbol is used, while > > not defined, just like LLVM does. > > I gather you want to avoid a case of an undefined reference making it to > output for a symbol whose name suggests its a local label, right? > > But that seems like material for the generic part of GAS rather than the > MIPS backend only (and then specifically SVR4 PIC only and not non-PIC or > VxWorks, according to your code as submitted), so that all targets behave > consistently, and I can't see e.g. i386 GAS doing it. > > So a question raises: what problem are you trying to solve? Can you give > us a piece of code that you think is handled incorrectly by GAS, and why? > main: la $4,$hello $ mipsel-linux-gnu-as -KPIC tt.s && objdump -dr a.out 00000000 <main>: 0: 8f840000 lw a0,0(gp) 0: R_MIPS_GOT16 $hello In this case, GAS treat $hello as an external symbol, so only a single R_MIPS_GOT16 is used. > Maciej
On Wed, 21 Feb 2024, YunQiang Su wrote: > > > In as.texi, there are lines: > > > A local symbol is any symbol beginning with certain local > > > label prefixes. By default, the local label prefix is > > > @samp{.L} for ELF systems or @samp{L} for traditional a.out > > > systems, but each target may have its own set of local > > > label prefixes. > > > > > > Let's support it for MIPS: > > > 1) For OldABI, GCC uses "$" to mark local symbols, and > > > for NewABI, ".L" is used. So let's support both for > > > OldABI, and ".L" only for NewABI. > > > 2) Emit an fatal error, if a local symbol is used, while > > > not defined, just like LLVM does. > > > > I gather you want to avoid a case of an undefined reference making it to > > output for a symbol whose name suggests its a local label, right? > > > > But that seems like material for the generic part of GAS rather than the > > MIPS backend only (and then specifically SVR4 PIC only and not non-PIC or > > VxWorks, according to your code as submitted), so that all targets behave > > consistently, and I can't see e.g. i386 GAS doing it. > > > > So a question raises: what problem are you trying to solve? Can you give > > us a piece of code that you think is handled incorrectly by GAS, and why? > > > > main: > la $4,$hello > > $ mipsel-linux-gnu-as -KPIC tt.s && objdump -dr a.out > > 00000000 <main>: > 0: 8f840000 lw a0,0(gp) > 0: R_MIPS_GOT16 $hello > > In this case, GAS treat $hello as an external symbol, so only a single > R_MIPS_GOT16 is used. So that's indeed a waste of a GOT entry if `$hello' does end up local in the link, but I fail to see it being a problem itself. It's no different from where you have forced an ordinary symbol local via a linker script really: it will have retained its individual GOT entry even though it cannot be preempted anymore and could well use a shared entry with an offset. If you're concerned as to the piece of GAS documentation you quoted, then refer to the paragraph that follows: "Local symbols are defined and used within the assembler, but they are normally not saved in object files. Thus, they are not visible when debugging. You may use the `-L' option (see Section 2.7 [Include Local Symbols], page 26) to retain the local symbols in the object files." -- which clarifies that this is specifically about symbols automatically produced internally by GAS for its own use, e.g. referring to `.' will emit such a symbol. In addition to the prefix described in the previous paragraph they use a non-printable character immediately following so as to make sure they don't clash with a symbol provided by assembly code supplied, cf. LOCAL_LABEL_CHAR. Then symbols supplied by assembly code are interpreted according to their attributes and an undefined symbol is necessarily global. If the supplier of code produced non-compliant code, then the GIGO principle applies, GAS just does what it's been told to, just as will say a C compiler when you use a symbol from a reserved namespace in ordinary user code. Tools must not stand in the way. If you think a warning would be useful here, then I guess that might be acceptable, but as I say that would have to go into a generic part of GAS. Maciej
diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c index 43c12de2c8a..a84b13e1815 100644 --- a/gas/config/tc-mips.c +++ b/gas/config/tc-mips.c @@ -17725,6 +17725,16 @@ pic_need_relax (symbolS *sym) if (symbol_section_p (sym)) return true; + if (strstr (S_GET_NAME (sym), ".L") == S_GET_NAME (sym) + || ((mips_abi == O64_ABI || mips_abi == O32_ABI) + && strstr (S_GET_NAME (sym), "$") == S_GET_NAME (sym))) + { + if (!S_IS_DEFINED (sym)) + as_fatal (_("undefined temporary symbol: %s"), + S_GET_NAME (sym)); + return true; + } + symsec = S_GET_SEGMENT (sym); /* This must duplicate the test in adjust_reloc_syms. */