Commit Graph

119 Commits

Author SHA1 Message Date
sergei
6023f73e2a * ELF linker: improved dynamic symbol handling.
+ Read .gnu.version sections and ignore local symbols and symbols with non-current version.
  + Check that external symbols are actually present in dynamic objects.

git-svn-id: trunk@22832 -
2012-10-23 15:16:10 +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
339d06aa58 * When writing section names of .o files, let sh_name of sections with relocations point into names of corresponding relocation sections past the .rel/.rela prefix. In case of smartlinked sections this saves almost half of .shstrtab section size.
* Fixed writing of weak defined symbols, TLS and GNU_IFUNC symbols.

git-svn-id: trunk@22665 -
2012-10-16 10:21:21 +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
c529356693 * Split most CPU-specific code from ogelf.pas into newly created cpuelf.pas units in CPU subdirectories.
git-svn-id: trunk@22208 -
2012-08-23 11:49:49 +00:00
sergei
f14e038172 + Implemented writeReloc_internal method for TElfObjSection.
+ TElfSymtab.writeInternalSymbol: added 'aValue' argument, needed for writing dynamic symbols.

git-svn-id: trunk@22087 -
2012-08-15 12:27:32 +00:00
sergei
95535ea845 - Do not create any default object sections. On targets with section-based smartlink these sections remain empty and only cause linker to do useless job of removing them. The same happens when loading object files because duplicate section names are allowed at that time. On targets without smartlink they don't stay empty, but the internal assembler creates sections when required, so not creating initial sections effectively doesn't change anything.
git-svn-id: trunk@22049 -
2012-08-09 17:12:39 +00:00
sergei
944189f046 - don't supply sh_link and sh_info members to TElfObjSection.create_ext.
+ Dedicated constructor TElfObjSection.create_reloc for relocation sections.
+ pass symbol name offset separately to TElfSymtab.writeSymbol, this is necessary for two-pass writing of dynamic symbol tables.

git-svn-id: trunk@21989 -
2012-07-31 07:44:10 +00:00
sergei
d4b7a6a9bd + Added some more ELF definitions
* Factored telfreloc.info calculation into separate function

git-svn-id: trunk@21988 -
2012-07-31 07:11:10 +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
27f342225a * Changed most fields of ELF structures to unsigned, to conform to their official declarations.
git-svn-id: trunk@21845 -
2012-07-10 13:03:17 +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
37b8cd1b7a * If relocation to a local label cannot be translated into (section+offset), then the target symbol must be written into symbol table. Fixes IE 200603012 in number of tests with -Cg on i386-linux (and possibly other targets with internal ELF assembler).
git-svn-id: trunk@21759 -
2012-07-02 15:43:33 +00:00
sergei
1284be72ea * Fixed alignment of '.data' section, which got accidentally changed from 16 to 8 by r21374, causing e.g. tests/test/tasm3.pp to crash if compiled without -Cg and on target without tf_smartlink_sections. The root problem is not here, however: if appending data with higher alignment to a section with lower alignment, we likely need to raise the alignment of section.
git-svn-id: trunk@21731 -
2012-06-28 18:35:34 +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
85f6062e05 * Reworked writing ELF symbols into a separate class, TElfSymtab, which is also suitable for creating symbol tables in executable and dynamic ELF files.
* Do not write ELF symbols for internal sections (symbol/string table, relocation sections and alike).

git-svn-id: trunk@21592 -
2012-06-13 16:40:50 +00:00
sergei
d0df2b247b * ogelf.pas: pass objdata into TElfObjSection.create_ext, so sections created via create_ext are 'owned' the same way as ones created via objData.CreateSection.
* cpu_soft -> fpu_soft

git-svn-id: trunk@21581 -
2012-06-11 13:02:35 +00:00
sergei
cc5fda2a1e + ogelf.pas: added definitions for program headers and .dynamic section, and reformatted existing ones to reduce line count.
git-svn-id: trunk@21580 -
2012-06-11 12:41:48 +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
263b46be86 * ogelf.pas: Changed MaybeSwap* into procedures, makes them more suitable for reuse in the upcoming reader (and reduces amount of copying while writing, too).
git-svn-id: trunk@21484 -
2012-06-04 10:27:14 +00:00
sergei
747cd55b09 * Fixed 64-bit ELF program header definition (field order is different from 32-bit counterpart!)
* Factored values used in the ELF header into constants, so they can be reused when reading object files.
* Writing first 16 bytes of ELF header should be endian-neutral.
* Section symbols must have st_name equal to zero, using section shstridx is incorrect because it is an index into .shstrtab, not into .strtab (actually written content is unchanged, because section_write_symbol is called while shstridx is still zero).

git-svn-id: trunk@21455 -
2012-06-02 11:35:12 +00:00
sergei
14d66a64a4 + Definitions and utility functions for executable ELF files
git-svn-id: trunk@21441 -
2012-05-31 09:23:35 +00:00
sergei
71c8b9cf8a * ogelf.pas: cleaned up code that creates default sections.
git-svn-id: trunk@21374 -
2012-05-23 14:21:44 +00:00
Jonas Maebe
14cfe770a4 * replaced most (if not all) remaining fields/parameters in the compiler
that deal with paths/filenames with TPathStr (= ansistring) to prevent
    cutting off long paths (no change in speed when compiling the compiler,
    1% extra memory usage)

git-svn-id: trunk@21120 -
2012-04-29 17:36:23 +00:00
sergei
cd89a90841 * Cleanup: removed empty destructors and redundant 'with' statement.
* Removed TElfObjectOutput.Elf32data field, passing ObjData to methods in parameter, similar to how COFF output works.

git-svn-id: trunk@21080 -
2012-04-27 13:42:38 +00:00
Jonas Maebe
ac43eb9b70 + generic implementation of ReplaceForbiddenAsmSymbolChars() instead
of the AVR-specific ifdef'ed variant
   o since the only special character we use in mangled names on all platforms
     is $, added a new field to tasminfo called "dollarsign" that holds the
     character $'s should be replaced with (if it doesn't have to be replaced,
     leave it at $)

git-svn-id: trunk@20801 -
2012-04-11 18:01:57 +00:00
pierre
06c362c02f Accept x86_64_netbsd system for elf64 object writer
git-svn-id: trunk@20744 -
2012-04-07 15:53:36 +00:00
pierre
58ef9b63dd Accept i386/x86_64 openbsd systems for elf object writer
git-svn-id: trunk@20718 -
2012-04-05 21:10:43 +00:00
pierre
98c7a5e4b0 * Enable internal elf writer for freebsd x86_64 target
git-svn-id: trunk@19608 -
2011-11-08 14:05:57 +00:00
sergei
6ee77d9088 + ogelf.pas: support relocation of type R_X86_64_32 which is apparently used by DWARF3 debug info.
git-svn-id: trunk@19258 -
2011-09-27 20:38:10 +00:00
sergei
e3050439a8 * Reverted r17556 and replaced it with more generic handling of 'rela'-styled relocations. Resolves #19416.
+ Test case added to existing test/ulib2a.pp.

git-svn-id: trunk@17580 -
2011-05-27 18:19:08 +00:00
sergei
9c27a802a0 * When relocating local symbols on x86_64, put symbol address into addend field of the relocation, resolves #13671.
+ test

git-svn-id: trunk@17556 -
2011-05-25 16:18:04 +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
0be59445f8 + basic i386-embedded implementation for multiboot by Jeppe Johansen, resolves #15676
git-svn-id: trunk@16801 -
2011-01-23 11:18:50 +00:00
pierre
d2939bce3d * i386 _GLOBAL_OFFSET_TABLE_ label special treatment moved to taicpu.pass2
git-svn-id: trunk@16100 -
2010-10-07 14:14:25 +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
pierre
0083fc3e3d * Avoid overflow error
git-svn-id: trunk@15922 -
2010-08-30 12:48:54 +00:00
florian
c1f3d8dcaa * unified names of system_*/systems_* sets
git-svn-id: trunk@14566 -
2010-01-07 18:16:20 +00:00
pierre
0687f16a04 * Accept weak for Solaris targets
git-svn-id: trunk@14224 -
2009-11-20 11:06:50 +00:00
pierre
791c165af9 * Use ELF assembler for i386/Solaris target
git-svn-id: trunk@14208 -
2009-11-18 10:50:11 +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
Jonas Maebe
6165536b5e + added {$modeswitch objectivec1}/-Mobjectivec1 mode switch to enable
the use of Objective-C 1.0 constructs. Because it is a mode switch, it
    can be used cumulatively with every syntax mode. Note that a {$mode xxx}
    statement resets all mode switches as well, so you cannot use the
    -Mobjectivec1 variant if you have such a statement in a unit. This
    modeswitch is currently only enabled for Darwin/PowerPC and Darwin/i386,
    as the backend support is not yet implemented for other platforms.
  + implemented selector() statement that can be used to create an Objective-C
    selector for the message with the specified *constant* name (in the future,
    it will also work for Objective-C method identifiers)
  + added SEL type to the system unit (the selector() statement returns it)
  + added all Objective-C segments to the assembler writers
  + (currently mostly dummy) objc1 unit that is automatically included if the
    {$modeswitch objectivec1} statement is used
  + some tests for the selector() statement

git-svn-id: trunk@12870 -
2009-03-08 18:40:32 +00:00
Jonas Maebe
b1c3f76ff9 * changed the supported targets for assembler writers to a set, and
(hopefully correctly) limited all assembler writers to only the
    OSes they support (mantis #11801)

git-svn-id: trunk@12622 -
2009-01-28 15:12:43 +00:00
Jonas Maebe
3216e8c7bc * mark produced object files as "does not require executable stack" by
default for Linux (overridable using -WX switch) (mantis #11563)

git-svn-id: trunk@12356 -
2008-12-12 16:26:25 +00:00
yury
4cabbe0e39 * Fixed compiler cycling with enabled range and overflow checking.
git-svn-id: trunk@11489 -
2008-07-29 21:11:03 +00:00
yury
5e11e697b4 * Use unsigned integers for sizes and positions to break 2GB limit in tdynamicarray, object writer, internal linker, coff and PE headers.
git-svn-id: trunk@11480 -
2008-07-28 20:29:25 +00:00
yury
fd0ed50331 * Removed/commented more unused variables.
* Fixed some uninitialized variable warnings.

git-svn-id: trunk@11442 -
2008-07-23 10:48:53 +00:00
peter
a9c9ca0115 * set elf flags for soft float on arm
git-svn-id: trunk@10560 -
2008-03-25 16:15:15 +00:00
Jonas Maebe
f36e5411af * split cpu64bit compiler define into
a) cpu64bitaddr, which means that we are generating a compiler which
       will generate code for targets with a 64 bit address space/abi
    b) cpu64bitalu, which means that we are generating a compiler which
       will generate code for a cpu with support for 64 bit integer
       operations (possibly running in a 32 bit address space, depending
       on the cpu64bitaddr define)
   All cpus which had cpu64bit set now have both the above defines set,
   and none of the 32 bit cpus have cpu64bitalu set (and none will
   compile with it currently)
  + pint and puint types, similar to aint/aword (not pword because that
    that conflicts with pword=^word)
  * several changes from aint/aword to pint/pword
  * some changes of tcgsize2size[OS_INT] to sizeof(pint)

git-svn-id: trunk@10320 -
2008-02-13 20:44:00 +00:00