Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to enable linking with LLVM/lld #173

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Commits on Jan 15, 2024

  1. tls_rootserver.lds: Add NOLOAD to .tbss section

    Like .bss, .tbss needs explicit NONLOAD to ensure they are not
    allocated/loaded in the ELF image.
    
    Sponsored by: DARPA.
    
    Signed-off-by: Hesham Almatary <[email protected]>
    heshamelmatary committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    c85d38f View commit details
    Browse the repository at this point in the history
  2. elfloader/linker: Retain _driver_list section

    unused attribute does not prevent the section from being
    garbage-collected during link-time optimisation. This may trigger
    undefined references errors to [__start|__stop]_driver_list symbols
    that are expected to be emitted by the linker anyway.
    
    Adding "retain" attribute makes sure that the section and its
    associated symbols are kept regardless of linker's garbage
    collection. Another fix could be adding "nostart-stop-gc" to the
    linker flags, but since it is only one section (_driver_list)
    where its __start/__stop symbols are references, adding retain to
    it makes more sense. This additional functionality requires
    binutils version 2.36 or later.
    
    Sponsored by: DARPA.
    
    Signed-off-by: Hesham Almatary <[email protected]>
    heshamelmatary committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    921184a View commit details
    Browse the repository at this point in the history
  3. elfloader/linker: Add NOLOAD to .bss

    Most linkers heuristically recognise common section names and
    apply the proper flags to them. .[t]bss sections for example
    should be recognised and linkers mark them ALLOC, NOLOAD,
    which means that they don't occupy space in the ELF image
    and shouldn't be loaded at run-time, but they should be
    allocated space at run-time in the process image when loaded.
    
    Adding NOLOAD (similar to the seL4's kernel) is good for
    intentionality, and for linkers that might not automatically
    flag .[t]bss at NOLOAD.
    
    Sponsored by: DARPA.
    
    Signed-off-by: Hesham Almatary <[email protected]>
    heshamelmatary committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    76236d3 View commit details
    Browse the repository at this point in the history
  4. elfloader/linker: Fix arithmetic in the linker script

    Linker's operators precedence [1] which follows C makes "+" higher than
    shifting "<<". Thus, ". + CONFIG_MAX_NODES" will be shifted by 12 in this
    case, which is wrong and is not the intended behavior.
    In lld (which properly implements C's operators precedence, unlike ld.bfd),
    the arithmetic results in a significant value.
    
    The outcome is either a huge ELF file size, or a linking error
    (e.g., relocation R_AARCH64_ADR_PREL_PG_HI21 out of range).
    
    This commit fixes the arithmetic and uses += which is more portable.
    
    [1] https://sourceware.org/binutils/docs/ld.html
    
    Sponsored by: DARPA.
    
    Signed-off-by: Hesham Almatary <[email protected]>
    heshamelmatary committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    db8d245 View commit details
    Browse the repository at this point in the history
  5. elfloader/linker: Unify linker.lds in one file

    This allows to use the same file for both Arm and RISC-V.
    Furthermore, this new file is more portable and works with
    both LLVM/lld and GNU's ld, unlike the removed Arm's one
    which contains directives and sections that lld does not
    handle (e.g., .interp, INSERT BEFORE .hash).
    
    Signed-off-by: Hesham Almatary <[email protected]>
    heshamelmatary committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    843b0c9 View commit details
    Browse the repository at this point in the history