Commit Graph

138 Commits

Author SHA1 Message Date
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
sergei
3b3da49ad6 * Merged TElfObjSection.secshidx and TCoffObjSection.secidx into TObjSection.index.
git-svn-id: trunk@21848 -
2012-07-10 13:34:55 +00:00
sergei
712f5d1c26 - Removed oso_readonly and oso_noload section options, it is enough to have just oso_write and oso_load to express possible section states.
git-svn-id: trunk@21825 -
2012-07-09 12:58:37 +00:00
sergei
1c5fa5448e * Do not dereference null pointer, 'real' (not script-provided) common symbols don't have objsection assigned at this point.
git-svn-id: trunk@21748 -
2012-07-01 13:42:25 +00:00
sergei
65e701a198 * Fixed operation of 'PROVIDE' link script directive (all symbols were incorrectly put into .bss section, instead of locations given by placement of the directive).
* Changed type of symbols created by link script from AT_FUNCTION to AT_DATA. This isn't significant for COFF, but matters for ELF targets.
* Changed alignment of .gnu_debuglink section from 0 to 1, this matches behavior of ld.

git-svn-id: trunk@21741 -
2012-06-30 17:32:45 +00:00
sergei
c65abdeeae * Implemented link map generation without involving TObjSection.ObjSymbolDefines, and removed the latter because it isn't used otherwise. The new approach uses CPU/memory only when map generation is requested.
git-svn-id: trunk@21737 -
2012-06-30 07:51:45 +00:00
sergei
80bbd388f9 * Made removal of unused ExeSymbols a separate procedure, call it earlier and regardless of presence of the 'SYMBOLS' directive in the linker script.
git-svn-id: trunk@21727 -
2012-06-27 20:26:49 +00:00
sergei
8c8883cc35 * Once TExeOutput is accessible in TObjSection.fixuprelocs, its ImageBase can be used directly, without a need to have a copy in every TObjSection.
* Also simplified COFF symbol loading, separate array of symbol sizes is not needed because these sizes never change during the load.

git-svn-id: trunk@21704 -
2012-06-25 18:39:46 +00:00
sergei
bd7ebdce18 * ELF relocation cleanup/improvement:
+ Store size of relocation and explicit addend in TObjRelocation (reusing 'orgsize' field for the latter). This removes need for reading addends back from section data, addends are stored in full 64 bits and therefore not truncated.
  + Relocation style is now controlled by relocs_use_addend variable instead of $ifdef's.
  - Removed (never working) checks forbidding relocations of readonly sections. At the linking stage readonly sections *can* have relocations, executable stage is different matter to be handled elsewhere.
  - removed ugly hack with mapping 32-bit absolute relocations to RELOC_RVA.
  + support 64-bit relative relocations.
  * actualized list of x86_64 relocations.

git-svn-id: trunk@21662 -
2012-06-20 14:16:48 +00:00
sergei
98fffb7981 * Overloaded MemPos_ExeSection and DataPos_ExeSection accepting a TExeSection instead of name.
git-svn-id: trunk@21661 -
2012-06-20 13:33:18 +00:00
sergei
7cda919547 * Pass ExeOutput as argument to TObjSection.fixuprelocs, needed for ELF targets to relocate the complex GOT stuff.
* TExeSection.AddObjSection made virtual.
- TExeSymbol.ExeSection is nowhere used, removed.

git-svn-id: trunk@21626 -
2012-06-16 22:33:26 +00:00
sergei
807a2f243f * Fixed control flow after r21492, was causing IE 200602252 if compiling with "-g -Xg" (Mantis #22224)
- Also removed accidentally committed debug code.

git-svn-id: trunk@21522 -
2012-06-07 22:30:50 +00:00
sergei
7d3294b504 * Moved 4 procedures for basic reading/writing TObjSection contents into ogcoff.pas, so they don't have to be reimplemented for every output format.
git-svn-id: trunk@21492 -
2012-06-05 19:52:40 +00:00
sergei
8814f56081 * Fixed oso_debug section attribute being not preserved while reading/writing DJCOFF object files.
* Fixed header data positions for DJCOFF executables, they need adjustment by stub size.
* Fixed symbol values in DJCOFF executables, they must be absolute.
* Fixed missing oso_common flag on TExeOutput.commonObjSection, causing incorrect COFF relocations to this section.

git-svn-id: trunk@21408 -
2012-05-28 11:46:52 +00:00
Jonas Maebe
6432c82c01 * don't pass property as var-parameter to val()
git-svn-id: trunk@20137 -
2012-01-21 16:54:57 +00:00
sergei
6280ee2eed * Changed attributes of .pdata section so it is smart-linkable on x86_64.
* Changed alignment of .pdata section to 4.
+ Support saving RELOC_NONE relocations to .o files and reading them back on x86_64.

git-svn-id: trunk@19070 -
2011-09-15 15:22:03 +00:00
sergei
c9f92c0323 * Excluded oso_executable from attributes of user sections. User sections may currently be specified only for variables and typed consts, which are not executable.
* Fixed TLS directory size written to PE header when cross-compiling. It must be the value for target, not for host.

git-svn-id: trunk@18024 -
2011-07-27 14:10:22 +00:00
sergei
6a2e87121b * ogcoff.pas: sort all objsections having '$' in the name, not just .idata$*. This is a documented PECOFF feature and it is required for tls callback stuff to link correctly regardless of the order of declarations in source files.
git-svn-id: trunk@17968 -
2011-07-10 12:24:35 +00:00
pierre
92c92e1945 * Add oso_keep option to threadvar section if FPC_USE_TLS_DIRECTORY is set
git-svn-id: trunk@17905 -
2011-07-01 14:40:02 +00:00
pierre
c07bcefb6b * Fix anumval wrong overwriting as found out by Sergey
git-svn-id: trunk@17861 -
2011-06-28 20:39:53 +00:00
pierre
239944f8d0 + Use DLL name in assembler labels used to import DLL functions/variables
in Windows, Emx and OS2 targets.
    This fixes test failures: test/library/tlib1b.pp and lib2b.pp

    link unit TLinker.AddImportSymbol: Added symmangledname parameter.
    ogbase unit TImportSymbol.Create: Add AMangledName parameter.
    fmodule unit TModule.AddExternalImport: Add symmangledname parameter.
    fppu unit: Also put mangled name string for imported symbol.
    ppu unit: Increase PPUVersion
    utils/ppudump.pp: Adapt to PPU change above.
    systems/T_OS units: Use ImportSymbol.MangledName property to create
    import libraries or .idata sections.

git-svn-id: trunk@17804 -
2011-06-23 11:38:57 +00:00
pierre
1a9f4ba314 * Improve ogbase linker script support, add warnings for unknown entries
git-svn-id: trunk@17784 -
2011-06-21 16:49:50 +00:00
florian
c97869bd89 * merge user sections support branch
git-svn-id: trunk@17285 -
2011-04-10 18:08:59 +00:00
armin
7eace122dc internal linker support for creating novell netware loadable modules
git-svn-id: trunk@17192 -
2011-03-27 14:47:25 +00:00
florian
f328b6d635 + user section type
+ parsing of section directive for variables
  + section test
  + write section names in the assembler/binary writers correctly
  * allow section only after ; and for embedded targets

git-svn-id: branches/usersections@17154 -
2011-03-20 15:42:28 +00:00
florian
26fbfaf5a7 + introduce the usage of asizeint/asizeuint for cpus with sizeof("alu")<>sizeof(pointer)
git-svn-id: trunk@17011 -
2011-02-26 20:10:03 +00:00
pierre
292e85a59a * Partial fix for i386 linux PIC code generation
git-svn-id: trunk@16080 -
2010-10-05 08:07:15 +00:00
Jonas Maebe
28cd8271c9 * initial version of internal Mach-O/i386 assembler by Dmitry Boyarintsev
(mantis #15163)

git-svn-id: trunk@14628 -
2010-01-12 19:52:55 +00:00
florian
c1f3d8dcaa * unified names of system_*/systems_* sets
git-svn-id: trunk@14566 -
2010-01-07 18:16:20 +00:00
Jonas Maebe
edacea82be * changed assembler directives for darwin lazy/non-lazy symbol pointers
and init/fini routines into their section equivalents (based on patch
    by Dmitry Boyarintsev, mantis #15037)

git-svn-id: trunk@14128 -
2009-11-09 22:20:01 +00:00
Jonas Maebe
0c675a4039 * the objc1 unit has been renamed to objc
* the objc unit links against the Foundation instead of against the Cocoa
    framework, and inludes an interface to either the fragile or non-fragile
    obj-c run time depending on the target platform
  + support for the non-fragile Objective-C runtime/ABI, as used on Mac OS X
    for ARM (iPhone) 64 bit (PowerPC/64, x86_64) -- all these targets now
    are now also supported for the objectivec1 modeswitch
  + support for private_extern symbol bindings, required for the above
  * mark objcclasses that are declared in the implementation section of a
    unit as "hidden" (not sure what the effect is, since the Objective-C
    runtime does not seem to do anything with this flag)
  * enabled all obj-c tests for the newly supported platforms

git-svn-id: branches/objc@13763 -
2009-09-27 15:24:50 +00:00
yury
5cd83b26d9 * More proper check for executable image size limits.
* Proper handling of 64-bit COFF relocations.
* Use jumps with 32-bit relative addressing in imports on win64.
* This fixes are related to bug #13657. The bug is not fully fixed yet...

git-svn-id: trunk@13104 -
2009-05-06 18:07:07 +00:00