* module/system/vm/linker.scm (find-shstrndx): Check whether NAME is
lower than the length of BV; remove 'false-if-exception' around
'string-table-ref' call.
* module/system/vm/linker.scm (*lcm-page-size*): Rename
from *page-size*, change to 64 KB.
* libguile/loader.c (load_thunk_from_memory): Only require page size
alignment, knowing that although Guile might emit ELF with 64k
alignment, it only really needs page alignment.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.