Forráskód Böngészése

* on Mach-O, PECOFF and ELF platforms, write local symbols as hidden/
private_extern (or plain global in case of PECOFF, as the effect is
the same there): visible across object files, but they become local
when linked into a binary/library. This enables cross-unit inlining
of functions accessig implementation-only symbols.

git-svn-id: trunk@42340 -

Jonas Maebe 6 éve
szülő
commit
3fee990218

+ 1 - 1
compiler/aarch64/hlcgcpu.pas

@@ -161,7 +161,7 @@ implementation
       if make_global then
         list.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
       else
-        list.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0,procdef));
+        list.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
 
       { set param1 interface to self  }
       procdef.init_paraloc_info(callerside);

+ 4 - 2
compiler/aasmbase.pas

@@ -39,8 +39,10 @@ interface
     type
        TAsmsymbind=(
          AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL,AB_WEAK_EXTERNAL,
-         { global in the current program/library, but not visible outside it }
-         AB_PRIVATE_EXTERN,AB_LAZY,AB_IMPORT,
+         { global in the current program/library, but not visible outside it
+           (= "hidden" in ELF) }
+         AB_PRIVATE_EXTERN,
+         AB_LAZY,AB_IMPORT,
          { a symbol that's internal to the compiler and used as a temp }
          AB_TEMP,
          { a global symbol that points to another global symbol and is only used

+ 33 - 0
compiler/aasmtai.pas

@@ -551,6 +551,7 @@ interface
           constructor Create_Global(_sym:tasmsymbol;siz:longint);
           constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
           constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
+          constructor Createname_hidden(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
           constructor Createname_global_value(const _name : string;_symtyp:Tasmsymtype;siz:longint;val:ptruint;def:tdef);
           constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
@@ -634,6 +635,7 @@ interface
           sym       : tasmsymbol;
           size      : asizeint;
           constructor Create(const _name : string;_size : asizeint; def: tdef);
+          constructor Create_hidden(const _name : string;_size : asizeint; def: tdef);
           constructor Create_global(const _name : string;_size : asizeint; def: tdef);
           constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
@@ -1289,6 +1291,23 @@ implementation
          is_global:=false;
       end;
 
+    constructor tai_datablock.Create_hidden(const _name: string; _size: asizeint; def: tdef);
+      begin
+        if tf_supports_hidden_symbols in target_info.flags then
+          begin
+            inherited Create;
+            typ:=ait_datablock;
+            sym:=current_asmdata.DefineAsmSymbol(_name,AB_PRIVATE_EXTERN,AT_DATA,def);
+            { keep things aligned }
+            if _size<=0 then
+              _size:=sizeof(aint);
+            size:=_size;
+            is_global:=true;
+          end
+        else
+          Create(_name,_size,def);
+      end;
+
 
     constructor tai_datablock.Create_global(const _name : string;_size : asizeint; def: tdef);
       begin
@@ -1377,6 +1396,20 @@ implementation
          is_global:=true;
       end;
 
+    constructor tai_symbol.Createname_hidden(const _name: string; _symtyp: Tasmsymtype; siz: longint; def: tdef);
+      begin
+        if tf_supports_hidden_symbols in target_info.flags then
+          begin
+            inherited Create;
+            typ:=ait_symbol;
+            sym:=current_asmdata.DefineAsmSymbol(_name,AB_PRIVATE_EXTERN,_symtyp,def);
+            size:=siz;
+            is_global:=true;
+          end
+        else
+          Createname(_name, _symtyp, siz, def);
+      end;
+
 
     constructor tai_symbol.createname_global_value(const _name: string;_symtyp: tasmsymtype; siz: longint; val: ptruint;def:tdef);
       begin

+ 31 - 9
compiler/aggas.pas

@@ -55,6 +55,7 @@ interface
         procedure WriteExtraFooter;virtual;
         procedure WriteInstruction(hp: tai);
         procedure WriteWeakSymbolRef(s: tasmsymbol); virtual;
+        procedure WriteHiddenSymbol(sym: TAsmSymbol);
         procedure WriteAixStringConst(hp: tai_string);
         procedure WriteAixIntConst(hp: tai_const);
         procedure WriteUnalignedIntConst(hp: tai_const);
@@ -835,8 +836,11 @@ implementation
                      processes). The alternate code creates some kind of common symbols
                      in the data segment.
                    }
+
                    if tai_datablock(hp).is_global then
                      begin
+                       if tai_datablock(hp).sym.bind=AB_PRIVATE_EXTERN then
+                         WriteHiddenSymbol(tai_datablock(hp).sym);
                        writer.AsmWrite('.globl ');
                        writer.AsmWriteln(tai_datablock(hp).sym.name);
                        writer.AsmWriteln('.data');
@@ -915,6 +919,8 @@ implementation
                      begin
                        if Tai_datablock(hp).is_global then
                          begin
+                           if (tai_datablock(hp).sym.bind=AB_PRIVATE_EXTERN) then
+                             WriteHiddenSymbol(tai_datablock(hp).sym);
                            writer.AsmWrite(#9'.globl ');
                            if replaceforbidden then
                              writer.AsmWriteln(ReplaceForbiddenAsmSymbolChars(Tai_datablock(hp).sym.name))
@@ -1215,14 +1221,6 @@ implementation
 
            ait_symbol :
              begin
-               if (tai_symbol(hp).sym.bind=AB_PRIVATE_EXTERN) then
-                 begin
-                   writer.AsmWrite(#9'.private_extern ');
-                   if replaceforbidden then
-                     writer.AsmWriteln(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name))
-                   else
-                     writer.AsmWriteln(tai_symbol(hp).sym.name);
-                 end;
                if (target_info.system=system_powerpc64_linux) and
                   (tai_symbol(hp).sym.typ=AT_FUNCTION) and
                   (cs_profile in current_settings.moduleswitches) then
@@ -1235,6 +1233,8 @@ implementation
                     writer.AsmWriteln(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name))
                   else
                     writer.AsmWriteln(tai_symbol(hp).sym.name);
+                  if (tai_symbol(hp).sym.bind=AB_PRIVATE_EXTERN) then
+                    WriteHiddenSymbol(tai_symbol(hp).sym);
                 end;
                if (target_info.system=system_powerpc64_linux) and
                   use_dotted_functions and
@@ -1508,7 +1508,29 @@ implementation
 
     procedure TGNUAssembler.WriteWeakSymbolRef(s: tasmsymbol);
       begin
-        writer.AsmWriteLn(#9'.weak '+s.name);
+        writer.AsmWrite(#9'.weak ');
+        if asminfo^.dollarsign='$' then
+          writer.AsmWriteLn(s.name)
+        else
+          writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(s.name))
+      end;
+
+
+    procedure TGNUAssembler.WriteHiddenSymbol(sym: TAsmSymbol);
+      begin
+        { on Windows/(PE)COFF, global symbols are hidden by default: global
+          symbols that are not explicitly exported from an executable/library,
+          become hidden }
+        if target_info.system in systems_windows then
+          exit;
+        if target_info.system in systems_darwin then
+          writer.AsmWrite(#9'.private_extern ')
+        else
+          writer.AsmWrite(#9'.hidden ');
+        if asminfo^.dollarsign='$' then
+          writer.AsmWriteLn(sym.name)
+        else
+          writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(sym.name))
       end;
 
 

+ 1 - 1
compiler/arm/hlcgcpu.pas

@@ -177,7 +177,7 @@ implementation
       if make_global then
         list.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
       else
-        list.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0,procdef));
+        list.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
 
       { the wrapper might need aktlocaldata for the additional data to
         load the constant }

+ 19 - 0
compiler/elfbase.pas

@@ -140,6 +140,11 @@ interface
     STT_TLS     = 6;
     STT_GNU_IFUNC = 10;
 
+    STV_DEFAULT = 0;
+    STV_INTERNAL = 1;
+    STV_HIDDEN = 2;
+    STV_PROTECTED = 3;
+
     { program header types }
     PT_NULL     = 0;
     PT_LOAD     = 1;
@@ -435,6 +440,9 @@ interface
     procedure MaybeSwapElfverneed(var h: TElfverneed);
     procedure MaybeSwapElfvernaux(var h: TElfvernaux);
 
+    function GetElfSymbolVisibility(other: byte): byte; inline;
+    procedure SetElfSymbolVisibility(var other: byte; vis: byte); inline;
+
 implementation
 
     uses
@@ -682,4 +690,15 @@ implementation
             end;
       end;
 
+
+    function GetElfSymbolVisibility(other: byte): byte; inline;
+      begin
+        result:=other and 3;
+      end;
+
+    procedure SetElfSymbolVisibility(var other: byte; vis: byte);
+      begin
+        other:=(other and not(3)) or vis;
+      end;
+
 end.

+ 3 - 3
compiler/hlcgobj.pas

@@ -3935,7 +3935,7 @@ implementation
         end
       else
         begin
-          sym:=current_asmdata.DefineAsmSymbol(wrappername,AB_LOCAL,AT_FUNCTION,procdef);
+          sym:=current_asmdata.DefineAsmSymbol(wrappername,AB_PRIVATE_EXTERN,AT_FUNCTION,procdef);
           list.concat(Tai_symbol.Create(sym,0));
         end;
       a_jmp_external_name(list,externalname);
@@ -4620,7 +4620,7 @@ implementation
               else
                 begin
                   list.concat(tai_symbolpair.create(spk_set,item.str,firstitem.str));
-                  current_asmdata.DefineAsmSymbol(item.str,AB_LOCAL,AT_FUNCTION,current_procinfo.procdef);
+                  current_asmdata.DefineAsmSymbol(item.str,AB_PRIVATE_EXTERN,AT_FUNCTION,current_procinfo.procdef);
                 end;
             end
           else
@@ -4628,7 +4628,7 @@ implementation
               if global then
                 list.concat(Tai_symbol.createname_global(item.str,AT_FUNCTION,0,current_procinfo.procdef))
               else
-                list.concat(Tai_symbol.createname(item.str,AT_FUNCTION,0,current_procinfo.procdef));
+                list.concat(Tai_symbol.Createname_hidden(item.str,AT_FUNCTION,0,current_procinfo.procdef));
               if not(af_stabs_use_function_absolute_addresses in target_asm.flags) then
                 list.concat(Tai_function_name.create(item.str));
             end;

+ 1 - 1
compiler/i386/hlcgcpu.pas

@@ -394,7 +394,7 @@ implementation
       if make_global then
         List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
       else
-        List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0,procdef));
+        List.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
 
       { set param1 interface to self  }
       g_adjust_self_value(list,procdef,ioffset);

+ 1 - 1
compiler/i8086/hlcgcpu.pas

@@ -599,7 +599,7 @@ implementation
       if make_global then
         List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
       else
-        List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0,procdef));
+        List.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
 
       { set param1 interface to self  }
       g_adjust_self_value(list,procdef,ioffset);

+ 2 - 0
compiler/llvm/nllvmutil.pas

@@ -63,6 +63,8 @@ implementation
     begin
       if sym.globalasmsym then
         asmsym:=current_asmdata.DefineAsmSymbol(sym.mangledname,AB_GLOBAL,AT_DATA,sym.vardef)
+      else if tf_supports_hidden_symbols in target_info.flags then
+        asmsym:=current_asmdata.DefineAsmSymbol(sym.mangledname,AB_PRIVATE_EXTERN,AT_DATA,sym.vardef)
       else
         asmsym:=current_asmdata.DefineAsmSymbol(sym.mangledname,AB_LOCAL,AT_DATA,sym.vardef);
       if not(vo_is_thread_var in sym.varoptions) then

+ 1 - 1
compiler/m68k/hlcgcpu.pas

@@ -212,7 +212,7 @@ implementation
       if make_global then
         List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
       else
-        List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0,procdef));
+        List.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
 
       { set param1 interface to self  }
       g_adjust_self_value(list,procdef,ioffset);

+ 1 - 1
compiler/mips/hlcgcpu.pas

@@ -204,7 +204,7 @@ implementation
     if make_global then
       List.concat(Tai_symbol.Createname_global(labelname, AT_FUNCTION, 0, procdef))
     else
-      List.concat(Tai_symbol.Createname(labelname, AT_FUNCTION, 0, procdef));
+      List.concat(Tai_symbol.Createname_hidden(labelname, AT_FUNCTION, 0, procdef));
 
     IsVirtual:=(po_virtualmethod in procdef.procoptions) and
         not is_objectpascal_helper(procdef.struct);

+ 3 - 2
compiler/ncal.pas

@@ -4253,11 +4253,12 @@ implementation
             st:=procdefinition.owner;
             while (st.symtabletype in [ObjectSymtable,recordsymtable]) do
               st:=st.defowner.owner;
-            if (pi_uses_static_symtable in tprocdef(procdefinition).inlininginfo^.flags) and
+            if not(tf_supports_hidden_symbols in target_info.flags) and
+               (pi_uses_static_symtable in tprocdef(procdefinition).inlininginfo^.flags) and
                (st.symtabletype=globalsymtable) and
                (not st.iscurrentunit) then
               begin
-                Comment(V_lineinfo+V_Debug,'Not inlining "'+tprocdef(procdefinition).procsym.realname+'", references static symtable');
+                Comment(V_lineinfo+V_Debug,'Not inlining "'+tprocdef(procdefinition).procsym.realname+'", references private symbols from other unit');
                 exclude(callnodeflags,cnf_do_inline);
               end;
             para:=tcallparanode(parameters);

+ 2 - 0
compiler/ncgutil.pas

@@ -699,6 +699,8 @@ implementation
             if (cs_profile in current_settings.moduleswitches) or
                (po_global in current_procinfo.procdef.procoptions) then
               current_asmdata.DefineAsmSymbol(item.str,AB_GLOBAL,AT_FUNCTION,pd)
+            else if tf_supports_hidden_symbols in target_info.flags then
+              current_asmdata.DefineAsmSymbol(item.str,AB_PRIVATE_EXTERN,AT_FUNCTION,pd)
             else
               current_asmdata.DefineAsmSymbol(item.str,AB_LOCAL,AT_FUNCTION,pd);
            item := TCmdStrListItem(item.next);

+ 1 - 1
compiler/ngenutil.pas

@@ -873,7 +873,7 @@ implementation
           list.concat(Tai_datablock.create_global(sym.mangledname,size,sym.vardef));
         end
       else
-        list.concat(Tai_datablock.create(sym.mangledname,size,sym.vardef));
+        list.concat(Tai_datablock.create_hidden(sym.mangledname,size,sym.vardef));
     end;
 
 

+ 2 - 0
compiler/ngtcon.pas

@@ -1133,6 +1133,8 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
               addstabx:=true;
             asmsym:=current_asmdata.DefineAsmSymbol(fsym.mangledname,AB_GLOBAL,AT_DATA,tcsym.vardef)
           end
+        else if tf_supports_hidden_symbols in target_info.flags then
+          asmsym:=current_asmdata.DefineAsmSymbol(fsym.mangledname,AB_PRIVATE_EXTERN,AT_DATA,tcsym.vardef)
         else
           asmsym:=current_asmdata.DefineAsmSymbol(fsym.mangledname,AB_LOCAL,AT_DATA,tcsym.vardef);
         if vo_has_section in fsym.varoptions then

+ 9 - 4
compiler/ogbase.pas

@@ -789,7 +789,7 @@ implementation
 
     procedure TObjSymbol.SetAddress(apass:byte;aobjsec:TObjSection;abind:TAsmsymbind;atyp:Tasmsymtype);
       begin
-        if not(abind in [AB_GLOBAL,AB_LOCAL,AB_COMMON,AB_IMPORT]) then
+        if not(abind in [AB_GLOBAL,AB_PRIVATE_EXTERN,AB_LOCAL,AB_COMMON,AB_IMPORT]) then
           internalerror(200603016);
         if not assigned(aobjsec) then
           internalerror(200603017);
@@ -1608,7 +1608,7 @@ implementation
       begin
         { export globals and common symbols, this is needed
           for .a files }
-        if p.bind in [AB_GLOBAL,AB_COMMON] then
+        if p.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN,AB_COMMON] then
          FWriter.writesym(p.name);
       end;
 
@@ -2478,7 +2478,7 @@ implementation
           for j:=0 to ObjData.ObjSymbolList.Count-1 do
             begin
               objsym:=TObjSymbol(ObjData.ObjSymbolList[j]);
-              { From the local symbols we are only interressed in the
+              { From the local symbols we are only interessed in the
                 VTENTRY and VTINHERIT symbols }
               if objsym.bind=AB_LOCAL then
                 begin
@@ -2534,7 +2534,8 @@ implementation
                 end;
               objsym.ExeSymbol:=exesym;
               case objsym.bind of
-                AB_GLOBAL :
+                AB_GLOBAL,
+                AB_PRIVATE_EXTERN:
                   begin
                     if exesym.State<>symstate_defined then
                       begin
@@ -2580,6 +2581,10 @@ implementation
                       else
                         { specific error if ComDat flags are different? }
                         Message1(link_e_duplicate_symbol,objsym.name);
+
+                    { hidden symbols must become local symbols in the executable }
+                    if objsym.bind=AB_PRIVATE_EXTERN then
+                      objsym.bind:=AB_LOCAL;
                   end;
                 AB_EXTERNAL :
                   begin

+ 2 - 1
compiler/ogcoff.pas

@@ -1491,7 +1491,8 @@ const pemagic : array[0..3] of byte = (
                if (objsym.bind=AB_LOCAL) then
                  continue;
                case objsym.bind of
-                 AB_GLOBAL :
+                 AB_GLOBAL,
+                 AB_PRIVATE_EXTERN:
                    begin
                      globalval:=COFF_SYM_GLOBAL;
                      sectionval:=objsym.objsection.index;

+ 11 - 1
compiler/ogelf.pas

@@ -742,7 +742,10 @@ implementation
         if objsym.ThumbFunc then
           inc(elfsym.st_value);
 {$endif ARM}
-
+        { hidden symbols should have been converted to local symbols in
+          the linking pass in case we're writing an exe/library; don't
+          convert them to local here as well, as that would potentially
+          hide a bug there. }
         case objsym.bind of
           AB_LOCAL :
             begin
@@ -761,6 +764,11 @@ implementation
             elfsym.st_info:=STB_WEAK shl 4;
           AB_GLOBAL :
             elfsym.st_info:=STB_GLOBAL shl 4;
+          AB_PRIVATE_EXTERN :
+            begin
+              elfsym.st_info:=STB_GLOBAL shl 4;
+              SetElfSymbolVisibility(elfsym.st_other,STV_HIDDEN);
+            end
         else
           InternalError(2012111801);
         end;
@@ -1187,6 +1195,8 @@ implementation
                 STB_GLOBAL:
                   if sym.st_shndx=SHN_UNDEF then
                     bind:=AB_EXTERNAL
+                  else if GetElfSymbolVisibility(sym.st_other)=STV_HIDDEN then
+                    bind:=AB_PRIVATE_EXTERN
                   else
                     bind:=AB_GLOBAL;
                 STB_WEAK:

+ 1 - 1
compiler/ppcgen/hlcgppc.pas

@@ -165,7 +165,7 @@ implementation
       if make_global then
         List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
       else
-        List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0,procdef));
+        List.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
 
       { set param1 interface to self  }
       g_adjust_self_value(list,procdef,ioffset);

+ 2 - 0
compiler/psub.pas

@@ -2587,6 +2587,8 @@ implementation
              if (po_global in pd.procoptions) or
                 (cs_profile in current_settings.moduleswitches) then
                current_asmdata.DefineAsmSymbol(pd.mangledname,AB_GLOBAL,AT_FUNCTION,pd)
+             else if tf_supports_hidden_symbols in target_info.flags then
+               current_asmdata.DefineAsmSymbol(pd.mangledname,AB_PRIVATE_EXTERN,AT_FUNCTION,pd)
              else
                current_asmdata.DefineAsmSymbol(pd.mangledname,AB_LOCAL,AT_FUNCTION,pd);
            end;

+ 1 - 1
compiler/riscv/hlcgrv.pas

@@ -152,7 +152,7 @@ implementation
       if make_global then
         list.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,voidcodepointertype))
       else
-        list.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0,voidcodepointertype));
+        list.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,voidcodepointertype));
 
       { the wrapper might need aktlocaldata for the additional data to
         load the constant }

+ 1 - 1
compiler/sparcgen/hlcgcpu.pas

@@ -76,7 +76,7 @@ implementation
       if make_global then
         List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
       else
-        List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0,procdef));
+        List.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
 
       { set param1 interface to self  }
       procdef.init_paraloc_info(callerside);

+ 3 - 1
compiler/systems.pas

@@ -171,7 +171,9 @@ interface
             { use high level cfi directives to generate call frame information }
             tf_use_hlcfi,
             { supports symbol order file (to ensure symbols in vectorised sections are kept in the correct order) }
-            tf_supports_symbolorderfile
+            tf_supports_symbolorderfile,
+            { supports hidden/private extern symbols: visible across object files, but local/private in exe/library }
+            tf_supports_hidden_symbols
        );
 
        psysteminfo = ^tsysteminfo;

+ 5 - 5
compiler/systems/i_android.pas

@@ -37,7 +37,7 @@ unit i_android;
             flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
                             tf_requires_proper_alignment, tf_safecall_exceptions,
                             tf_pic_uses_got, tf_pic_default,
-                            tf_smartlink_sections,tf_has_winlike_resources];
+                            tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_arm;
             unit_env     : 'ANDROIDUNITS';
             extradefines : 'UNIX;HASUNIX;CPUARMEL';
@@ -106,7 +106,7 @@ unit i_android;
             flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
                             tf_needs_dwarf_cfi,tf_has_winlike_resources,
                             tf_pic_uses_got, tf_pic_default, tf_smartlink_sections,
-                            tf_safecall_exceptions];
+                            tf_safecall_exceptions,tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'ANDROIDUNITS';
             extradefines : 'UNIX;HASUNIX';
@@ -175,7 +175,7 @@ unit i_android;
              flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
                              tf_requires_proper_alignment, tf_safecall_exceptions,
                              tf_pic_uses_got, tf_pic_default,
-                             tf_smartlink_sections,tf_has_winlike_resources];
+                             tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
              cpu          : cpu_aarch64;
              unit_env     : 'ANDROIDUNITS';
              extradefines : 'UNIX;HASUNIX';
@@ -244,7 +244,7 @@ unit i_android;
              flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
                              tf_needs_dwarf_cfi,tf_has_winlike_resources,
                              {tf_pic_uses_got,} tf_pic_default, tf_smartlink_sections,
-                             tf_safecall_exceptions, tf_safecall_clearstack];
+                             tf_safecall_exceptions, tf_safecall_clearstack,tf_supports_hidden_symbols];
              cpu          : cpu_x86_64;
              unit_env     : 'ANDROIDUNITS';
              extradefines : 'UNIX;HASUNIX';
@@ -312,7 +312,7 @@ unit i_android;
             shortname    : 'Android';
             flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
                             tf_requires_proper_alignment,tf_pic_default,tf_safecall_exceptions,
-                            tf_smartlink_sections,tf_has_winlike_resources];
+                            tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_mipsel;
             unit_env     : 'ANDROIDUNITS';
             extradefines : 'UNIX;HASUNIX';

+ 3 - 3
compiler/systems/i_aros.pas

@@ -34,7 +34,7 @@ unit i_aros;
             system       : system_i386_aros;
             name         : 'AROS for i386';
             shortname    : 'AROS';
-            flags        : [tf_files_case_aware, tf_smartlink_sections, tf_has_winlike_resources];
+            flags        : [tf_files_case_aware, tf_smartlink_sections, tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'AROSUNITS';
             extradefines : 'HASAMIGA;AROS_ABIv0';
@@ -100,7 +100,7 @@ unit i_aros;
             system       : system_x86_64_aros;
             name         : 'AROS for x86_64';
             shortname    : 'AROS';
-            flags        : [tf_files_case_aware, tf_smartlink_sections, tf_has_winlike_resources];
+            flags        : [tf_files_case_aware, tf_smartlink_sections, tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_x86_64;
             unit_env     : 'AROSUNITS';
             extradefines : 'HASAMIGA;AROS_BINCOMPAT;AROS_ABIv1';
@@ -165,7 +165,7 @@ unit i_aros;
             system       : system_arm_aros;
             name         : 'AROS for ARM';
             shortname    : 'AROS';
-            flags        : [tf_files_case_aware, tf_smartlink_sections, tf_has_winlike_resources];
+            flags        : [tf_files_case_aware, tf_smartlink_sections, tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_arm;
             unit_env     : 'AROSUNITS';
             extradefines : 'HASAMIGA;AROS_BINCOMPAT;AROS_ABIv0';

+ 29 - 18
compiler/systems/i_bsd.pas

@@ -64,7 +64,8 @@ unit i_bsd;
                             tf_section_threadvars,
 {$endif tls_threadvars}
                             tf_needs_symbol_type,tf_needs_symbol_size
-                            ,tf_smartlink_sections,tf_has_winlike_resources];
+                            ,tf_smartlink_sections,tf_has_winlike_resources
+                            ,tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX';
@@ -135,7 +136,7 @@ unit i_bsd;
             flags        : [tf_needs_symbol_size,tf_needs_dwarf_cfi,tf_library_needs_pic,tf_needs_symbol_type,
                             tf_files_case_sensitive,
                             tf_dwarf_only_local_labels,
-                            {tf_pic_uses_got,}tf_smartlink_sections,tf_has_winlike_resources];
+                            {tf_pic_uses_got,}tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_x86_64;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;HASUNIX;BSD';
@@ -205,7 +206,7 @@ unit i_bsd;
             flags        : [tf_needs_symbol_size,tf_needs_dwarf_cfi,tf_library_needs_pic,tf_needs_symbol_type,
                             tf_files_case_sensitive,
                             tf_dwarf_only_local_labels,
-                            {tf_pic_uses_got,}tf_smartlink_sections,tf_has_winlike_resources];
+                            {tf_pic_uses_got,}tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_x86_64;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;HASUNIX;BSD';
@@ -272,7 +273,8 @@ unit i_bsd;
             system       : system_i386_NetBSD;
             name         : 'NetBSD for i386';
             shortname    : 'NetBSD';
-            flags        : [tf_pic_uses_got,tf_under_development,tf_files_case_sensitive,tf_smartlink_library,tf_has_winlike_resources];
+            flags        : [tf_pic_uses_got,tf_under_development,tf_files_case_sensitive,tf_smartlink_library,tf_has_winlike_resources,
+                            tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX';
@@ -338,7 +340,8 @@ unit i_bsd;
             system       : system_i386_OpenBSD;
             name         : 'OpenBSD for i386';
             shortname    : 'OpenBSD';
-            flags        : [tf_pic_default,tf_pic_uses_got,tf_under_development,tf_files_case_sensitive,tf_smartlink_sections,tf_has_winlike_resources];
+            flags        : [tf_pic_default,tf_pic_uses_got,tf_under_development,tf_files_case_sensitive,tf_smartlink_sections,tf_has_winlike_resources,
+                            tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX';
@@ -408,7 +411,7 @@ unit i_bsd;
             flags        : [tf_needs_symbol_size,tf_needs_dwarf_cfi,tf_library_needs_pic,tf_needs_symbol_type,
                             tf_files_case_sensitive, tf_under_development,
                             tf_dwarf_only_local_labels, tf_pic_default,
-                            { tf_pic_uses_got,}tf_smartlink_sections,tf_has_winlike_resources];
+                            { tf_pic_uses_got,}tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_x86_64;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;HASUNIX;BSD';
@@ -475,7 +478,7 @@ unit i_bsd;
             name         : 'NetBSD for m68k';
             shortname    : 'NetBSD';
             flags        : [tf_under_development,tf_needs_symbol_size,tf_needs_symbol_type,tf_requires_proper_alignment,
-                            tf_files_case_sensitive,tf_smartlink_sections,tf_has_winlike_resources];
+                            tf_files_case_sensitive,tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_m68k;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX';
@@ -541,7 +544,7 @@ unit i_bsd;
             system       : system_powerpc_netbsd;
             name         : 'NetBSD for PowerPC';
             shortname    : 'NetBSD';
-            flags        : [tf_under_development,tf_files_case_sensitive,tf_smartlink_library,tf_has_winlike_resources];
+            flags        : [tf_under_development,tf_files_case_sensitive,tf_smartlink_library,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_powerpc;
             unit_env     : '';
             extradefines : 'UNIX;BSD;HASUNIX';
@@ -611,7 +614,7 @@ unit i_bsd;
             flags        : [tf_needs_symbol_size,tf_needs_dwarf_cfi,tf_library_needs_pic,tf_needs_symbol_type,
                             tf_files_case_sensitive, tf_under_development,
                             tf_dwarf_only_local_labels,
-                            { tf_pic_uses_got,}tf_smartlink_sections,tf_has_winlike_resources];
+                            { tf_pic_uses_got,}tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_x86_64;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;HASUNIX;BSD';
@@ -677,7 +680,8 @@ unit i_bsd;
             system       : system_arm_netbsd;
             name         : 'NetBSD for ARMHF';
             shortname    : 'NetBSD';
-            flags        : [tf_under_development,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_has_winlike_resources];
+            flags        : [tf_under_development,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_has_winlike_resources,
+                            tf_supports_hidden_symbols];
             cpu          : cpu_arm;
             unit_env     : '';
             extradefines : 'UNIX;BSD;HASUNIX';
@@ -743,7 +747,8 @@ unit i_bsd;
             system       : system_powerpc_darwin;
             name         : 'Darwin for PowerPC';
             shortname    : 'Darwin';
-            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources];
+            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources,
+                            tf_supports_hidden_symbols];
             cpu          : cpu_powerpc;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX';
@@ -811,7 +816,8 @@ unit i_bsd;
             system       : system_i386_darwin;
             name         : 'Darwin for i386';
             shortname    : 'Darwin';
-            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_uses_got,tf_pic_default,tf_has_winlike_resources,tf_use_hlcfi,tf_supports_symbolorderfile];
+            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_uses_got,
+                            tf_pic_default,tf_has_winlike_resources,tf_use_hlcfi,tf_supports_symbolorderfile,tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX';
@@ -879,7 +885,8 @@ unit i_bsd;
             system       : system_i386_iphonesim;
             name         : 'Darwin/iPhoneSim for i386';
             shortname    : 'iPhoneSim';
-            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_uses_got,tf_pic_default,tf_has_winlike_resources,tf_use_hlcfi];
+            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,
+                            tf_pic_uses_got,tf_pic_default,tf_has_winlike_resources,tf_use_hlcfi,tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX;DARWIN'; // also define darwin for code compatibility
@@ -947,7 +954,8 @@ unit i_bsd;
             system       : system_powerpc64_darwin;
             name         : 'Darwin for PowerPC64';
             shortname    : 'Darwin';
-            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources,tf_supports_symbolorderfile];
+            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,
+                            tf_pic_default,tf_has_winlike_resources,tf_supports_symbolorderfile,tf_supports_hidden_symbols];
             cpu          : cpu_powerpc64;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX';
@@ -1016,7 +1024,7 @@ unit i_bsd;
             name         : 'Darwin for x86_64';
             shortname    : 'Darwin';
             flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources,tf_use_hlcfi
-                            {$ifdef llvm},tf_use_psabieh{$endif},tf_supports_symbolorderfile];
+                            {$ifdef llvm},tf_use_psabieh{$endif},tf_supports_symbolorderfile,tf_supports_hidden_symbols];
             cpu          : cpu_x86_64;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX';
@@ -1083,7 +1091,8 @@ unit i_bsd;
             system       : system_x86_64_iphonesim;
             name         : 'Darwin/iPhoneSim for x86_64';
             shortname    : 'iPhoneSim';
-            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources,tf_use_hlcfi];
+            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,
+                            tf_pic_default,tf_has_winlike_resources,tf_use_hlcfi,tf_supports_hidden_symbols];
             cpu          : cpu_x86_64;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX;DARWIN'; // also define darwin for code compatibility
@@ -1150,7 +1159,8 @@ unit i_bsd;
             system       : system_arm_darwin;
             name         : 'Darwin for ARM';
             shortname    : 'Darwin';
-            flags        : [tf_p_ext_support,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_has_winlike_resources,tf_pic_default,tf_supports_symbolorderfile];
+            flags        : [tf_p_ext_support,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,
+                            tf_dwarf_only_local_labels,tf_has_winlike_resources,tf_pic_default,tf_supports_symbolorderfile,tf_supports_hidden_symbols];
             cpu          : cpu_arm;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX;CPUARMEL';
@@ -1218,7 +1228,8 @@ unit i_bsd;
             system       : system_aarch64_darwin;
             name         : 'Darwin for AArch64';
             shortname    : 'Darwin';
-            flags        : [tf_p_ext_support,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources,tf_supports_symbolorderfile];
+            flags        : [tf_p_ext_support,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,
+                            tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources,tf_supports_symbolorderfile,tf_supports_hidden_symbols];
             cpu          : cpu_aarch64;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX';

+ 2 - 2
compiler/systems/i_haiku.pas

@@ -37,7 +37,7 @@ unit i_haiku;
             shortname    : 'Haiku';
             flags        : [tf_under_development,tf_needs_symbol_size,tf_files_case_sensitive,
                             tf_pic_default,tf_pic_uses_got,tf_library_needs_pic,
-                            tf_smartlink_sections,tf_has_winlike_resources];
+                            tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'HAIKUUNITS';
             extradefines : 'BEOS;UNIX;HASUNIX';
@@ -117,7 +117,7 @@ unit i_haiku;
             shortname    : 'Haiku';
             flags        : [tf_under_development,tf_needs_symbol_size,tf_files_case_sensitive,
                             tf_pic_default,tf_library_needs_pic,tf_smartlink_sections,
-                            tf_has_winlike_resources];
+                            tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_x86_64;
             unit_env     : 'HAIKUUNITS';
             extradefines : 'BEOS;UNIX;HASUNIX';

+ 21 - 15
compiler/systems/i_linux.pas

@@ -44,7 +44,7 @@ unit i_linux;
 {$ifdef psabieh}
                             ,tf_use_psabieh
 {$endif psabieh}
-                            ];
+                            ,tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX';
@@ -113,7 +113,7 @@ unit i_linux;
             shortname    : 'Linux6432';
             flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
                             tf_pic_uses_got,tf_smartlink_sections,
-                            tf_has_winlike_resources];
+                            tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_x86_64;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX';
@@ -182,7 +182,7 @@ unit i_linux;
             flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
                             tf_smartlink_sections,tf_safecall_exceptions,tf_safecall_clearstack,
                             tf_requires_proper_alignment, { Coldfire seems to need this at least (KB) }
-                            tf_has_winlike_resources];
+                            tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_m68k;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX';
@@ -250,7 +250,7 @@ unit i_linux;
             shortname    : 'Linux';
             flags        : [tf_needs_symbol_size,tf_smartlink_sections,
                             tf_needs_symbol_type,tf_files_case_sensitive,
-                            tf_has_winlike_resources];
+                            tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_powerpc;
             unit_env     : '';
             extradefines : 'UNIX;HASUNIX';
@@ -317,7 +317,8 @@ unit i_linux;
             name         : 'Linux for PowerPC64';
             shortname    : 'Linux';
             flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
-                            tf_requires_proper_alignment,tf_smartlink_sections,tf_has_winlike_resources];
+                            tf_requires_proper_alignment,tf_smartlink_sections,tf_has_winlike_resources,
+                            tf_supports_hidden_symbols];
             cpu          : cpu_powerpc64;
             unit_env     : '';
             extradefines : 'UNIX;HASUNIX';
@@ -393,6 +394,7 @@ unit i_linux;
 {$ifdef psabieh}
                             ,tf_use_psabieh
 {$endif psabieh}
+                            ,tf_supports_hidden_symbols
                             ];
             cpu          : cpu_x86_64;
             unit_env     : 'LINUXUNITS';
@@ -463,7 +465,7 @@ unit i_linux;
                             tf_needs_symbol_type,tf_files_case_sensitive,
                             tf_pic_uses_got,
                             tf_requires_proper_alignment,tf_safecall_exceptions, tf_safecall_clearstack,
-                            tf_has_winlike_resources];
+                            tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_SPARC;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX';
@@ -533,7 +535,7 @@ unit i_linux;
                             tf_needs_symbol_type,tf_files_case_sensitive,
                             tf_pic_uses_got,
                             tf_requires_proper_alignment,tf_safecall_exceptions, tf_safecall_clearstack,
-                            tf_has_winlike_resources];
+                            tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_SPARC64;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX';
@@ -609,7 +611,7 @@ unit i_linux;
                             tf_use_psabieh,
 {$endif llvm}
                             tf_smartlink_sections,tf_pic_uses_got,
-                            tf_has_winlike_resources];
+                            tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_arm;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX;CPUARMHF';
@@ -682,7 +684,7 @@ unit i_linux;
                             tf_section_threadvars,
 {$endif tls_threadvars}
                             tf_smartlink_sections,tf_pic_uses_got,
-                            tf_has_winlike_resources];
+                            tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_arm;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX;CPUARMEL';
@@ -752,7 +754,7 @@ unit i_linux;
             flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
                             tf_requires_proper_alignment,
                             tf_smartlink_sections,tf_pic_uses_got,
-                            tf_has_winlike_resources];
+                            tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_arm;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX;CPUARMEB';
@@ -820,7 +822,7 @@ unit i_linux;
             shortname    : 'Linux';
             flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
                             tf_requires_proper_alignment,
-                            tf_smartlink_sections,tf_has_winlike_resources];
+                            tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_arm;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX';
@@ -898,6 +900,7 @@ unit i_linux;
 {$ifdef llvm}
                             ,tf_use_psabieh
 {$endif llvm}
+                            ,tf_supports_hidden_symbols
                             ];
             cpu          : cpu_aarch64;
             unit_env     : 'LINUXUNITS';
@@ -967,7 +970,7 @@ unit i_linux;
             flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
                             tf_requires_proper_alignment,tf_library_needs_pic,
                             tf_pic_uses_got,tf_safecall_exceptions,
-                            tf_smartlink_sections,tf_has_winlike_resources];
+                            tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_mipseb;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX';
@@ -1037,7 +1040,7 @@ unit i_linux;
             flags        : [tf_needs_symbol_size,tf_needs_symbol_type,tf_files_case_sensitive,
                             tf_requires_proper_alignment,tf_library_needs_pic,
                             tf_pic_uses_got,tf_safecall_exceptions,
-                            tf_smartlink_sections,tf_has_winlike_resources];
+                            tf_smartlink_sections,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_mipsel;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX';
@@ -1106,7 +1109,8 @@ unit i_linux;
             shortname    : 'Linux';
             flags        : [tf_needs_symbol_size,tf_smartlink_sections,
                             tf_needs_symbol_type,tf_files_case_sensitive,
-                            tf_requires_proper_alignment,tf_has_winlike_resources];
+                            tf_requires_proper_alignment,tf_has_winlike_resources,
+                            tf_supports_hidden_symbols];
             cpu          : cpu_riscv32;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX';
@@ -1175,7 +1179,9 @@ unit i_linux;
             shortname    : 'Linux';
             flags        : [tf_needs_symbol_size,tf_smartlink_sections,
                             tf_needs_symbol_type,tf_files_case_sensitive,
-                            tf_requires_proper_alignment,tf_has_winlike_resources];
+                            tf_requires_proper_alignment,tf_has_winlike_resources,
+                            tf_supports_hidden_symbols
+                            ];
             cpu          : cpu_riscv64;
             unit_env     : 'LINUXUNITS';
             extradefines : 'UNIX;HASUNIX';

+ 1 - 1
compiler/systems/i_nativent.pas

@@ -39,7 +39,7 @@ unit i_nativent;
                             ,tf_smartlink_sections{,tf_section_threadvars}{,tf_needs_dwarf_cfi},
                             tf_no_pic_supported,
                             tf_no_generic_stackcheck{,tf_has_winlike_resources},tf_under_development,
-                            tf_dwarf_only_local_labels];
+                            tf_dwarf_only_local_labels,tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'NTUNITS';
             extradefines : 'NATIVENT;FPC_OS_UNICODE';

+ 3 - 3
compiler/systems/i_sunos.pas

@@ -37,7 +37,7 @@ unit i_sunos;
             flags        : [tf_under_development,tf_needs_symbol_size,
                             tf_files_case_sensitive,tf_requires_proper_alignment,
                             tf_pic_uses_got,tf_library_needs_pic,
-                            tf_smartlink_library,tf_has_winlike_resources];
+                            tf_smartlink_library,tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'SOLARISUNITS';
             extradefines : 'UNIX;LIBC;SUNOS;HASUNIX';
@@ -109,7 +109,7 @@ unit i_sunos;
                             tf_under_development,
                             tf_files_case_sensitive,
                             tf_requires_proper_alignment,tf_smartlink_library,tf_library_needs_pic,
-                            tf_has_winlike_resources];
+                            tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_x86_64;
             unit_env     : 'SOLARISUNITS';
             extradefines : 'UNIX;LIBC;SUNOS;HASUNIX';
@@ -180,7 +180,7 @@ unit i_sunos;
                             tf_files_case_sensitive,
                             tf_pic_uses_got,
                             tf_requires_proper_alignment,tf_smartlink_library,
-                            tf_has_winlike_resources];
+                            tf_has_winlike_resources,tf_supports_hidden_symbols];
             cpu          : cpu_SPARC;
             unit_env     : 'SOLARISUNITS';
             extradefines : 'UNIX;LIBC;SUNOS;HASUNIX';

+ 4 - 4
compiler/systems/i_win.pas

@@ -39,7 +39,7 @@ unit i_win;
                             tf_winlikewidestring,tf_no_pic_supported,
                             tf_no_generic_stackcheck,tf_has_winlike_resources,
                             tf_dwarf_only_local_labels,
-                            tf_safecall_exceptions,tf_no_backquote_support];
+                            tf_safecall_exceptions,tf_no_backquote_support,tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : 'WIN32UNITS';
             extradefines : 'MSWINDOWS;WINDOWS';
@@ -110,7 +110,7 @@ unit i_win;
                             tf_winlikewidestring,tf_no_pic_supported,
                             tf_dwarf_only_local_labels,
                             tf_no_generic_stackcheck,tf_has_winlike_resources,
-                            tf_safecall_exceptions,tf_no_backquote_support];
+                            tf_safecall_exceptions,tf_no_backquote_support,tf_supports_hidden_symbols];
             cpu          : cpu_x86_64;
             unit_env     : 'WIN64UNITS';
             extradefines : 'MSWINDOWS;WINDOWS';
@@ -179,7 +179,7 @@ unit i_win;
             flags        : [tf_files_case_aware{,tf_winlikewidestring},
                             tf_smartlink_sections,tf_requires_proper_alignment,tf_no_pic_supported,
                             tf_has_winlike_resources,
-                            tf_safecall_exceptions,tf_no_backquote_support];
+                            tf_safecall_exceptions,tf_no_backquote_support,tf_supports_hidden_symbols];
             cpu          : cpu_arm;
             unit_env     : '';
             extradefines : 'UNDER_CE;WINDOWS;FPC_OS_UNICODE';
@@ -248,7 +248,7 @@ unit i_win;
             flags        : [tf_files_case_aware
                             {,tf_winlikewidestring},tf_smartlink_sections,tf_no_pic_supported,
                             tf_has_winlike_resources,
-                            tf_safecall_exceptions,tf_no_backquote_support];
+                            tf_safecall_exceptions,tf_no_backquote_support,tf_supports_hidden_symbols];
             cpu          : cpu_i386;
             unit_env     : '';
             extradefines : 'UNDER_CE;WINDOWS;FPC_OS_UNICODE';

+ 17 - 1
compiler/x86/agx86nsm.pas

@@ -59,6 +59,7 @@ interface
         procedure WriteOper(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean);
         procedure WriteOper_jmp(const o:toper; ai : taicpu);
         procedure WriteSection(atype:TAsmSectiontype;const aname:string;alignment : longint);
+        procedure WriteHiddenSymbolAttribute(sym: TAsmSymbol);
         procedure ResetSectionsList;
         procedure AddGroup(const grpname: string);
         procedure AddSegmentToGroup(const grpname,segname: string);
@@ -623,6 +624,17 @@ interface
         LastSecType:=atype;
       end;
 
+    procedure TX86NasmAssembler.WriteHiddenSymbolAttribute(sym: TAsmSymbol);
+      begin
+        if target_info.system in systems_windows then
+          exit;
+        if target_info.system in systems_darwin then
+          writer.AsmWrite(':private_extern')
+        else
+          { no colon }
+          writer.AsmWrite(' hidden')
+      end;
+
     procedure TX86NasmAssembler.ResetSectionsList;
       begin
         FSections.Free;
@@ -786,7 +798,9 @@ interface
                if tai_datablock(hp).is_global or SmartAsm then
                 begin
                   writer.AsmWrite(#9'GLOBAL ');
-                  writer.AsmWriteLn(tai_datablock(hp).sym.name);
+                  writer.AsmWrite(tai_datablock(hp).sym.name);
+                  if tai_datablock(hp).sym.bind=AB_PRIVATE_EXTERN then
+                    WriteHiddenSymbolAttribute(tai_datablock(hp).sym);
                 end;
                writer.AsmWrite(PadTabs(tai_datablock(hp).sym.name,':'));
                if SmartAsm then
@@ -1003,6 +1017,8 @@ interface
                 begin
                   writer.AsmWrite(#9'GLOBAL ');
                   writer.AsmWriteLn(tai_symbol(hp).sym.name);
+                  if tai_symbol(hp).sym.bind=AB_PRIVATE_EXTERN then
+                    WriteHiddenSymbolAttribute(tai_symbol(hp).sym);
                 end;
                writer.AsmWrite(tai_symbol(hp).sym.name);
                if SmartAsm then

+ 1 - 1
compiler/x86_64/hlcgcpu.pas

@@ -72,7 +72,7 @@ implementation
       if make_global then
         List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
       else
-        List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0,procdef));
+        List.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
 
       { set param1 interface to self  }
       g_adjust_self_value(list,procdef,ioffset);