Skip to content

Commit 22b1bf4

Browse files
committed
arc: Fix alignment of the TLS Translation Control Block
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. Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
1 parent 72b0ca9 commit 22b1bf4

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

bfd/elfnn-arc.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,10 +1291,8 @@ arc_special_overflow_checks (const struct arc_relocation_data reloc_data,
12911291
(bfd_signed_vma) (reloc_data.sym_section->output_section->vma)
12921292
#define JLI (bfd_signed_vma) (reloc_data.sym_section->output_section->vma)
12931293
#define _SDA_BASE_ (bfd_signed_vma) (reloc_data.sdata_begin_symbol_vma)
1294-
#define TLS_REL (bfd_signed_vma) \
1295-
((elf_hash_table (info))->tls_sec->output_section->vma)
1296-
#define TLS_TBSS (align_power(TCB_SIZE, \
1297-
reloc_data.sym_section->alignment_power))
1294+
#define TLS_REL (bfd_signed_vma)(tls_sec->output_section->vma)
1295+
#define TLS_TBSS (align_power (TCB_SIZE, tls_sec->alignment_power))
12981296
#define ICARRY insn
12991297
#define DEREFP (insn)
13001298

@@ -1375,6 +1373,7 @@ arc_do_relocation (bfd_byte * contents,
13751373
bfd * abfd = reloc_data.input_section->owner;
13761374
struct elf_link_hash_table *htab ATTRIBUTE_UNUSED = elf_hash_table (info);
13771375
bfd_reloc_status_type flag;
1376+
asection *tls_sec = htab->tls_sec;
13781377

13791378
if (!reloc_data.should_relocate)
13801379
return bfd_reloc_ok;
@@ -1409,6 +1408,19 @@ arc_do_relocation (bfd_byte * contents,
14091408

14101409
orig_insn = insn;
14111410

1411+
/* If we resolve a TLS relocation, make sure we do have a valid TLS
1412+
section. */
1413+
switch (reloc_data.howto->type)
1414+
{
1415+
case R_ARC_TLS_LE_32:
1416+
if (tls_sec == NULL)
1417+
return bfd_reloc_notsupported;
1418+
break;
1419+
1420+
default:
1421+
break;
1422+
}
1423+
14121424
switch (reloc_data.howto->type)
14131425
{
14141426
#include "elf/arc-reloc.def"

0 commit comments

Comments
 (0)