From patchwork Fri Jan 3 03:28:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 854859 Delivered-To: patch@linaro.org Received: by 2002:a5d:4888:0:b0:385:e875:8a9e with SMTP id g8csp8068955wrq; Thu, 2 Jan 2025 19:28:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXQgxnAbEgsZRSrUkxYusx/6m9h+pOfwTrrMXIXbE62n6EHunAax62wGhZtizTCOQPq8tvySw==@linaro.org X-Google-Smtp-Source: AGHT+IGzRHpYQwELQ/ZjU7iKrqVr9ogADixWfkEtzo0s4bdVsc3W9ca70VIFZj9kWCS8YJrpumw8 X-Received: by 2002:a05:620a:1727:b0:7b1:4a48:56bb with SMTP id af79cd13be357-7b9ba833dffmr5889413285a.56.1735874938647; Thu, 02 Jan 2025 19:28:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1735874938; cv=pass; d=google.com; s=arc-20240605; b=cuVzh1u6TzZwIyDVFOJm8iMBMJZV7LZDJJJ6NrPacCqIGqiJwwYetRsE6j+xtLnWFr KQ7strtzyA7QvJHXfHCE6lw6bPnkC/1CvXDjLL7nm6kou9OXz/cV7ZA71afOvp00mVJL CdCnIZqUNlyl97YyLotc2HA/0g8jwwRXI3542LXxtB4jTAC+oLLSXfQr7m9vK9Cxu3Nb c2s1rTe4RBEX6vC8aYBCWQntuuwtFfvpBg9Pw9Fn2dDtVulY19JEVDklz1+4q1bQlBze IeD2AQu2PyDycK+IDmy8hXyt+eh7ZX9CBanoW2+KRLoQVZJ/ojfmsF9n27jBD/xvdQW4 CSAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:dkim-signature :dkim-filter:arc-filter:dmarc-filter:delivered-to:dkim-filter; bh=p+4KVLodMwenxNpAFCRmd7woo3EfS4lrq0YStT7UXY0=; fh=9kWjmlFLaAqw8ciJ/qjQjpjLI0A8k9nz7xJX3R9Mbas=; b=VUxwwOxZe+NqesLGPNFjaVbQ4Undy4gd0ZrGfBpknL2T4coyQHNELJdAA3M2EUIyKu EQ1E8UJ1KTSDPpiktQkWvNDMX1E0DNfQ2c8w8SKTcX2NSyhHrXlDAGOYBW6r1PHHQ3MV 4CnImB8CIK7cLv9S9y27L1oSV+pmKGTA8egKTi2Qn+uL5ySaFPTvAH+/MEgwfbgcYB5J 8QTU49fRZJ9Fh2Uf9ZWUf5ByFGNlZYJCFrhW1IdeURgDMXzT7n00x8K1nDHqnbUuIhdn YNibrOHTw8ETGiiX5IsQPHK6ncv0W0VH2s8szFc/OXPTUaV7yV70447e4XWT8bDXCP7O UoOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=twkQZC0J; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id af79cd13be357-7b9ac4eebb9si3740133785a.473.2025.01.02.19.28.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 19:28:58 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces~patch=linaro.org@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=@linaro.org header.s=google header.b=twkQZC0J; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 364263858C32 for ; Fri, 3 Jan 2025 03:28:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 364263858C32 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=twkQZC0J X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 5E2433858C32 for ; Fri, 3 Jan 2025 03:28:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E2433858C32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5E2433858C32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735874915; cv=none; b=AyziyN5dGfC2ipuBLYExL6CoKaV+cwzummPTzvXOJPbUwjtLnBvlW4f8sPLrYkA6ztKqjMSWzzD/mDBc27Kp0pUR3A7vXAtq7ds0WFUYwBufGiq1FyPMvZa2aPFsM2juMHndPIhAoxQYYFVy7OYecuVC0s/rDB04IcW+GoDrylE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735874915; c=relaxed/simple; bh=0oiZfaQbDB+oCIk0vuxPcA8JtZnii2RlNPFbOSKjE4M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=aAeafqgfufcIsQcFb3y3NYkgiuvCVeIzlvAUAznV8dj0JN5aH6/+0n9xUYH3yoVGZBplreFY+vAu6a9WODlfcW3Jt7t4uUrFC6hNzFrEuYdHFv+RIZXXIOglVyonAWjsoVcHGDv5c3jzL1HTkIz842TAFbr5b/6WzDq6wS0hsMA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E2433858C32 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-216426b0865so160170495ad.0 for ; Thu, 02 Jan 2025 19:28:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735874914; x=1736479714; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=p+4KVLodMwenxNpAFCRmd7woo3EfS4lrq0YStT7UXY0=; b=twkQZC0JlqqOLG4WKnifGBajCJMBqHpYconiEiYN13TVjdPU1mwHrvw71OjLn/CG4d YiJOczU+u9DrPKfxDqaSdYXXiiTh1pUABzGy6hDTJOgzVIFlMtjt3hpj8l8vEgfN5NfH iYejqMQUOPAKKrv3plQVbbf3H+bnxAFlmPEwHRu/40lhspiMV+C5y1/XgFg01D7JiAFb FGJ2QVVfEapylqsYRD3Gpei+Aubryi6u2+VVqcml9s11xE7JCj3YTpvT2lab3S8Vs+rO 0Qn9xw7F/qaF+gpQn5BRVvvgk7dTQ3pgVjihZyxhciCY3zptKHod0nYtXXrBzR4aMEmY dfww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735874914; x=1736479714; 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=p+4KVLodMwenxNpAFCRmd7woo3EfS4lrq0YStT7UXY0=; b=LvD0lIz98rNhNbvJ0nReMJxRQEqmZHapCymw9Fxr7iNJTv4He1ffms5KSYC9GzoytE AC41dOciozmUd+tV5lgOmUAr5APcXF5doxz50GZ7Fs14xp1hKawfzBYFsn+6gA4spQVO /lQLAF+wuabDRXnI8WvvtnlBHEcoUyR3YH36fJOVCO8kJtCZAIOtkdGVu6XIAVQpYmQM j6wKHXIUqocB4FqhBbViJQOT95Bj3rM6TGqgSFw6gwkmuRhR66KgdN6v4STEbrDjhxMy VWZMP55RnOeVrmzhcY1CriVrSNno41p0ly2lOwYrkTyYQBnoyml8gjXahctwsU3SimN7 188g== X-Gm-Message-State: AOJu0YzO7SRaJtKMU3DnzCunmHMX6zwf8sG+wPL5BQH1xaWYxTq8Y6DE za3gJtS1OS9flHiDSwqoq4xuUwxxMW6VG3ZpE9HyF96Db5ZhXDt43+CAF0x/rVR1uLEPPoCsU72 d X-Gm-Gg: ASbGncuwJsgqdoN3KCq4MOVQTnhKCxQKr5D2N6Hl0nRy+mNzMmGU3kSF8mrzTucw1hy 5jbzJ3E8CLLouT9bTGlI478m4FWJjfrroJt93f7Ysx3oQOv9Ogb5hSWokDaDe1NLiPw8fAX+oq+ Lj5oWyuYbkSeNy6yUMkhjXbXcAgsI5R9qIXnLBOHjsQroMJgY1agPfZvLDf/75rTJM0/Ja1kLzB AlL5AicfZXblOOaFUhxqhzg5iBYPllFqMgkZs4eNZszzQ6QM9pc+rvxETwOlaRcgAc= X-Received: by 2002:a05:6a21:9102:b0:1e0:da90:5f1f with SMTP id adf61e73a8af0-1e5e0464d21mr69642716637.16.1735874914368; Thu, 02 Jan 2025 19:28:34 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:e5d2:46dc:efa2:a538]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad90c331sm25186076b3a.196.2025.01.02.19.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 19:28:33 -0800 (PST) From: Thiago Jung Bauermann To: binutils@sourceware.org Cc: Alan Modra , Jan Beulich Subject: [PATCH] gas/ELF: Assume merge entity size of 1 if it's missing Date: Fri, 3 Jan 2025 00:28:31 -0300 Message-ID: <20250103032831.622617-1-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patch=linaro.org@sourceware.org commit d5cbf916be4a ("gas/ELF: also reject merge entity size being zero") made gas stricter when an entity size isn't specified (and thus assumed to be zero). Unfortunately this mistake can happen in 32-bit Arm assembly, where the @ character is the start of a comment. E.g.: .section .rodata.str, "aMS", @progbits, 1 The aforementioned commit actually pointed out a binutils testcase with this problem, as well as a bug in GCC's configure script. Therefore, change the parser to accept the specific case of an absent entsize with "M" and assume 1, as suggested by Alan Modra. With this change, a version of GCC's configure script with the bug recognizes support for section merging: configure:27013: checking assembler for section merging support configure:27022: /path/to/bin/as --fatal-warnings -o conftest.o conftest.s >&5 conftest.s: Assembler messages: conftest.s:1: entity size for SHF_MERGE / SHF_STRINGS not specified. Assuming 1. configure:27025: $? = 0 configure:27036: result: yes PR gas/32491 * gas/config/obj-elf.c (obj_elf_section): Assume entsize of 1 if not specified. * gas/read.c (get_absolute_expression_kind): New function. * gas/read.h (get_absolute_expression_kind): Declare. --- gas/config/obj-elf.c | 15 +++++++++++---- gas/read.c | 21 +++++++++++++++++++++ gas/read.h | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) Also, note that I posted a patch to fix GCC's configure script here: https://inbox.sourceware.org/gcc-patches/20241227214756.1059146-1-thiago.bauermann@linaro.org/ base-commit: f087e2e3f6dece21c5cb6049b4531bf762a3068f diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index c4af01808b6a..d5b558210919 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -1318,15 +1318,22 @@ obj_elf_section (int push) if ((attr & (SHF_MERGE | SHF_STRINGS)) != 0 && *input_line_pointer == ',') { + operatorT kind; + ++input_line_pointer; SKIP_WHITESPACE (); if (inherit && *input_line_pointer == ',' && (bfd_section_flags (now_seg) & (SEC_MERGE | SEC_STRINGS)) != 0) goto fetch_entsize; - entsize = get_absolute_expression (); + entsize = get_absolute_expression_kind (&kind); SKIP_WHITESPACE (); - if (entsize <= 0) + if (kind == O_absent) + { + as_tsktsk (_("entity size for SHF_MERGE / SHF_STRINGS not specified. Assuming 1.")); + entsize = 1; + } + else if (entsize <= 0) { as_warn (_("invalid merge / string entity size")); attr &= ~(SHF_MERGE | SHF_STRINGS); @@ -1342,8 +1349,8 @@ obj_elf_section (int push) } else if ((attr & (SHF_MERGE | SHF_STRINGS)) != 0) { - as_warn (_("entity size for SHF_MERGE / SHF_STRINGS not specified")); - attr &= ~(SHF_MERGE | SHF_STRINGS); + as_tsktsk (_("entity size for SHF_MERGE / SHF_STRINGS not specified. Assuming 1.")); + entsize = 1; } if ((attr & (SHF_MERGE | SHF_STRINGS)) != 0 && type == SHT_NOBITS) diff --git a/gas/read.c b/gas/read.c index 6d0d4b5e31a1..9468277bc609 100644 --- a/gas/read.c +++ b/gas/read.c @@ -45,6 +45,7 @@ #include "ginsn.h" #include +#include #ifndef TC_START_LABEL #define TC_START_LABEL(STR, NUL_CHAR, NEXT_CHAR) (NEXT_CHAR == ':') @@ -569,6 +570,26 @@ get_absolute_expression (void) return get_absolute_expr (&exp); } +/* Return value of absolute expression starting at INPUT_LINE_POINTER and + set KIND to either O_constant, O_absent or O_illegal depending on + whether the expression was constant, absent or something else + entirely. */ + +offsetT +get_absolute_expression_kind (operatorT *kind) +{ + expressionS exp; + offsetT value; + + value = get_absolute_expr (&exp); + if (exp.X_op == O_absent || exp.X_op == O_constant) + *kind = exp.X_op; + else + *kind = O_illegal; + + return value; +} + static int pop_override_ok; static const char *pop_table_name; diff --git a/gas/read.h b/gas/read.h index d11daf13034f..bc236523a89e 100644 --- a/gas/read.h +++ b/gas/read.h @@ -117,6 +117,7 @@ extern char *demand_copy_string (int *lenP); extern char *demand_copy_C_string (int *len_pointer); extern char get_absolute_expression_and_terminator (long *val_pointer); extern offsetT get_absolute_expression (void); +extern offsetT get_absolute_expression_kind (operatorT *kind); extern unsigned int next_char_of_string (void); extern void s_mri_sect (char *); extern char *mri_comment_field (char *);