Menu

Compiling and -flto : help appreciated

Gene C
2022-08-29
2022-08-29
  • Gene C

    Gene C - 2022-08-29

    On Archlinux the gnu-efi library is now compiled with -flto. This causes trouble when the loader used is 'ld' rather than 'gcc'. I understand the reason being that gcc will invoke the appropriate lto plugin whereas ld does not.
    Using ld to link leads to multiple lto related errors.

    Tooling:
    gcc 12.2.0
    binutils 2.39
    gnu-efi 3.0.15
    refind is git master.

    After changing Make.common to use gcc in place of ld, the build makes further progress but than ends up with the error shown below.

    The gnuefi library is an archive (.a) containing a single .o file:
    % ar t /usr/lib/libgnuefi.a
    reloc_x86_64.o
    Extracting it and running file shows:
    foo.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped

    The file referenced below, also provided by gnu-efi is similar:
    file /usr/lib /usr/lib/crt0-efi-x86_64.o
    /usr/lib/crt0-efi-x86_64.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped

    Any suggestions on how to proceed so I can build?
    Unclear to me what needs to be rebuilt -fpic as per gcc below.

    /~~~
    /usr/bin/gcc -L./../libeg/ -L./../mok/ -L./../EfiLib/ -T /usr/lib/elf_x86_64_efi.lds -shared -Bstatic -nostdlib -L/usr/lib -L/usr/lib /usr/lib/crt0-efi-x86_64.o -znocombreloc -zdefs apple.o config.o crc32.o driver_support.o gpt.o icns.o install.o launch_efi.o launch_legacy.o lib.o line_edit.o linux.o log.o main.o menu.o mystrings.o pointer.o scan.o screen.o \
    -o refind_x64.so -leg -lmok -lEfiLib -lefi -lgnuefi /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/libgcc.a
    /usr/bin/ld: /usr/lib/crt0-efi-x86_64.o: warning: relocation against ImageBase' in read-only section.text'
    /usr/bin/ld: /usr/lib/crt0-efi-x86_64.o: relocation R_X86_64_PC32 against symbol `ImageBase' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: final link failed: bad value
    collect2: error: ld returned 1 exit status
    make[1]: *** [Makefile:49: refind_x64.so] Error 1
    ~~~

     

    Last edit: Gene C 2022-08-29
  • Gene C

    Gene C - 2022-08-29

    The arch gnu-efi is compiled with comment:
    NOTE: fat-lto-objects is required for non-mangled (static) object files
    CFLAGS="-O2 -flto -ffat-lto-objects"

    Which explains why I failed trying -fno-lto (as its no longer allowed with above).

    While there may be a better way using the arch compiled lto stuff, I couldn't find it.
    Possibly related to crt0-efi-x86_64 being assembly code not C.

    So, Instead if I simply rebuild gnu-efi without any lto flags and use that - refind builds fine like it usually does. i.e. use instead:
    CFLAGS="-O2"

    Is this a problem with the way gnu-efi was compiled. or is refind able to find a way to work with it?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.