NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: paml27 on April 03, 2020, 10:20:39 PM

Title: Error assembling .so with thread local storage
Post by: paml27 on April 03, 2020, 10:20:39 PM
Following is a simple shared object with thread local storage.  The syntax in the section TLS_Test_fn is taken from section "7.9.4 Thread Local Storage in ELF: elf Special Symbols and WRT" in the NASM 2.13.02 manual (corresponding to the version installed on my Ubuntu 18.04). 

The two lines that that uses the TLS variable are:

   mov rax,[rel MQ_FDes_Core wrt ..gottpoff]
   mov rcx,[fs:rax]

I assemble with NASM assembler:

   sudo nasm -f elf64 -g -F dwarf TLS_Test.asm

and I get:

   "TLS_Test.asm:24: error: unable to find a suitable global symbol for this reference"

If I write it as mov rax,[MQ_FDes_Core wrt ..gottpoff] I get the same error. 

Here is the full code:

   ; Header Section
   [BITS 64]

   [default rel]

   global Main_Entry_fn
   global TLS_Test_fn

   section .data align=16   
   unused_data: dq 0

   section .tdata align=16
   MQ_FDes_Core: dq 0

   ; __________

   section .text


   mov rax,87
   ;mov [MQ_FDes_Core],rax

   mov rax,[rel MQ_FDes_Core wrt ..gottpoff]
   mov rcx,[fs:rax]


   ; __________
   ; Main Entry


   push rdi
   push rbp
   push rbx

   ; __________

   call TLS_Test_fn
   pop rbx
   pop rbp
   pop rdi

The .so entry point is  Main_Entry_fn.

Why do I get that error?