From patchwork Fri Sep 15 10:03:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Zissulescu Ianculescu X-Patchwork-Id: 76124 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 01A653857B98 for ; Fri, 15 Sep 2023 10:04:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01A653857B98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694772265; bh=wcKT9r/g3PCb9KOqvd5/iCIGnAHZNfekFcKEwQqdjDs=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=uB6/mgUlwLexmi41C++WkPyjKkAcQ9Bzq11fSwdgjTimOTU72MDebTrpXqKN4BBVi TqeRFHHtgwV7c3QgpI/dce03m34APnVRWokG0V+pT/TFQoaN7zXXMvrbYqSXlIqWOg MkpawYA2ZNAI/6iDS0q2G4cMcB7ldEmr96jrR6d8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id 4300E3858D1E for ; Fri, 15 Sep 2023 10:03:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4300E3858D1E Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2bcb89b476bso32388561fa.1 for ; Fri, 15 Sep 2023 03:03:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694772233; x=1695377033; 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=wcKT9r/g3PCb9KOqvd5/iCIGnAHZNfekFcKEwQqdjDs=; b=nycIxt5UNvWi33OkDb/lWJAMET2ZThS2SMC84kiSFz+6cDBz+XNkezjCVUpb5j+QWx 1+QA8G4qDVkHdPn32IShIg+ANZSwLi6Hq/6XLH0xeDyhSpV+wGaKhEr2GD0ZqzNPZjNH DPziiTuqpOoVDOBiQKAEz4f/9yky6BRBANO/BvB5fhDUyJn+TNXcNLlvjDhDTZ5vlbbp Y6+7zI0/hllfPaT/jcn3K7Ww3WsTKuWQUT+d34Oy0M1ARixV/FUs1bdhcxDkUNUNlLcS ewkXq5munUjWRCTZO0GbngymlS2G6eyMno/l2bC8lZXRTubYgRVQNLvx9MFufmnMF0bF dDLg== X-Gm-Message-State: AOJu0YyQti7INvjMmP25DgMk+GM1ntgVYsKQL9vSPfCzBpp+zGBL4sHY AkFeY5fFL2hnT753Rfkud4wOPvSRF58= X-Google-Smtp-Source: AGHT+IFWJSg4IfDBY9jtlC+YaiPOHpwbZB+Dva81m/s8wlzn9xCdMF/plV9Qp+62necoKSjDsmIkYg== X-Received: by 2002:a05:6512:214a:b0:4fb:9469:d659 with SMTP id s10-20020a056512214a00b004fb9469d659mr884632lfr.23.1694772233090; Fri, 15 Sep 2023 03:03:53 -0700 (PDT) Received: from fatty.nomansland ([193.187.151.25]) by smtp.gmail.com with ESMTPSA id q18-20020a056402519200b00530a0ceb4a0sm255908edd.37.2023.09.15.03.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:03:52 -0700 (PDT) To: binutils@sourceware.org Cc: fbedard@synopsys.com Subject: [committed] arc: Fix alignment of the TLS Translation Control Block Date: Fri, 15 Sep 2023 13:03:49 +0300 Message-Id: <20230915100349.1227137-1-claziss@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 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: , X-Patchwork-Original-From: Claudiu Zissulescu via Binutils From: Claudiu Zissulescu Ianculescu Reply-To: Claudiu Zissulescu Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org Sender: "Binutils" The R_ARC_TLS_LE_32 is defined as S + A + TLS_TBSS - TLS_REL, where - S is the base address of the symbol in the memory - A is the symbol addendum - TLS_TBSS is the TLS Translation Control Block size (aligned) - TLS_REL is the base of the TLS section Given the next code snip: __thread int data_var = 12; __attribute__((__aligned__(128))) __thread int data_var_128 = 128; __thread int bss_var; __attribute__((__aligned__(256))) __thread int bss_var_256; int __start(void) { return data_var + data_var_128 + bss_var + bss_var_256; } The current code returns different TLS_TBSS values for .tdata and .tbss. This patch fixes this by using the linker provided tls_sec. bfd/ * elf32-arc.c (TLS_REL): Clean up. (TLS_TBSS): Use tls_sec alignment. (arc_do_relocation): Check if we have valid tls_sec. Signed-off-by: Claudiu Zissulescu --- bfd/elf32-arc.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c index 78dfd6eebbd..ac9970545c3 100644 --- a/bfd/elf32-arc.c +++ b/bfd/elf32-arc.c @@ -1226,10 +1226,8 @@ arc_special_overflow_checks (const struct arc_relocation_data reloc_data, (bfd_signed_vma) (reloc_data.sym_section->output_section->vma) #define JLI (bfd_signed_vma) (reloc_data.sym_section->output_section->vma) #define _SDA_BASE_ (bfd_signed_vma) (reloc_data.sdata_begin_symbol_vma) -#define TLS_REL (bfd_signed_vma) \ - ((elf_hash_table (info))->tls_sec->output_section->vma) -#define TLS_TBSS (align_power(TCB_SIZE, \ - reloc_data.sym_section->alignment_power)) +#define TLS_REL (bfd_signed_vma)(tls_sec->output_section->vma) +#define TLS_TBSS (align_power (TCB_SIZE, tls_sec->alignment_power)) #define none (0) @@ -1307,6 +1305,7 @@ arc_do_relocation (bfd_byte * contents, bfd * abfd = reloc_data.input_section->owner; struct elf_link_hash_table *htab ATTRIBUTE_UNUSED = elf_hash_table (info); bfd_reloc_status_type flag; + asection *tls_sec = htab->tls_sec; if (!reloc_data.should_relocate) return bfd_reloc_ok; @@ -1336,6 +1335,20 @@ arc_do_relocation (bfd_byte * contents, orig_insn = insn; + /* If we resolve a TLS relocation, make sure we do have a valid TLS + section. */ + switch (reloc_data.howto->type) + { + case R_ARC_TLS_LE_32: + if (tls_sec == NULL) + return bfd_reloc_notsupported; + break; + + default: + break; + } + + switch (reloc_data.howto->type) { #include "elf/arc-reloc.def"