Commit Graph

95 Commits

Author SHA1 Message Date
Sven/Sarah Barth
30a7199165 * make the VMT symbol and type def of the corresponding class or object instead of having them be global
* bump PPU version to avoid potential compilation errors due to this

Based on code by Blaise.ru
2022-05-26 21:42:51 +02:00
Jonas Maebe
3d3c904ac5 TSymStr: more consistent usage 2022-05-08 15:03:44 +02:00
Jonas Maebe
fcaea21075 SymAnsiStr: fix "make all" and webtbs/tw39661*
Fixes compilation with LLVM backend
2022-05-08 14:59:36 +02:00
Jonas Maebe
629c1de460 TOC handling: clean up
Also fix on 32 bits PowerPC
2022-02-06 22:10:06 +01:00
Jonas Maebe
68b5ca633c ppc platforms: fix missing TOC restoration room
PPC platforms that use a TOC can never use a tail call to call a different
routine that potentially accesses globals, as it may use a different TOC and
then the linker must be able to insert an instruction after the branch to
restore the original TOC register value on "return". Even if FPC code itself
does not use the TOC register, it's still required since
  1) the linker does not know this, and
  2) the FPC code might still be called from other code that does use it
2022-02-05 21:36:41 +01:00
florian
9314bbbf08 * compilation hopefully fixed 2021-11-28 00:03:30 +01:00
florian
12f48c230b * use high level interface wrappers for powerpc64 if pic is generated as
the abi does not support branches between functions located in different
    tocs which might happen for inter-module branches
2021-11-27 23:33:22 +01:00
florian
a4672fbd1c o based on a patch by Rika, resolves #39401:
* use Base64 (62=_, 63=$) encoded FNV hash (instead of CR-32) to shorted identifiers
    * renamed fpccrc to fpchash
    + test
2021-10-10 10:09:22 +02:00
florian
0ab4515e58 * properly mangle interface wrapper names to avoid duplicate label errors, resolves #38385
git-svn-id: trunk@48411 -
2021-01-24 21:32:27 +00:00
Jonas Maebe
cc315e0ac7 * fix tw3930 after r37927
o "unique" class (and interface) type aliases should actually not exist at
     all except for overload resolution. All the rest (VMT, UUID, RTTI, ...)
     should be taken from the aliased class/interface
   o there is one Delphi-incompatibily left after this change, but it shouldn't
     matter: tw8180 does not compile if you change the declaration to
     "tcl=class(TInterfacedObject,XStr,iinterface)", while Kylix does compile
     that. It doesn't really matter though, because in Kylix this actually
     adds iinterface twice as implemented interface, so there is no point
     in accepting this.

git-svn-id: trunk@46773 -
2020-09-05 12:25:09 +00:00
svenbarth
068f0d2ec8 * fix for Mantis #36935: apply patch by J. Gareth Moreton to fix a typo in cs_opt_remove_empty_proc
git-svn-id: trunk@44888 -
2020-04-20 18:42:30 +00:00
Jonas Maebe
4ba19f5418 * add support for creating non-address-only procvars to
cprocvar.getreusableprocaddr()

git-svn-id: trunk@44516 -
2020-04-02 21:21:36 +00:00
svenbarth
3ced30f816 * apply (adjusted) patch by Blaise.ru: vmtentries is always created since 2008, so treat it as such (also fixes a memory leak in tobjectdef.getcopy)
git-svn-id: trunk@43626 -
2019-12-02 06:59:05 +00:00
Jonas Maebe
9678542ba6 + add "thunk" attribute for stubs/thunks and emit it for LLVM
- also removed wrong "noreturn" attribute for interface thunks generated
     for high level code generator targets

git-svn-id: trunk@43018 -
2019-09-15 20:43:12 +00:00
Jonas Maebe
d8903ce6b3 - removed maxcrecordalign parameter/field from recordsymtables, as this value
cannot be modified in the settings (so we can directly use the one from
    current_settings)

git-svn-id: trunk@42447 -
2019-07-14 19:24:32 +00:00
Jonas Maebe
281b3ad276 * fix case completeness and unreachable code warnings in compiler that would
be introduced by the next commit

git-svn-id: trunk@42046 -
2019-05-12 14:29:03 +00:00
svenbarth
190716ac0e * move getrecorddef and gettabledef from TVMTWritter to symdef as they might be used from the RTTI as well
git-svn-id: trunk@39687 -
2018-08-29 19:21:23 +00:00
florian
048c2c09fd * shorten interface wrapper names if needed, resolves #33069
git-svn-id: trunk@38319 -
2018-02-22 21:55:07 +00:00
pierre
61d0d8717a Disable 37973 for AIX specific stabx format
git-svn-id: trunk@37995 -
2018-01-18 16:29:39 +00:00
Jonas Maebe
a73b723c1d * when using a dummy file position for an interface wrapper, set
the module to the current module. This is required in case of -al,
    because when writing source lines to the assembly output the input
    file position gets changed. Since the wrappers are generated at the
    end of a unit's compilation, that's no problem if that input file
    belongs to the current unit. It was hardcoded to the unit with id 1
    before though, which is the main unit specified on the command line
    and that one could be different (fixes compilation of win32 buildrtl
    with -al after r37961)

git-svn-id: trunk@37973 -
2018-01-14 22:06:52 +00:00
Jonas Maebe
a1df776167 * changed function name emitted for interface wrappers, as otherwise the
stabs debug info uses the wrong symbol name (fixes win32 compilation
    with stabs after r37961)

git-svn-id: trunk@37970 -
2018-01-14 21:07:41 +00:00
Jonas Maebe
d35377fdee * workaround for debug info for interface method wrappers: give them the
line number information of the method declaration if it's in the current
    unit, and otherwise the first line of the current unit (mantis #14399)

git-svn-id: trunk@37961 -
2018-01-13 16:54:22 +00:00
svenbarth
530213711f * change the class references in a class' field table to indirect references
git-svn-id: trunk@37482 -
2017-10-17 20:34:21 +00:00
florian
b1dff29cbf * removed unused units
git-svn-id: trunk@36165 -
2017-05-09 19:53:14 +00:00
svenbarth
f517311227 * ensure that the indirect symbols for VMT, RTTI and IID reside in the same sections as the symbols they point to -> reduces the amount of sections for them by half
git-svn-id: trunk@35367 -
2017-01-29 17:43:39 +00:00
svenbarth
b813fc641f * put data that's used by the VMT into the same section (that also means changing some sections from rodata_norel to rodata); this way the amount of sections per class is reduced (e.g. two for classes that inherited from a class with interfaces)
git-svn-id: trunk@35364 -
2017-01-29 17:37:13 +00:00
Jonas Maebe
d36fe53d85 * factored out the code to create an complete alias for a procdef to
symcreat.create_procdef_alias()

git-svn-id: trunk@35087 -
2016-12-09 13:39:35 +00:00
nickysn
ac186eb85d * use sizeuinttype instead of ptruinttype for the array range type in the
structure, created by TVMTWriter.gettabledef

git-svn-id: trunk@34715 -
2016-10-14 13:22:05 +00:00
nickysn
7d15b688e8 * TInterfaceEntry changed to a variant record, that overlays a CodePointer on
top of the IOffset: SizeUInt field, because it is sometimes used as a
  CodePointer (for etStaticMethodResult and etStaticMethodClass) and sometimes
  as a SizeInt and these two types can be of different size in certain i8086
  memory models

git-svn-id: trunk@34645 -
2016-10-07 20:18:02 +00:00
nickysn
7fceb8aa1f * use .Create_sizeuint and sizeuinttype when writing tinterfacetable.EntryCount
git-svn-id: trunk@34635 -
2016-10-06 14:23:37 +00:00
Jonas Maebe
4c9903455e - don't apply const_align() to alignments passed to high level typed
constant builder, it will do so itself if necessary

git-svn-id: trunk@34632 -
2016-10-06 06:25:02 +00:00
nickysn
5e7ba4a893 * the type of FieldOffset in the TFieldInfo rtti structure changed to SizeUInt,
because it represents an offset _within_ a structure

git-svn-id: trunk@34627 -
2016-10-04 21:57:29 +00:00
nickysn
f62be8f6e6 * use sizesinttype instead of ptrsinttype to refer to vInstanceSize and
vInstanceSize2 in the VMT

git-svn-id: trunk@34623 -
2016-10-04 15:25:13 +00:00
yury
e3d9dbbeef * Removed unused vars.
git-svn-id: trunk@34404 -
2016-09-01 19:55:45 +00:00
svenbarth
37c32f4b61 * generate indirect symbols for interface IID and IIDSTR (fixes cycling; I wonder why that worked on Windows without problems :/ )
git-svn-id: trunk@34353 -
2016-08-19 21:49:42 +00:00
svenbarth
fb6546972b * IID and IIDStr references of the VMT's interface table need to be indirect
git-svn-id: trunk@34338 -
2016-08-19 13:06:26 +00:00
svenbarth
77de5dd968 * reference assembler symbol of FPC_EMPTYMETHOD using AB_EXTERNAL and not AB_GLOBAL
git-svn-id: trunk@34337 -
2016-08-19 12:42:14 +00:00
svenbarth
2841cd9a9e * export IID and IIDSTR symbols of interfaces
git-svn-id: trunk@34255 -
2016-08-05 15:10:25 +00:00
svenbarth
971d05c898 * also import procdefs that are called through the VMT
git-svn-id: trunk@34177 -
2016-07-22 13:38:59 +00:00
svenbarth
f69b365b77 * declare various symbols as external assembler symbols: RTTI references, parent VMT, FPC_EMPTYMETHOD (all three only if it's used from a different unit), threadvar lists and symbols declared as "external"
git-svn-id: trunk@34176 -
2016-07-22 13:34:38 +00:00
svenbarth
bb72c1c4df * declare various assembler symbols (VMT, RTTI, threadvars) as public assembler symbols
* declare public function alias as public assembler symbols

git-svn-id: trunk@34175 -
2016-07-22 13:11:24 +00:00
svenbarth
685f820622 * switch class'/object's parent reference in the VMT to an indirect reference
(this also requires the adjustment of a test)

git-svn-id: trunk@34172 -
2016-07-22 12:53:51 +00:00
svenbarth
dc21bc842a * also generate an indirect symbol for the VMT
git-svn-id: trunk@34171 -
2016-07-22 12:50:38 +00:00
Jonas Maebe
a0efde8167 * automatically generate necessary indirect symbols when a new assembler
symbol is defined
   o removed all places where AB_INDIRECT symbols were explicitly generated
   o only generate AB_INDIRECT symbols for AT_DATA on systems_indirect_var_imports
   o for some symbols an indirect symbol is always required (because they are
     dereferenced by code in RTL units) -> use new AT_DATA_FORCEINDIRECT type

git-svn-id: trunk@34165 -
2016-07-20 20:53:03 +00:00
Jonas Maebe
1cb8c0d00c * specify the def of assembler level symbols defined via
tasmdata.DefineAsmSymbol() and all routines that call it
   o will be used to automatically generate AB_INDIRECT sybols when
     necessary

git-svn-id: trunk@34164 -
2016-07-20 20:52:59 +00:00
Jonas Maebe
c0ff55e95a * changed the abstract method wrapper generation from thlcgobj to synthetic
methods. Implementing a fully functional g_external_wrapper() for llvm is
    quite hard, and the regular wrapper method that calls FPC_ABSTRACTERROR can
    in principle be optimized to a plain jump by tail call optimisation on other
    targets (to the extent that this matters, because most of them will be
    smartlinked away, and the ones that are executed will trigger an exception)
   o this means that the synthetic method generation needs to be run for all
     objectdefs on all platforms now, rather than only for Java classes

git-svn-id: trunk@34127 -
2016-07-14 15:24:13 +00:00
svenbarth
7a5bac9cd3 Rework the interface table of VMTs to get rid of FPC_EMPTYINTF.
Previously we had the following approach:
- classes that implemented interfaces had an interface table
- classes that didn't implement an interface, but inherited from a class that did had a Nil entry
- classes that didn't implement any interface (including their parents) had a reference to FPC_EMPTYINTF (this was to optimize lookups)

Now the approach is as follows:
- classes that implement an interface or have a parent that implements an interface have an interface table; if the class itself doesn't implement an interface then the count will be 0
- classes that don't implement an interface at all (neither them nor their parents) have a Nil interface table

This way FPC_EMPTYINTF can be removed without sacrificing at least the optimization for classes without any interface. For classes that have parents with interfaces there will be a small speed penalty due to an additional lookup for the counter.

git-svn-id: trunk@34087 -
2016-07-08 15:34:55 +00:00
svenbarth
345d83c3e3 Merge RTTI changes from packages branch (including adjustments that were required due to changes in trunk since then). These changes favor source backwards compatibility in contrast to Delphi compatibility. Binary compatiblity is however drastically broken due to the indirect references that are platform independant!
Merged revision(s) 28239-28289 from branches/svenbarth/packages:
Provide the possiblity to switch between the direct and indirect RTTI symbols.

ncgrtti.pas, TRTTIWriter:
  + get_rtti_label, get_rtti_label_ord2str & get_rtti_label_str2ord: add new "indirect" parameter and pass that along to rtti_mangledname
hlcgobj.pas, thlcgobj:
  * g_incrrefcount, g_initialize, g_finalize, g_array_rtti_helper: for now pass along False to get_rtti_label()
ncgvmt.pas, TVMTWriter:
  * writevmt: for now pass along False to get_rtti_label()
ncgld.pas, tcgrttinode:
  * pass_generate_code: for now pass along False to the get_rtti_label*() methods
........
Provide possibility to select between using a direct and an indirect RTTI reference. This way the references can be changed for selected cases.

ncgrtti, TRTTIWriter:
  * ref_rtti: new "indirect" parameter that's relayed to rtti_mangledname()
  * write_rtti_reference: new "indirect" paramater that's relayed to ref_rtti()
........
Switch properties to use the indirect type information without breaking backwards compatiblity. :)

compiler/ncgrtti.pas, TRTTIWriter:
  * published_properties_write_rtti_data: use the indirect reference, not the direct one
rtl/objpas/typinfo.pp:
  * to allow compilation with both 2.6.x and 2.7.1 and too avoid too many ifdefs at least in the declarations we define a macro TypeInfoPtr which is either PTypeInfo (2.6.x) or PPTypeInfo (2.7.1 and newer)
  * TPropInfo: rename PropType to PropTypeRef and change type to TypeInfoPtr
  + TPropInfo: add a new property PropType which returns a PTypeInfo out of the PropTypeRef depending on the compiler version
........
Switch further simple types (sets, enums, class references, pointers) to indirect type information (again without breaking backwards compatibility).

compiler/ncgrtti.pas, TRTTIWriter.write_rtti_data:
  * enumdef_rtti, setdef_rtti, classrefdef_rtti & pointerdef_rtti: write an indirect RTTI reference

rtl/objpas/typinfo.pp, TTypeData:
  * rename BaseType to BaseTypeRef, CompType to CompTypeRef, InstanceType to InstanceTypeRef and RefType to RefTypeRef and change their type to TypeInfoPtr
  + add properties BaseType, CompType, InstanceType & RefType which return a PTypeInfo out of the corresponding *Ref field depending on the compiler version
........
Switch class and interface parent as well as extended type to indirect type information

compiler/ncgrtti.pas, TRTTIWriter:
  * write_rtti_data.objectdef_rtti.objectdef_rtti_class_full: use indirect reference for class parent and extended type
  * write_rtti_data.objectdef_rtti.objectdef_rtti_interface_full: use indirect reference for interface parent

rtl/objpas/typinfo.pp, TTypeData:
  + add new method DerefTypeInfoPtr which returns Nil if the indirect reference is Nil and otherwise returns the dereferences indirect reference (for 2.6.x the direct reference is returned as is)
  * rename ParentInfo to ParentInfoRef, HelperParent to HelperParentRef, ExtendedInfo to ExtendedInfoRef, IntfParent ot IntfParentRef and RawIntfParent to RawIntfParentRef and change their type to TypeInfoPtr
  + introduce ParentInfo, HelperParent, ExtendedInfo, IntfParent and RawIntfParent properties that return a PTypeInfo and use the new DerefTypeInfoPtr to return the correct type info value
  * change the other newly introduced properties of TTypeData to use DerefTypeInfoPtr as well to be on the safe side
........
Switch record/object fields to indirect type information references.

compiler/ncgrtti.pas, TRTTIWriter.fields_write_rtti_data:
  * use the indirect reference for the object parent type
  * use the indirect reference for the field type

rtl/inc/rtti.inc:
  * TRecordElement: change TypeInfo to PPointer for 2.7.1 and newer
  * RecordRTTI: correctly dereference the element type for 2.7.1 and newer
  * fpc_copy: correctly reference the element type for 2.7.1 and newer
........
Switch static arrays to indirect RTTI reference.

compiler/ncgrtti.pas, TRTTIWriter.write_rtti_data:
  * arraydef_rtti: write the dimension types and the final field type as indirect references

rtl/inc/rtti.inc:
  * TArrayInfo: switch ElInfo to PPointer for 2.7.1+
  * ArrayRTTI & fpc_copy: correctly dereference ElInfo for 2.7.1+
rtl/objpas/typinfo.pp, TArrayTypeData:
  * switch ElType and Dims to PPTypeInfo; no backwards compatibility needed here as TArrayTypeData was added in 2.7.1 only

tests/test/trtti8.pp: fix test
........
Switch dynamic arrays to indirect RTTI references.

compiler/ncgrtti.pas, TRTTIWriter.write_rtti_data.arraydef_rtti:
  * write indirect references for the two element entries

rtl/inc/dynarr.inc:
  * tdynarraytypedata: change elType2 to PPointer for 2.7.1+
  * fpc_dynarray_clear, fpc_dynarray_setlength & fpc_dynarray_copy: correctly dereference elType2 for 2.7.1+
rtl/objpas/typinfo.pp, TTypeData:
  * rename elType and elType2 to elTypeRef and elType2Ref respectively and change type to TypeInfoPtr
  * add properties elType and elType2 which return PTypeInfo by dereferencing elTypeRef and elType2Ref respecively correctly
  * remove a few stray "inline" directives in the implementation
........
Switch procedure parameters and result type to indirect RTTI references.

compiler/ncgrtti.pas, TRTTIWriter.write_rtti_data.procvardef_rtti:
  * write_procedure_param: use indirect RTTI reference
  * write result info for both methods and procvars as indirect RTTI reference
  * write parameters for procvars as indirect RTTI reference

rtl/objpas/typinfo.pp:
  * TProcedureParam: change type of ParamType to PPTypeInfo (no backwards compatiblity needed here; was added for 2.7.1)
  * TProcedureSignature: change type of RseultType to PPTypeInfo (no backwards compatibility needed here; was added for 2.7.1)
  * TTypeData: remark in the comments of tkMethod that ResultTypeRef and ParamTypeRefs are of type PPTypeInfo and not PTypeInfo

tests/test/trtti9.pp: 
  * fix test
........
Remove no longer needed "indirect" parameter for TRTTIWriter methods.

ncgrtti.pas, TRTTIWriter:
  - ref_rtti & write_rtti_reference: remove "indirect" parameter
  * ref_rtti: call rtti_mangledname with "indirect" always set to "true"
  - remove "true" parameter on callsites of write_rtti_reference & ref_rtti
........

git-svn-id: trunk@33944 -
2016-06-10 17:01:51 +00:00
svenbarth
9857a27ad8 Generate and use an indirect symbol for VMTs.
Note: the merged code has been adjusted to a) use the typed constant builder and b) to not use the indirect symbol when its not necessary (non-Windows or same unit)

Merged revision(s) 28340, 28350 from branches/svenbarth/packages:
Generate an indirect VMT symbol for each generated VMT.

ncgvmt.pas, TVMTWriter:
  * writevmt: write a symbol with the indirect VMT name that references the direct VMT symbol
........
Load the VMT using the indirect symbol if the target supports packages.

ncgmem.pas, tcgloadvmtaddrnode:
  * pass_generate_code: if tf_supports_packages is set in target_info.flags we load the VMT using the indirect symbol, otherwise we load it using the direct symbol

........

git-svn-id: trunk@33448 -
2016-04-08 14:21:51 +00:00
svenbarth
557f74cdbd (Note to self: always include the root of the working copy in the commit when dealing with merges -.-)
Merged revision(s) 28793, 28903, 31951 from branches/svenbarth/packages:
psub.pas, read_proc:
  * don't generate assembler symbols for compiler internal code
........
Ensure that unneeded initialization/finalization procedures don't leave assembler symbols.

ncgutil.pas:
  + new function release_proc_symbol which removes all assembler symbols of a procdef
pmodules.pas, proc_unit:
  * if the initialization or finalization procedure is empty also remove their assembler symbols so they are exported
........
Ensure that readonly sections that need relocations are indeed declared as such.
Thanks to Jonas for this.

ncgvmt.pas, TVMTWriter:
  * writeinterfaceids: use sec_rodata instead of sec_rodata_norel

........

git-svn-id: trunk@32982 -
2016-01-22 16:58:33 +00:00