From patchwork Thu Oct 3 04:29:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 98312 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 28815385DDC0 for ; Thu, 3 Oct 2024 04:29:55 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id E8646385DDE6 for ; Thu, 3 Oct 2024 04:29:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E8646385DDE6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E8646385DDE6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727929767; cv=none; b=Ld8TuHB5CwI1yohQVnEpm33G+ve5CDoOEeC9IsxjFUltW6ANDC1bwilhebKui7FbvC1gEmJRH6+qcQKYdoPKUD30q2SoXrFiZkfesL0QAkuH43ckRFSr0cLZxV6/sOy2w/Qy61tCNSmGNp2H4Je3fOY/VAxHRVfzfe5Jm25SMFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727929767; c=relaxed/simple; bh=BuO57h4oS3IX81LI4U64otSs2JTRqRzFrw8nlKSymT8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=t7UQ3p+VVu7dyr9BveC0FVmN/bYj4EPC3go1wE8FI4BzoSYP/eMsg60yFJCGsaCNo3c4IsyH9gNd0VyWa6+M/i0MvETtaMsEiZp1UYzH0LWM3Wvdqy5RKsebHEE93OlLAMh5Q9A3KFsEL/Cw8YGjrxhiYo30CvaGjaoxsiSWkGY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-20ba8d92af9so2917525ad.3 for ; Wed, 02 Oct 2024 21:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727929763; x=1728534563; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=VEmwU5TkfDlKzdPMud5E4ee8MfO2P7lW/tuSP0PoNDE=; b=R3asBIhgNLPLhs4gseEriGPekjrwpfpSeKEjl2jXCtdSyTjodlFtTUppTj0owX8/5l 3H/Q7H6nZTwTsO9lEItWqTVDNAaHPAByK743vuVAQuXzlyaol8DJ6g8SCFiDMC3xdiU8 A3l+oPCJOv5DQmBryZXWitrDnvmJoFUu8bLnapwLY4nG6Ma95Zy/1sboXnyLvWWgrfAA LQN2UfZPeDWReafg0drdyWENN/ehSW1RJmQiFtJimaSaY1l8cwwR1UBzQ4AwV9SkDrHI rST7ekVySKc+dt2FPVpWlagRwzjCmbqZi1fUDikITqmWxOE+b1lE31Hjl94NCbBmHsUp Byzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727929763; x=1728534563; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VEmwU5TkfDlKzdPMud5E4ee8MfO2P7lW/tuSP0PoNDE=; b=XItqLAKp/j4PJ09zUpfCWr47NH9QcUX8C1OPaQZ2a7RfWoIKT0Xxoyzc+jw53md8KS /mWRqjOg7MjK0T/S3gSKj66utWgDh1X/jaHcchVzzgHBEBCrve+OO3PD2dQDsqsNpb+u cG1FXwpbbVh3O0XB+GJz9oTdF2w2FHGh1aL10PbY6EUvJOTdSyrApMbW41upFGsvuAMv GE8CcMblb0kBlHq9iXoLXoyLGMwti7Q8dUzn+0oHy2ge3VA7GL/s8oiyQoRBB4lKweNF iMS4syFKVQGPRuNBMv2P5MKBRMmzfKhANb1Rm8ZyKUz2CTOL74M94uqmGuMJZPddzVPo MLSA== X-Gm-Message-State: AOJu0YwgoYSgBLsgWNFUsEeCnwtnM5skkO7ky11dfazaZrsM3ylKnu5p CQEXJDl8jKfvd2lC4nhV35/CPCbSUdGYHRJTZbGjSli9b0jytsyqGTgFBA== X-Google-Smtp-Source: AGHT+IFpbQ6LHEz7erGIP6iiEAb/8kEi1UX949465+KGgPKyzDOy82+s3+acjqNqUwFlKNElOJOaQQ== X-Received: by 2002:a17:902:d4cf:b0:202:13ca:d73e with SMTP id d9443c01a7336-20bc5a3ea55mr73840165ad.28.1727929763277; Wed, 02 Oct 2024 21:29:23 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20beead205asm1314185ad.18.2024.10.02.21.29.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 21:29:22 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 6195B11422FC; Thu, 3 Oct 2024 13:59:20 +0930 (ACST) Date: Thu, 3 Oct 2024 13:59:20 +0930 From: Alan Modra To: binutils@sourceware.org Subject: dlltool leading_underscore Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3033.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org This patch tidies dlltool code dealing with adding a leading underscore to generated symbol names. There should be no functional change here, but there could be if we ever have a bfd target with symbol_leading_char something other than '_' or 0. * dlltool.c (leading_underscore): Change from an int to a char*. Update all uses. If neither --leading-underscore or --no=leading-underscore is given, set leading_underscore to a string with first char returned by bfd_get_target_info as the target's symbol underscoring. diff --git a/binutils/dlltool.c b/binutils/dlltool.c index 01d6cf7d392..c7f4b154242 100644 --- a/binutils/dlltool.c +++ b/binutils/dlltool.c @@ -402,11 +402,7 @@ static int dll_name_set_by_exp_name; static int add_indirect = 0; static int add_underscore = 0; static int add_stdcall_underscore = 0; -/* This variable can hold three different values. The value - -1 (default) means that default underscoring should be used, - zero means that no underscoring should be done, and one - indicates that underscoring should be done. */ -static int leading_underscore = -1; +static char *leading_underscore = NULL; static int dontdeltemps = 0; /* TRUE if we should export all symbols. Otherwise, we only export @@ -909,31 +905,13 @@ rvabefore (int mach) static const char * asm_prefix (int mach, const char *name) { - switch (mach) - { - case MARM: - case MTHUMB: - case MARM_INTERWORK: - case MMCORE_BE: - case MMCORE_LE: - case MMCORE_ELF: - case MMCORE_ELF_LE: - case MARM_WINCE: - case MAARCH64: - break; - case M386: - case MX86: - /* Symbol names starting with ? do not have a leading underscore. */ - if ((name && *name == '?') || leading_underscore == 0) - break; - else - return "_"; - default: - /* xgettext:c-format */ - fatal (_("Internal error: Unknown machine type: %d"), mach); - break; - } - return ""; + /* ??? --leading_underscore is only supported on x86. */ + if (!(mach == M386 || mach == MX86)) + return ""; + /* Symbol names starting with ? do not have a leading underscore. */ + if (name && *name == '?') + return ""; + return leading_underscore; } #define ASM_BYTE mtable[machine].how_byte @@ -1500,7 +1478,7 @@ add_excludes (const char *new_excludes) if (*exclude_string == '@') sprintf (new_exclude->string, "%s", exclude_string); else - sprintf (new_exclude->string, "%s%s", !leading_underscore ? "" : "_", + sprintf (new_exclude->string, "%s%s", leading_underscore, exclude_string); new_exclude->next = excludes; excludes = new_exclude; @@ -2150,11 +2128,10 @@ gen_exp_file (void) if (create_compat_implib) fprintf (f, "\t%s\t__imp_%s\n", ASM_GLOBAL, exp->name); fprintf (f, "\t%s\t_imp_%s%s\n", ASM_GLOBAL, - !leading_underscore ? "" : "_", exp->name); + leading_underscore, exp->name); if (create_compat_implib) fprintf (f, "__imp_%s:\n", exp->name); - fprintf (f, "_imp_%s%s:\n", - !leading_underscore ? "" : "_", exp->name); + fprintf (f, "_imp_%s%s:\n", leading_underscore, exp->name); fprintf (f, "\t%s\t%s\n", ASM_LONG, exp->name); } } @@ -3874,10 +3851,10 @@ main (int ac, char **av) add_stdcall_underscore = 1; break; case OPTION_NO_LEADING_UNDERSCORE: - leading_underscore = 0; + leading_underscore = ""; break; case OPTION_LEADING_UNDERSCORE: - leading_underscore = 1; + leading_underscore = "_"; break; case OPTION_IDENTIFY_STRICT: identify_strict = 1; @@ -4008,12 +3985,18 @@ main (int ac, char **av) || strcmp (mname, "arm64") == 0); /* Check the default underscore */ - int u = leading_underscore; /* Underscoring mode. -1 for use default. */ - if (u == -1) - bfd_get_target_info (mtable[machine].how_bfd_target, NULL, - NULL, &u, NULL); - if (u != -1) - leading_underscore = u != 0; + if (leading_underscore == NULL) + { + int u; + static char underscore[2]; + bfd_get_target_info (mtable[machine].how_bfd_target, NULL, + NULL, &u, NULL); + if (u == -1) + u = 0; + underscore[0] = u; + underscore[1] = 0; + leading_underscore = underscore; + } if (!dll_name && exp_name) {