1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00
Commit graph

9 commits

Author SHA1 Message Date
Andy Wingo
9e1c07bda6 Assembler works on byte offsets, not u32 offsets
* module/system/vm/assembler.scm (u32-ref, u32-set!, s32-ref, s32-set!):
  Remove these helpers.
* module/system/vm/assembler.scm (<asm>): Track offsets in bytes, not
  u32 units.
  (emit, assembler, process-relocs, process-labels, link-text-object)
  (link-frame-maps, link-symtab, write-arities, link-docstrs)
  (link-procprops, link-debug): Adapt.

* module/system/vm/linker.scm (process-reloc): Add addend before
  dividing by 4 for rel32/4 symbols.
2015-12-26 22:12:09 +01:00
Andy Wingo
26c19d79d9 PT_DYNAMIC inside some other PT_LOAD segment
* libguile/loader.c (load_thunk_from_memory): Only load PT_LOAD
  segments, as libc does.  The PT_DYNAMIC segment should be inside some
  other PT_LOAD segment.

* module/system/vm/linker.scm (segment-kind): Give the .dynamic segment
  PT_LOAD kind, so that it is written in a PT_LOAD segment.
  (count-segments): Add one if there is a SHT_DYNAMIC segment.
  (allocate-segment): Set the paddr to the addr, as binutils do.
  (record-special-segments): New routine, to write out special segments
  like PT_DYNAMIC.
  (allocate-elf): Call record-special-segments.
2014-02-17 14:15:34 +01:00
Andy Wingo
c90c81898e ELF linker can produce objects with native ABI
* module/system/vm/elf.scm: Define more ABI types and ELF object types.
  Export the ABI, object type, and machine type values.

* module/system/vm/linker.scm (<linker-reloc>, process-reloc): Allow
  rel32/1 relocs.
  (add-elf-objects, allocate-elf, link-elf): Allow the user to set an
  ABI, type, and machine-type.
2014-02-16 12:18:44 +01:00
Andy Wingo
812c83d48b Fix section table writing for non-loadable sections
* module/system/vm/linker.scm (add-elf-objects): Don't fill in the
  sh_addr field if the section is not loadable.
2013-12-10 20:03:59 +01:00
Andy Wingo
a236867dc1 Non-loadable sections should not have an sh_addr field set
* module/system/vm/linker.scm (relocate-section-header):
  (write-linker-object): Sections that are not loadable should not have
  their sh_addr fields set.  Fix.
2013-12-10 19:49:56 +01:00
Andy Wingo
f5473fbaaf linker string tables are stateful objects
* module/system/vm/linker.scm (make-string-table): Rework to be a
  stateful object instead of a function object.  Works better in this
  case.  Adapt users.
  (string-table-intern!): Rename from string-table-intern, and just
  return the index of the string.
  (link-string-table!): Rename from link-string-table, and set a flag to
  prevent interning strings after linking, as that's not going to work
  well.

* module/language/objcode/elf.scm (bytecode->elf): Adapt.
2013-06-09 16:04:12 +02:00
Andy Wingo
d4da9ba9c0 refactor linker to lay out ELF files and memory in the same way
* module/system/vm/linker.scm (make-linker-object):
  (linker-object-section-symbol):
  (linker-object-symbols*): Create a symbol to the start of a linker
  object.  Hide it from the external linker-object-symbols* accessor.

  (segment-kind, count-segments): Sections without SHF_ALLOC don't get
  segments.
  (collate-objects-into-segments): Allow for #f segment types.  If two
  sections have the same type and flags, leave them in the same order.

  (align): Allow for 0 alignment.

  (add-elf-objects): New helper: puts the ELF data structures (header,
  segment table, and section table) in sections of their own.  This
  lends a nice clarity and conceptual unity to the linker.

  (relocate-section-header, allocate-segment): Lay out segments with
  congruent, contiguous addresses, so that we can just mmap the file and
  if debugging sections that are not in segments are present, they can
  be lazily paged in if needed by the kernel's VM system.

  (link-elf): Refactor to use the new interfaces.

* test-suite/tests/linker.test: Update to expect the additional sections
  for the header and section table.
2013-05-23 12:44:02 +02:00
Andy Wingo
6756d265ed ELF refactor and consequent linker simplifications
* module/system/vm/elf.scm: Add commentary.
  (make-elf): Add a constructor similar to make-elf-segment and
  make-elf-section.
  (write-elf32-header, write-elf64-header, write-elf-header): Take an
  <elf> instead of all the fields separately.
  (<elf-segment>, <elf-section>): Add "index" property.  Adapt
  constructors accordingly.

* module/language/objcode/elf.scm (bytecode->elf): Arrange to set the
  section indexes when creating ELF sections.

* module/system/vm/linker.scm (fold-values): New helper.
  (alloc-segment, relocate-section-header): Arrange to set segment and
  section indexes.
  (find-shstrndx): New helper, replaces compute-sections-by-name.  Now
  that sections know their indexes, this is easier.
  (allocate-elf, write-elf): New helpers, factored out of link-elf.
  Easier now that sections have indexes.
  (link-elf): Simplify.  Check that the incoming objects have sensible
  numbers.

* test-suite/tests/linker.test: Update to set #:index on the linker
  objects.
2013-05-23 11:02:02 +02:00
Andy Wingo
45037e7527 split linker out of elf module
* module/Makefile.am:
* module/system/vm/linker.scm: New file, split out of (system vm elf).
  (make-string-table, string-table-intern): Export under their bare
  names, instead of make-elf-string-table and elf-string-table-intern.

* module/system/vm/elf.scm: Remove linking capabilities.
  (string-table-ref): Export.

* module/language/objcode/elf.scm (bytecode->elf): Adapt to use (system
  vm linker).

* test-suite/tests/linker.test: New test.
2013-05-23 09:42:04 +02:00