From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YH7UMxdbXGdfeRUAWB0awg (envelope-from ) for ; Fri, 13 Dec 2024 11:04:39 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=VVc48+E3; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D0F051E097; Fri, 13 Dec 2024 11:04:39 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 1D6D21E091 for ; Fri, 13 Dec 2024 11:04:39 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B9100385842D for ; Fri, 13 Dec 2024 16:04:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9100385842D Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=VVc48+E3 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id 05F1A3858432 for ; Fri, 13 Dec 2024 15:57:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05F1A3858432 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 05F1A3858432 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::533 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734105465; cv=none; b=kRv1WO+ooH2n5zQL5v47TN719JduQEjo6EELom0qdyZNJfFrVhub4BMqQNsjc+jJlMBI/SNy1mgO7RsZ8jgCngmYeDwic5OfSJNFyGoE6muZ3AAZnroClNS7j5WA7L4Pym8lLwGHog/sOVfmzpDN9UuNdx7Ei/3DakNpW1bJF60= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734105465; c=relaxed/simple; bh=OS58a0DwmIGFl3gLof2kp7NgfBjTi9TmXX7IW3besLc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=e24IvE07zEYOO59P4VkBC2aENuyFc3pPlZyNoFIvgs4GE2TT/9D4w8pziT1x1h2lBoSp+Iu0KLVGlNkS/UEPqTvSvaeaf5zdafoc4U32fIcUxXqIO1E9W+3m9v2Hi0U+SRWVaM63QgPn8JKOyuAzuV3YD5t3ozfVDByoVX59uII= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05F1A3858432 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5d0ac27b412so2693164a12.1 for ; Fri, 13 Dec 2024 07:57:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734105463; x=1734710263; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cMVXB2gvf0z4dMmQV9TVdPrGf6gBdlGzYn1dXeHkBpQ=; b=VVc48+E3YMPP3Qf8ZToLpov17qS47AlQL4laeINVeAq1x2fdXZgVm9h2p8EZrlBnOl b9y7YzlPPdrE6Dx8fCpFwgWyaoOiCaiggvGd2t70GVSfOtMR7/xBpPzCZqShUlkHxpuR dzCj3PgxAeT6yYNtvnJGMjM4a//CzEwqZMvrtQYrmNGabpb/v8gVOmx1s/kipvLPVf+z 1lUmLc/jDXEXc2ao4t7PpA3eG2Bo/+BNYGbLva3zCszt7d99yFn8dvrqFVPp3YvmK0vT C9pbvwPLMnIH3Hd0i54HZFXCXLqIF4d3izLr7D8D4E2BIqA8VAavTRWJPNqbR3P1kWdA Vgjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734105463; x=1734710263; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cMVXB2gvf0z4dMmQV9TVdPrGf6gBdlGzYn1dXeHkBpQ=; b=hVgFhww2Rl2DAjMXFBdpBCNPAS3xZQVf5Hlyz2uKPnH//sTOxfNRTfO4jJWgtesvKq Po9QnaV6qmeEIloXjnSHNSmtqoD4QA9loOgmxGLHxAZ1PuIguo6ndhxGAVPhVWDy/uwo rvZYgQc9oEI9Za8y5tYHbRpf5Mifeq2VnaKpchA0ffA9jQdE5ee7iRTqKSrqTQhrSr6r niXNnkjAxtJBtiBGPtfGzSoHnBNWBwCbSgVwfiPl4xak4+FVgi3fZiUBMxiYVhIDmzZ3 FTrcEFOxQZq6uazWjmfm39aMs25k0o2xU3JR755HnI3bQov+XyNXBUEzeDmyRFWx7s3S o0Mg== X-Gm-Message-State: AOJu0YwmuRA3jN4edHbEyrefo22/ND0G3fRByGUCMix6OUqyScZL3gaE B3PFQ9j5Y8nOGtBFKzUDWYmqZWZc6pTz2lnWsd0IYsyMvQ0rL4BslMUeEXA7 X-Gm-Gg: ASbGnctq9rh2DyZWyqOxJ9h/DrGAcNyyOfqL0tKlXUS3nokL+RYhEKVYM5y6rLbRPy8 NLIrNMJC8w0kJv3W/Qw9Ir/dx5bovemIm3QfGYeM98mC4+IoIjB0XUAQ2lRgFGaaEhtMjd5VHCJ wc5gxFbV0ttCKHCTq7dxuTVbzseLVQLLI7CT3cf4EIMGMcopxkqvSUVEwrIQbIZ6Lu68R2nfey9 5alshyq7chXSDuCuhg8PCaZp+s8orSkJiOfiv7vFP35Fx/CFwvrKaDJ71lR9XB2ax9pTCNn X-Google-Smtp-Source: AGHT+IFoEaqTIWyRM+UCgzVOzwXDzfpT2Zmfh4nt2ekwiqcEs+H/j6i+rOiA46E4dUyZnaB0CSV0Jw== X-Received: by 2002:a05:6402:2548:b0:5d3:baa3:29f with SMTP id 4fb4d7f45d1cf-5d63c30afbdmr2527343a12.9.1734105463135; Fri, 13 Dec 2024 07:57:43 -0800 (PST) Received: from SYRN16-0224-L.. ([109.245.202.111]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5d6501d5863sm95355a12.76.2024.12.13.07.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 07:57:42 -0800 (PST) From: Milica Matic X-Google-Original-From: Milica Matic To: gdb-patches@sourceware.org Cc: milica.matic@htecgroup.com, simark@simark.ca, cfu@wavecomp.com, aburgess@redhat.com, kevinb@redhat.com, macro@orcam.me.uk, djordje.todorovic@htecgroup.com, Matthew Fortune , Matthew Fortune , Faraz Shahbazker Subject: [PATCH 07/21] Add --user-defined-sdata-sections Date: Fri, 13 Dec 2024 16:53:14 +0100 Message-Id: <20241213155328.406003-9-milica.matic@htecgroup.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241213155328.406003-1-milica.matic@htecgroup.com> References: <20241213155328.406003-1-milica.matic@htecgroup.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Matthew Fortune This feature has never been used. It was not properly documented at the usual places or tested. Posting the entire documentation that Matthew provided to the customer in to the commit message, for lack of better alternative: Introduction ============ This documentation describes how a user can specify which small data area is used for each data item. This allows different software contexts to use different small data areas. There are three stages: 1. GCC is informed which small data area to use. 2. The linker script places each small data area around a specifically named anchor. 3. System code sets up GP to contain the correct value for each software context. Compiling/Assembling ==================== Automatic data placement ------------------------ The -mgpopt and -G behaviour is modified by the -msdata-num= option to tell the compiler to use a numbered small data area instead of the generic area. can be 0 to 999. e.g. mips-mti-elf-gcc -mgpopt -G4 -msdata-num=4 GP relative addressing will be used for automatically chosen data items as usual. Manual data placement --------------------- The section attribute can be used to place data into a numbered small data section. int a __attribute__((section(".sdata_1"))) = 9; int b __attribute__((section(".sdata_2"))); e.g. mips-mti-elf-gcc -mgpopt -msdata-num= When using the -msdata-num= option then these data items will be accessed via GP relative addressing. This will happen even if the number given to the compiler option does not match the numbered data section in the section attribute. It is the user's responsibility to only access data from one small data area in each software context. If the -msdata-num= option is not given then global addressing will be used for these variables. Manual data placement with a list --------------------------------- The -moptimize-sdata-list= option is modified by the -msdata-num= option to use a numbered small data section for the list of symbols instead of the generic area. e.g. mips-mti-elf-gcc -moptimize-sdata-list=sdata.lst -msdata-num=4 Linking ======= Add the --user-defined-sdata-sections option to the link command to perform multi small data area linking. This will need prefixing with "-Wl," if passed via the 'mips-mti-elf-gcc' compiler driver. The linker script also needs modifying to place the multiple small data sections and define the 'gp' anchors. Each numbered area requires a corresponding numbered anchor defined like this: . = ALIGN(8); _gp_1 = . + 0x8000; .sdata_1 : { *(.sdata_1) *(.sdata_1.*) } . = ALIGN(4); _fsbss_1 = .; .sbss_1 : { *(.sbss_1) *(.sbss_1.*) } . = ALIGN(4); _esbss_1 = .; The range _fsbss_1 to _esbss_1 must be cleared to zero by CRT code similarly to the normal bss area. Runtime ======= System code needs to set the 'gp' register to the correct _gp_ value for each software context. There are no runtime checks to ensure that the correct GP value is used for each data item. Context switching code may need to save/restore GP if contexts running on the same VPE use different areas or contexts migrate between VPEs or cores. Cherry-picked 236e648 from https://github.com/MIPS/binutils-gdb Signed-off-by: Matthew Fortune Signed-off-by: Faraz Shahbazker Signed-off-by: Milica Matic --- bfd/elfxx-mips.c | 58 ++++++++++++++++++++++++++++++++++++++++- bfd/elfxx-mips.h | 2 ++ ld/emultempl/mipself.em | 23 ++++++++++++++++ ld/ldlex.h | 2 ++ 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 6345e782776..a895d08e009 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -464,6 +464,12 @@ struct mips_elf_link_hash_table /* True if we are targetting R6 compact branches. */ bool compact_branches; + /* When True and processing a gp relative relocation against a symbol + in a .sdata_/.sbss_ section use the gp value + based on the address of the _gp_ symbol where is + the number of the .sbss/.sdata section the symbol is in. */ + bool user_def_sdata_sections; + /* True if we're generating code for VxWorks. */ bool is_vxworks; @@ -606,6 +612,8 @@ struct mips_elf_obj_tdata asection *elf_data_section; asection *elf_text_section; + bfd_signed_vma sdata_section[1000]; + struct mips_hi16 *mips_hi16_list; }; @@ -5604,6 +5612,7 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd, struct mips_elf_link_hash_table *htab; bfd *dynobj; bool resolved_to_zero; + int gp_sec_num = 0; dynobj = elf_hash_table (info)->dynobj; htab = mips_elf_hash_table (info); @@ -6000,6 +6009,27 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd, if (gnu_local_gp_p) symbol = gp; + if (mips_elf_hash_table (info)->user_def_sdata_sections && sec != NULL) + { + if (strncmp (".sdata_", sec->name, 7) == 0) + gp_sec_num = atoi (&sec->name[7]); + else if (strncmp (".sbss_", sec->name, 6) == 0) + gp_sec_num = atoi (&sec->name[6]); + + if (gp_sec_num) + { + if (gp_sec_num < 0 || gp_sec_num > 999 + || mips_elf_tdata(abfd)->sdata_section[gp_sec_num] == -1) + { + (*_bfd_error_handler) + (_("%pB: Error: Unable to apply gp relocation to section `%s'"), + abfd, sec->name); + bfd_set_error (bfd_error_bad_value); + } + } + + gp = mips_elf_tdata(abfd)->sdata_section[gp_sec_num]; + } /* Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST. */ @@ -7597,7 +7627,8 @@ _bfd_mips_elf_section_processing (bfd *abfd, Elf_Internal_Shdr *hdr) on it in an input file will be followed. */ if (strcmp (name, ".sdata") == 0 || strcmp (name, ".lit8") == 0 - || strcmp (name, ".lit4") == 0) + || strcmp (name, ".lit4") == 0 + || strncmp (name, ".sdata_", 7) == 0) hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL; else if (strcmp (name, ".srdata") == 0) hdr->sh_flags |= SHF_ALLOC | SHF_MIPS_GPREL; @@ -7889,7 +7920,9 @@ _bfd_mips_elf_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec) else if (strcmp (name, ".got") == 0 || strcmp (name, ".srdata") == 0 || strcmp (name, ".sdata") == 0 + || strncmp (name, ".sdata_", 7) == 0 || strcmp (name, ".sbss") == 0 + || strncmp (name, ".sbss_", 6) == 0 || strcmp (name, ".lit4") == 0 || strcmp (name, ".lit8") == 0) hdr->sh_flags |= SHF_MIPS_GPREL; @@ -14832,6 +14865,12 @@ _bfd_mips_elf_compact_branches (struct bfd_link_info *info, bool on) mips_elf_hash_table (info)->compact_branches = on; } +void +_bfd_mips_elf_user_def_sdata_sections (struct bfd_link_info *info, bool on) +{ + mips_elf_hash_table (info)->user_def_sdata_sections = on; +} + /* Structure for saying that BFD machine EXTENSION extends BASE. */ @@ -15182,6 +15221,23 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info) if (hti.error) return false; + unsigned int gp_num; + for (gp_num = 0 ; gp_num < 1000 ; gp_num++) + { + struct bfd_link_hash_entry *h; + char gp_name[8]; + bfd_signed_vma gp_vma = -1; + + sprintf (gp_name, "_gp_%d", gp_num); + h = bfd_link_hash_lookup (info->hash, gp_name, false, false, true); + if (h != NULL && h->type == bfd_link_hash_defined) + gp_vma = (h->u.def.value + + h->u.def.section->output_section->vma + + h->u.def.section->output_offset); + + mips_elf_tdata(abfd)->sdata_section[gp_num] = gp_vma; + } + /* Get a value for the GP register. */ if (elf_gp (abfd) == 0) { diff --git a/bfd/elfxx-mips.h b/bfd/elfxx-mips.h index 85fb3da78f8..6e5843b565b 100644 --- a/bfd/elfxx-mips.h +++ b/bfd/elfxx-mips.h @@ -171,6 +171,8 @@ extern void _bfd_mips_elf_linker_flags (struct bfd_link_info *, bool, bool, bool); extern void _bfd_mips_elf_compact_branches (struct bfd_link_info *, bool); +extern void _bfd_mips_elf_user_def_sdata_sections + (struct bfd_link_info *, bool); extern bool _bfd_mips_elf_init_stubs (struct bfd_link_info *, asection *(*) (const char *, asection *, asection *)); diff --git a/ld/emultempl/mipself.em b/ld/emultempl/mipself.em index 3259f654b36..b9bea3756b2 100644 --- a/ld/emultempl/mipself.em +++ b/ld/emultempl/mipself.em @@ -45,6 +45,7 @@ static bfd *stub_bfd; static bool insn32; static bool ignore_branch_isa; static bool compact_branches; +static bool user_def_sdata_sections; struct hook_stub_info { @@ -204,6 +205,7 @@ mips_create_output_section_statements (void) if (is_mips_elf (link_info.output_bfd)) { _bfd_mips_elf_compact_branches (&link_info, compact_branches); + _bfd_mips_elf_user_def_sdata_sections (&link_info, user_def_sdata_sections); _bfd_mips_elf_init_stubs (&link_info, mips_add_stub_section); } } @@ -239,6 +241,8 @@ PARSE_AND_LIST_LONGOPTS=' { "no-ignore-branch-isa", no_argument, NULL, OPTION_NO_IGNORE_BRANCH_ISA }, { "compact-branches", no_argument, NULL, OPTION_COMPACT_BRANCHES }, { "no-compact-branches", no_argument, NULL, OPTION_NO_COMPACT_BRANCHES }, + { "user-defined-sdata-sections", no_argument, NULL, OPTION_USER_DEF_SDATA_SECTIONS }, + { "no-user-defined-sdata-sections", no_argument, NULL, OPTION_NO_USER_DEF_SDATA_SECTIONS }, ' PARSE_AND_LIST_OPTIONS=' @@ -262,6 +266,17 @@ PARSE_AND_LIST_OPTIONS=' fprintf (file, _("\ --no-compact-branches Generate delay slot branches/jumps for MIPS R6\n" )); + fprintf (file, _("\ + --user-defined-sdata-sections\n\ + When processing a gp relative relocation against a symbol\n\ + in a .sdata_/.sbss_ section use the gp value\n\ + based on the address of the _gp_ symbol where is\n\ + the number of the .sbss/.sdata section the symbol is in\n")); + fprintf (file, _("\ + --no-user-defined-sdata-sections\n\ + When processing a gp relative relocation against a symbol\n\ + in a .sdata_/.sbss_ section use the gp value\n\ + based on the address of the _gp symbol\n")); ' PARSE_AND_LIST_ARGS_CASES=' @@ -288,6 +303,14 @@ PARSE_AND_LIST_ARGS_CASES=' case OPTION_NO_COMPACT_BRANCHES: compact_branches = false; break; + + case OPTION_USER_DEF_SDATA_SECTIONS: + user_def_sdata_sections = true; + break; + + case OPTION_NO_USER_DEF_SDATA_SECTIONS: + user_def_sdata_sections = false; + break; ' LDEMUL_BEFORE_ALLOCATION=mips_before_allocation diff --git a/ld/ldlex.h b/ld/ldlex.h index bb431101fb2..c86352553bf 100644 --- a/ld/ldlex.h +++ b/ld/ldlex.h @@ -306,6 +306,8 @@ enum option_values OPTION_NO_IGNORE_BRANCH_ISA, OPTION_COMPACT_BRANCHES, OPTION_NO_COMPACT_BRANCHES, + OPTION_USER_DEF_SDATA_SECTIONS, + OPTION_NO_USER_DEF_SDATA_SECTIONS, /* Used by emultempl/msp430.em. */ OPTION_CODE_REGION, OPTION_DATA_REGION, -- 2.34.1