diff --git a/Makefile b/Makefile index f4b91ebb59..30412c9f49 100644 --- a/Makefile +++ b/Makefile @@ -472,7 +472,7 @@ OPTNEW+=$(OPT) endif ifneq ($(findstring $(OS_TARGET),linux),) ifneq ($(findstring $(CPU_TARGET),i386),) -override OPTNEW+=-CVgeneral +override OPTNEW+=-CVgeneral-dynamic endif endif CLEANOPTS=FPC=$(PPNEW) diff --git a/Makefile.fpc b/Makefile.fpc index 85c458352e..0e621b473b 100644 --- a/Makefile.fpc +++ b/Makefile.fpc @@ -202,7 +202,7 @@ endif # the general threading model when compiling the final versions of rtl and packages ifneq ($(findstring $(OS_TARGET),linux),) ifneq ($(findstring $(CPU_TARGET),i386),) -override OPTNEW+=-CVgeneral +override OPTNEW+=-CVgeneral-dynamic endif endif diff --git a/compiler/arm/cpuelf.pas b/compiler/arm/cpuelf.pas index eef6103769..141b3ce900 100644 --- a/compiler/arm/cpuelf.pas +++ b/compiler/arm/cpuelf.pas @@ -28,7 +28,7 @@ interface implementation uses - globtype,cutils,cclasses, + globtype,globals,cutils,cclasses, verbose, elfbase, systems,aasmbase,ogbase,ogelf,assemble; @@ -335,9 +335,14 @@ implementation result:=R_ARM_THM_CALL; RELOC_GOT32: result:=R_ARM_GOT_BREL; + RELOC_TPOFF: + if current_settings.tlsmodel=tlsm_initial_exec then + result:=R_ARM_TLS_IE32 + else if current_settings.tlsmodel=tlsm_local_exec then + result:=R_ARM_TLS_LE32 + else + Internalerror(2019092901); else - result:=0; - writeln(objrel.typ); InternalError(2012110602); end; end; diff --git a/compiler/globtype.pas b/compiler/globtype.pas index b6c142fb7f..47b1771c37 100644 --- a/compiler/globtype.pas +++ b/compiler/globtype.pas @@ -744,15 +744,22 @@ interface { subroutine uses threadvars } pi_uses_threadvar, { set if the procedure has generated data which shall go in an except table } - pi_has_except_table_data + pi_has_except_table_data, + { subroutine needs to load and maintain a tls register } + pi_needs_tls ); tprocinfoflags=set of tprocinfoflag; ttlsmodel = (tlsm_none, { elf tls model: works for all kind of code and thread vars } - tlsm_general, + tlsm_general_dynamic, + { elf tls model: works only if the thread vars are declared and used in the same module, + regardless when the module is loaded } + tlsm_local_dynamic, + { elf tls model: works only if the thread vars are declared and used in modules and executables loaded at startup } + tlsm_initial_exec, { elf tls model: works only if the thread vars are declared and used in the same executable } - tlsm_local + tlsm_local_exec ); type diff --git a/compiler/i386/cpupi.pas b/compiler/i386/cpupi.pas index 5e660d78f4..b4c3478e3e 100644 --- a/compiler/i386/cpupi.pas +++ b/compiler/i386/cpupi.pas @@ -98,7 +98,7 @@ unit cpupi; procedure tcpuprocinfo.allocate_got_register(list: tasmlist); begin - if (pi_uses_threadvar in flags) and (tf_section_threadvars in target_info.flags) and (current_settings.tlsmodel in [tlsm_general]) then + if (pi_uses_threadvar in flags) and (tf_section_threadvars in target_info.flags) and (current_settings.tlsmodel in [tlsm_general_dynamic]) then begin { FIXME: It is better to use an imaginary register for GOT and if EBX is needed for some reason just allocate EBX and diff --git a/compiler/options.pas b/compiler/options.pas index 39f3fd7369..09c7dad61b 100644 --- a/compiler/options.pas +++ b/compiler/options.pas @@ -1485,10 +1485,10 @@ begin 'V': begin s:=upper(copy(more,j+1,length(more)-j)); - if s='GENERAL' then - init_settings.tlsmodel:=tlsm_general - else if s='LOCAL' then - init_settings.tlsmodel:=tlsm_local + if s='GENERAL-DYNAMIC' then + init_settings.tlsmodel:=tlsm_general_dynamic + else if s='LOCAL-EXEC' then + init_settings.tlsmodel:=tlsm_local_exec else IllegalPara(opt); break; @@ -4155,9 +4155,9 @@ begin if (tf_section_threadvars in target_info.flags) and (init_settings.tlsmodel=tlsm_none) then begin if cs_create_pic in init_settings.moduleswitches then - init_settings.tlsmodel:=tlsm_general + init_settings.tlsmodel:=tlsm_general_dynamic else - init_settings.tlsmodel:=tlsm_local; + init_settings.tlsmodel:=tlsm_local_exec; end; { set Mac OS X version default macros if not specified explicitly } diff --git a/compiler/x86/nx86ld.pas b/compiler/x86/nx86ld.pas index 2ed62ced36..c0e9da0d32 100644 --- a/compiler/x86/nx86ld.pas +++ b/compiler/x86/nx86ld.pas @@ -93,12 +93,12 @@ implementation system_i386_linux,system_i386_android: begin case current_settings.tlsmodel of - tlsm_local: + tlsm_local_exec: begin location.reference.segment:=NR_GS; location.reference.refaddr:=addr_ntpoff; end; - tlsm_general: + tlsm_general_dynamic: begin include(current_procinfo.flags,pi_needs_got); reference_reset(href,0,[]); @@ -127,12 +127,12 @@ implementation system_x86_64_linux: begin case current_settings.tlsmodel of - tlsm_local: + tlsm_local_exec: begin location.reference.segment:=NR_FS; location.reference.refaddr:=addr_tpoff; end; - tlsm_general: + tlsm_general_dynamic: begin current_asmdata.CurrAsmList.concat(tai_const.Create_8bit($66)); reference_reset(href,0,[]);