Page 1 of 1

Import asm errno - linker wrong version (purebasic.o?)

Posted: Sat Jan 14, 2023 1:30 pm
by mk-soft
Purebasic Linker Error:
/usr/bin/ld: errno: TLS definition in /lib/x86_64-linux-gnu/libc.so.6 section .tbss mismatches non-TLS reference in purebasic.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: Fehler beim Hinzufügen von Symbolen: bad value
collect2: error: ld returned 1 exit status
Code:

Code: Select all

;-TOP
; By mk-soft, v1.01.1, 08.01.2023
; Not work with ASM (Bug version)

CompilerIf Not Defined(PB_Compiler_Backend, #PB_Constant)
  #PB_Backend_Asm = 0
  #PB_Backend_C = 1
  #PB_Compiler_Backend = 0
CompilerEndIf

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Macro GetLastError()
    GetLastError_()
  EndMacro
CompilerElse
  CompilerIf #PB_Compiler_Backend = #PB_Backend_C
    Procedure GetLastError()
      !#include "errno.h"
      !extern int errno;
      Protected r1
      !v_r1=errno;
      ProcedureReturn r1
    EndProcedure
  CompilerElse
    ImportC ""
      errno
    EndImport
    Procedure GetLastError()
      Protected r1
      r1 = errno
      ProcedureReturn r1
    EndProcedure
  CompilerEndIf
CompilerEndIf

; ----

CompilerIf #PB_Compiler_IsMainFile
  
  err = GetLastError()
  Debug "LastError = " + GetLastError()
  
CompilerEndIf

Re: Import asm errno - linker wrong version (purebasic.o?)

Posted: Sat Jan 21, 2023 6:52 pm
by juergenkulow

Code: Select all

PureBasic 6.01 LTS beta 1 - C Backend (Linux - x64)
Loading external modules...
Loading 'c' subsystem
Starting compilation...
Starting compilation...
43 lines processed.
Creating the executable.
Error: Linker
/usr/bin/ld: purebasic.o: in function `SYS_BankerRound':
purebasic.c:(.text+0x27): undefined reference To `fmod'
/usr/bin/ld: purebasic.o: in function `SYS_BankerRoundQuad':
purebasic.c:(.text+0xcf): undefined reference To `fmod'
collect2: error: ld returned 1 exit status
:?:

Re: Import asm errno - linker wrong version (purebasic.o?)

Posted: Tue Jan 31, 2023 11:26 am
by juergenkulow

Code: Select all

PureBasic 6.01 LTS beta 2 (Linux - x64)
Loading external modules...
Starting compilation...
Starting compilation...
44 lines processed.
Creating the executable.
Error: Linker
/usr/bin/ld: errno: TLS definition in /lib/x86_64-linux-gnu/libc.so.6 section .tbss mismatches non-TLS reference in purebasic.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: Fehler beim Hinzufügen von Symbolen: bad value
collect2: error: ld returned 1 exit status

Re: Import asm errno - linker wrong version (purebasic.o?)

Posted: Sat Jul 27, 2024 5:43 pm
by Fred
As explained here https://stackoverflow.com/questions/339 ... ted-in-c-c , the 'errno' is no more a simple variable on linux anymore as it's a TLS variable. You need to use __errno_location() to access it:

Code: Select all

;-TOP
; By mk-soft, v1.01.1, 08.01.2023
; Not work with ASM (Bug version)

CompilerIf Not Defined(PB_Compiler_Backend, #PB_Constant)
  #PB_Backend_Asm = 0
  #PB_Backend_C = 1
  #PB_Compiler_Backend = 0
CompilerEndIf

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Macro GetLastError()
    GetLastError_()
  EndMacro
CompilerElse
  CompilerIf #PB_Compiler_Backend = #PB_Backend_C
    Procedure GetLastError()
      !#include "errno.h"
      !extern int errno;
      Protected r1
      !v_r1=errno;
      ProcedureReturn r1
    EndProcedure
  CompilerElse
    ImportC ""
      __errno_location()
    EndImport
    Procedure GetLastError()
      Protected r1
      r1 = PeekL(__errno_location())
      ProcedureReturn r1
    EndProcedure
  CompilerEndIf
CompilerEndIf

; ----

CompilerIf #PB_Compiler_IsMainFile
  
  err = GetLastError()
  Debug "LastError = " + GetLastError()
  
CompilerEndIf