Commit Graph

169 Commits

Author SHA1 Message Date
nickysn
bde7d0aacb + added "code segment too large" and "data segment too large" error messages
git-svn-id: trunk@30687 -
2015-04-20 23:47:22 +00:00
nickysn
a7e059c875 + support segment relocations in the omf writer
git-svn-id: trunk@30600 -
2015-04-14 22:46:01 +00:00
nickysn
393b9b54a8 + handle aitconst_farptr in the internal asm writer as a new relocation type (RELOC_FARPTR)
git-svn-id: trunk@30456 -
2015-04-05 23:43:37 +00:00
Jeppe Johansen
52e505bff7 Fixed internal error in GOT related code for ARM internal assembler.
git-svn-id: trunk@30188 -
2015-03-14 16:03:16 +00:00
Jeppe Johansen
71cdedea82 Add missing NOP, and B instruction forms.
Move ThumbFunc flag from section to symbol.
Make .w forms optional the other way around. If .w is explicitly put on an instruction the assembler should always chose a wide form.

git-svn-id: branches/laksen/armiw@29341 -
2014-12-27 13:23:02 +00:00
Jeppe Johansen
de00a1d76d Implement simple support for .thumb_func in the ELF output.
git-svn-id: branches/laksen/armiw@29340 -
2014-12-27 11:02:38 +00:00
Jeppe Johansen
5c3093a937 Add most non-VFP Thumb-2 instruction entries for the ARM internal writer.
git-svn-id: branches/laksen/armiw@29329 -
2014-12-26 18:35:15 +00:00
Jeppe Johansen
9e5979e8be Implemented UAL syntax support in the ARM assembler reader. Can be toggled with a field for now, but not implemented yet. Still using pre-UAL syntax for now.
Switched codegeneration of VFPv2 and VFPv3 to use UAL mnemonics and syntax.
Updated VFP code in RTL to use UAL syntax too.
Added preliminary ELF support for ARM.
Added support for linking of WinCE COFF files. Should work for with a standard ARMv4-I target.

git-svn-id: branches/laksen/armiw@29247 -
2014-12-10 20:44:34 +00:00
sergei
a4053370fc * ELF linker: track relocation style (REL or RELA) of each input section and use it instead of global default on MIPS targets. This fixes internal linking of tests/test/units/system/tres*.pp.
git-svn-id: trunk@29070 -
2014-11-13 22:10:53 +00:00
nickysn
7cfd7a66cd + create a special 'heap' segment with reserved space equal to heapsize (i.e.
the value set by -Ch or the second parameter to the $M directive). This is
  equivalent to the heapmin value in Turbo Pascal 7 and ensures that the program
  has at least this amount of heap space available (otherwise DOS will show a
  'not enough memory' error and will refuse to load the program).

git-svn-id: trunk@28002 -
2014-06-19 14:14:01 +00:00
nickysn
3cc8ff11e3 + generate the stack segment for i8086 far data memory models from within fpc
itself (instead of having a fixed 16k stack in the startup code). This allows
  setting the stack size in these models with the -Cs option.

git-svn-id: trunk@27820 -
2014-05-27 23:29:50 +00:00
sergei
46f8e78d1f + Support GOT/gp-relative constants in GAS and internal assemblers, MIPS and i386.
* Change MIPS jump tables in PIC mode to use gp-relative constants, making them ABI-compliant and not requiring dynamic relocations.

git-svn-id: trunk@26886 -
2014-02-26 14:54:47 +00:00
florian
4d5119bf1c * fixes several issues which cause warnings by the dfa code when using it to detect uninitialized variables
git-svn-id: trunk@26161 -
2013-12-01 17:02:08 +00:00
sergei
1f8a67f552 + Property TObjSymbol.ObjData, allows to access owning TObjData for external/common symbols, i.e. ones with ObjSection=nil.
* For common symbols, report objdata of the original ObjSymbol, not of the resolving one, so the map file shows where it comes from.
+ TElfExeOutput.OrderOrphanSections method, handles object sections not mentioned in script similar to ld.
- t_linux.pas: removed sections that are not part of ld scripts, they are now handled by OrderOrphanSections.

git-svn-id: trunk@25184 -
2013-07-30 09:23:48 +00:00
sergei
5b6e50c9da * It is incorrect to use var_align() in linker code: it depends on current_settings.alignment, which is valid only while compiling, not while linking. Replaced with size_2_align().
git-svn-id: trunk@25182 -
2013-07-29 15:51:30 +00:00
sergei
1fea5a82c1 * Replaced oso_disabled flag by TExeSection.Disabled boolean property. Makes code a bit nicer to read.
git-svn-id: trunk@24361 -
2013-04-28 20:29:49 +00:00
sergei
b86372ccec + Internal linker: process unreferenced .pdata sections on x86_64-win64, restores the possibility to use GAS on win64 (which got broken by introducing SEH).
git-svn-id: trunk@24235 -
2013-04-13 18:52:50 +00:00
sergei
c3f8086598 + Internal linker: base support for sections that aren't referenced but must be linked if section referenced by them is linked (like win64 .pdata). Actual handling is still to be implemented in descendant classes.
git-svn-id: trunk@24224 -
2013-04-11 17:42:09 +00:00
sergei
999c3a0a02 * COFF linker: postpone import section generation until unreferenced sections (and imports) are removed, and put all remaining imports into a single section. This is much more efficient than generating multiple smart-linkable import sections and immediately discarding a good half of them.
git-svn-id: trunk@24123 -
2013-04-02 05:46:32 +00:00
sergei
cded05ccef + MIPS linker: support linking PIC object files with non-PIC ones, by routing absolute calls into PIC code through stubs that load R25.
git-svn-id: trunk@24098 -
2013-03-31 19:58:52 +00:00
sergei
1d32b107f5 * Made address comparison 64-bit safe.
* Referencing a section is basically referencing its AT_SECTION symbol, fixed reporting in map file.

git-svn-id: trunk@24029 -
2013-03-28 10:44:09 +00:00
florian
20a534e63f * fixed code which causes range check errors when compiled with -Cr
git-svn-id: trunk@23889 -
2013-03-17 14:24:50 +00:00
sergei
6484911f05 * TExeOutput.FixupRelocations method made virtual.
* TElfExeOutput.MemPos_Start split into four smaller methods.

git-svn-id: trunk@23684 -
2013-03-03 20:01:54 +00:00
sergei
f98e09d86e - TObjData.sectiontype2options: removed oso_keep flags. They don't have any effect here because this function is used only during assembling, and oso_keep cannot be represented in object files and therefore gets lost before linking.
git-svn-id: trunk@23364 -
2013-01-11 17:14:44 +00:00
sergei
2bba4e2d44 + Stabs debug info needs swapping when linking for different endianness.
* A few minor tweaks for Stabs generation.

git-svn-id: trunk@23316 -
2013-01-05 12:26:23 +00:00
sergei
d7c5daeccd * Don't calculate data position of each object section. Instead, write out a copy of exesection's memory image, i.e. every objsection is placed at the same offset from its owning exesection both on disk and in memory. This approach is simpler and works regardless of alignment requirements, while existing one could work only if SectionDataAlign<=SectionMemAlign.
* Netware target may be broken by this change; at least it deserves a good cleanup because it contains a lot of code trying to solve similar task: to write exesections without alignment and deal with objsections that are nevertheless being aligned by TExeOutput.

git-svn-id: trunk@23291 -
2013-01-02 10:10:23 +00:00
sergei
00ca4a74a3 * Reworked/fixed TExeSymbol.State behavior:
* Added symstate_undefweak for undefined symbols having only weak references to them, this state is removed when a normal reference to symbol is seen.
  * Use a separate boolean property to determine if ExeSymbol is referenced.
  * Use a separate property TExeOutput.AllowUndefinedSymbols to suppress error messages when linking dynamic shared objects.
  * Don't issue InternalError when an undefined symbol is encountered during unused section removal.

git-svn-id: trunk@23127 -
2012-12-09 08:02:58 +00:00
sergei
36859068f5 * Propagate AS_NEEDED flag further into Load_DynamicObject and handle it properly: shared objects marked with AS_NEEDED are added to dependencies only if they actually resolve some symbol.
* Dropped TObjInput.newObjData method. Instead, TObjData instances are created directly in ReadObjData, this gives possibility to create a different type of TObjData based on file header.
- Dropped TObjInput destructor, it does nothing except calling inherited.

git-svn-id: trunk@23118 -
2012-12-06 18:19:19 +00:00
sergei
129d737523 + Allow TObjRelocation to be created without a symbol, such relocations are being used to tag specific positions on non-x86 targets.
* Write relocation format dependent dynamic tags based on actual sh_type of dynamic relocation sections, instead of global relocs_use_addend flag.
* Don't write DT_REL[A]COUNT tag if .rel[a].dyn section is not present.

git-svn-id: trunk@23083 -
2012-12-01 13:38:28 +00:00
sergei
0369a30f49 * Internal linker: made sec_rodata_norel read-only.
* For Win32 and Win64 targets made sec_rodata read-only, too (for these targets it doesn't matter if read-only section contains relocations).

git-svn-id: trunk@23025 -
2012-11-18 17:40:17 +00:00
sergei
1aea22a6ca + Internal linker: generic and ELF-specific support for grouped sections, allow same symbol to be defined in several COMDAT groups.
* ELF linker: don't make unresolved weak symbols dynamic if linking statically (-Xt in command line).
* Now internal linker produces working executable for tw14265 also on i386-linux when compiling manually (still unable to locate required libraries when run from test suite).

git-svn-id: trunk@22987 -
2012-11-15 13:41:25 +00:00
sergei
d019670495 - Removed generic implementation of TObjData.sectionname, its existence is useless because it is completely overridden by all TObjData descendants.
- Removed separate ELF section names for PIC. The only difference was .data named .data.rel; however .rel suffix has nothing to do with PIC. It only signifies that the section has relocations so such sections can be grouped together in output file and reduce number of pages for dynamic linker to visit  while resolving the relocations at load time. At the same time, no existing link scripts distinguish between .rel and any other suffix (except .rel.ro, but it's a different story), meaning that long section names will break .rel grouping.
While support for .data.rel can be added similar to existing rodata handling (separate sec_data and sec_data_norel sections), this doesn't seem worth the trouble.

git-svn-id: trunk@22915 -
2012-11-02 08:03:54 +00:00
sergei
8a56c9f7dc * TExeOutput.Order_Symbol and Order_ProvideSymbol: Instead of searching objsection by name, search for the symbol and use its objsection.
* TExeOutput.WriteExeSectionContent: To write proper gap between exe sections, don't align writer position. The desired position is present in exesection.DataPos, so pad right up to it.

git-svn-id: trunk@22881 -
2012-10-30 12:49:15 +00:00
sergei
499162ca50 * Internal linker: fixed alignment routines. Neither of existing ones is suitable for 64-bit targets: cutils.align() is 32-bit only and moreover signed, system.align() crashes on zero alignment values and handles only pointer size of source platform.
Therefore, added dedicated routines align_aword and align_qword that handle target platform size and 64-bit unsigned, respectively.
+ Also added TExeOutput.FixedSectionAlign boolean that, when set to False, ignores SectionDataAlign and SectionMemAlign and aligns every exe section to its own SecAlign value. This kind of alignment is used on ELF targets.

git-svn-id: trunk@22858 -
2012-10-27 14:21:14 +00:00
sergei
ee62a1ed50 * Fixed unclosed comment from r22775.
git-svn-id: trunk@22777 -
2012-10-19 18:21:43 +00:00
sergei
6d70009f06 + ELF linker. Works on x86_64-linux and i386-linux good enough to pass the testsuite, but still requires a lot of work in nearly all aspects. In particular, no attempt to resolve symbols from shared libs is done, everything is just treated as imports. Symbol versioning isn't supported either.
x86_64 is the most elaborated, has some degree of indirect function (GNU_IFUNC) and TLS support, so it is even able to link with static libc/pthreads code (tw14265) and produce an executable that can launch (but still fails due to invalid DWARF unwind info).

i386 produces working shared libraries if they are compiled with -Cg, without one your mileage may vary. tw14265 does not link yet due to missing COMDAT group support.

git-svn-id: trunk@22775 -
2012-10-19 17:21:08 +00:00
sergei
a178e28275 + Extend TObjRelocation to hold untranslated platform-specific relocation types. This allows to avoid translating relocations into generic format when reading object files (which is just waste of time), and allows TObjRelocationType enumeration contain only types that are actually produced by compiler.
git-svn-id: trunk@22667 -
2012-10-16 10:40:34 +00:00
sergei
3d63b1a2b2 + Added a flag allowing a section to be written into both .dbg and executable files. This is needed at least for ELF SHT_NOTE sections.
git-svn-id: trunk@22614 -
2012-10-11 19:26:40 +00:00
sergei
fde944bf5d + Declare AT_TLS and AT_GNU_IFUNC symbol types, these are needed to handle object files created by gcc in ELF internal linker.
* TExeOutput.FixupSymbols:
  + Collect AT_GNU_IFUNC symbols in IndirectObjSymbols list for further processing by ELF back-end.
  * Do not overwrite bind and size while fixing AB_COMMON symbols, this removes need in storing symbol size in every relocation and dedicated handling of oso_common section.
  * Remove symbols with objsection<>nil from lists, so calling FixupSymbols several times skips already processed symbols.

git-svn-id: trunk@22393 -
2012-09-14 17:22:48 +00:00
sergei
c41b407119 * Changed TObjSection.WriteStr method to write a zero byte after the string.
+ Added TObjSection.WriteBytes method that writes just a string (without zero byte).
* ogelf.pas: Fixed st_value of COMMON symbols, it must contain required symbol alignment.
+ ogelf.pas: Some more definitions.

git-svn-id: trunk@22332 -
2012-09-06 06:06:04 +00:00
sergei
b1b175dacc + Internal linker support for weak symbols.
+ Allow unresolved external symbols in RemoveUnreferencedSections, such symbols are marked as 'dynamic' if referenced. This approach allows to collect unused sections early and generate import structures only for actually used symbols.

git-svn-id: trunk@22312 -
2012-09-04 13:16:56 +00:00
sergei
6f4e8927cd * Specify explicitly whether properties of an ObjSection should be considered when adding it to ExeSection, instead of deciding it implicitly.
git-svn-id: trunk@22292 -
2012-09-03 09:12:50 +00:00
sergei
d79511f96e + Basic ld script parsing capabilities (barely enough to parse glibc2.1 'libc.so' files, lacks any error handling).
+ Support linker input source grouping functionality.
* Promote TStaticLibrary to something like generic linker input statement, it can now hold regular ObjData or a group of other TStaticLibrary objects in addition to tarobjectreader.

git-svn-id: trunk@22155 -
2012-08-21 08:37:39 +00:00
sergei
ec56677927 + Added method TObjSection.writeReloc_internal to write relocations to given section+offset without need to have a symbol at target location.
* Optimized COFF importing code using the new method.
  - Don't create .text sections for imported variables.
  - Don't create .idata$6 sections for imports by ordinal.

git-svn-id: trunk@22086 -
2012-08-15 12:22:07 +00:00
sergei
c1e7e9c85e * TObjData.symbolref: don't lose the weak binding of asm symbol. This fixes tests/tweaklib*.pp at least for Linux x86 targets with internal assembler.
* Enabled weak linking for Linux targets.

git-svn-id: trunk@21998 -
2012-08-02 12:15:55 +00:00
sergei
1d09005542 + Implemented two-stage removal of empty exe sections. Candidates for removal are first marked with oso_disabled flag, then actually removed. Descendants of TExeOutput that override MemPos_Start may modify list of sections pending removal. In particular, the COFF-specific .reloc section no longer has to be handled in base TExeOutput class.
git-svn-id: trunk@21971 -
2012-07-26 10:04:12 +00:00
sergei
31d004e056 + Basic executable stack support in TExeOutput.
+ Two stubs (TExeOutput.Load_DynamicObject and TObjInput.CanReadObjData) to override in ELF linker.
+ Stop linking if errors were detected while loading object files.
* Changed TStaticLibrary to TObject. It is never looked up by name, so hashing is redundant; moreover its name has been changed to TCmdStr, which may be trimmed by TFPHashList. 

git-svn-id: trunk@21968 -
2012-07-25 11:08:54 +00:00
sergei
24c7b7f433 * If alignment requirement of data is bigger than alignment of the section being written to, increase section alignment to match. This mostly affects cases of non-smart linking, where wrong initial alignment used to cause hard to catch misalignment issues. It also largely obsoletes the need to supply the initial section alignment (hidden tai_section constructor,etc).
* Likewise, when merging object sections into exe sections, set alignment of exe section to maximum value.

git-svn-id: trunk@21964 -
2012-07-24 08:38:11 +00:00
sergei
06844fdb23 * Entirely moved relocation fixup functionality from TObjSection to TExeOutput.
git-svn-id: trunk@21944 -
2012-07-22 07:21:11 +00:00
sergei
2bc792fe97 * TObjData.FName made protected.
* Allow EntryName to remain unspecified.

git-svn-id: trunk@21940 -
2012-07-20 12:50:21 +00:00