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

Fix search order in INPUT and GROUP of script #1217

Closed
wants to merge 1 commit into from

Conversation

demin-han
Copy link

The scenario is from incremental cross compiling gcc. libgcc_s.so is a ld script in my OS.
GROUP ( libgcc_s.so.1 -lgcc )
The path of libgcc_s.so.1 is not absolute.
When current directory contains libgcc_s.so.1 of other ISA, We will get target of other ISA and report "skipping incompatible file".

As ld manual shows:
If a sysroot prefix is not used then the linker will try to open the file in the directory containing the linker script. If it is not found the linker will then search the current directory. If it is still not found the linker will search through the archive library search path.

@demin-han
Copy link
Author

CI failed because of "No space left on device"

The scenario is from incremental cross compiling gcc.
libgcc_s.so is a ld script in my OS.
  GROUP ( libgcc_s.so.1 -lgcc )
The path of libgcc_s.so.1 is not absolute.
When current directory contains libgcc_s.so.1 of other ISA,
We will get target of other ISA and report "skipping incompatible file".

As ld manual shows:
If a sysroot prefix is not used then the linker will try to open
the file in the directory containing the linker script.
If it is not found the linker will then search the current directory.
If it is still not found the linker will search through the archive library search path.
@demin-han
Copy link
Author

@rui314
linker-script-relocatable.sh failed in all other ISAs.
The reason:
open_library checks machine_type.
resolve_path calls open_library.
get_script_output_type reuses resolve_path in this pr.
deduce_machine_type failed first.

which is the best way to solve this?

  1. add check_machine parameter to functions or
  2. add check_machine flag to Context

rui314 added a commit that referenced this pull request Mar 19, 2024
@rui314
Copy link
Owner

rui314 commented Mar 19, 2024

Does the above commit fix the problem for you?

@demin-han
Copy link
Author

demin-han commented Mar 19, 2024

Does the above commit fix the problem for you?

No, the commit not fix the problem.

get_script_output_type still uses "open" function and open the library existed in current directory.

if (tok.size() >= 3 && (tok[0] == "INPUT" || tok[0] == "GROUP") && tok[1] == "(") if (MappedFile<Context<E>> *mf = MappedFile<Context<E>>::open(ctx, std::string(unquote(tok[2])))) return get_machine_type(ctx, mf);

@rui314
Copy link
Owner

rui314 commented Mar 19, 2024

Can you write a test to demonstrate the issue?

@demin-han
Copy link
Author

demin-han commented Mar 19, 2024

Can you write a test to demonstrate the issue?

My OS is Manjaro. The minimal requirements as following:

  1. the /usr/lib/libgcc_s.so should contains following content:
    /* GNU ld script
    Use the shared library, but some functions are only in
    the static library. */
    GROUP ( libgcc_s.so.1 -lgcc )
  2. mkdir test
  3. write a test.c in test directory
    int main() {}
  4. copy libgcc_s.so.1 of riscv64(or other ISA) to test directory
  5. gcc -fuse-lld=mold test.c
  6. following error reported:
    mold: warning: /usr/lib/libgcc_s.so: skipping incompatible file riscv64 62
    mold: warning: /lib/libgcc_s.so: skipping incompatible file riscv64 62
    mold: warning: /usr/lib/libgcc_s.so: skipping incompatible file riscv64 62
    mold: warning: /usr/lib//libgcc_s.so: skipping incompatible file riscv64 62
    mold: fatal: library not found: gcc_s

The call trace :
mold::MappedFile<mold::elf::Contextmold::elf::X86_64 >::open(mold::elf::Contextmold::elf::X86_64&,
std::__cxx11::basic_string<char, std::char_traits, std::allocator >)
mold::elf::get_script_output_typemold::elf::X86_64(mold::elf::Contextmold::elf::X86_64&,
mold::MappedFile<mold::elf::Contextmold::elf::X86_64 >)
mold::elf::get_machine_typemold::elf::X86_64(mold::elf::Contextmold::elf::X86_64&,
mold::MappedFile<mold::elf::Contextmold::elf::X86_64 >
)
mold::elf::open_librarymold::elf::X86_64(mold::elf::Contextmold::elf::X86_64&, std::__cxx11::basic_string<char,
std::char_traits, std::allocator >)
mold::elf::find_librarymold::elf::X86_64(mold::elf::Contextmold::elf::X86_64&, std::__cxx11::basic_string<char,
std::char_traits, std::allocator >)
mold::elf::read_input_filesmold::elf::X86_64(mold::elf::Contextmold::elf::X86_64&,
std::span<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, 18446744073709551615ul>)
mold::elf::elf_mainmold::elf::X86_64(int, char**)
mold::elf::main(int, char**)
main(int, char**)

@demin-han
Copy link
Author

Can you reproduce the problem with the minimal requirement?

@rui314
Copy link
Owner

rui314 commented Mar 20, 2024

I think I understood the issue. I'm preparing a fix.

rui314 added a commit that referenced this pull request Mar 25, 2024
@rui314
Copy link
Owner

rui314 commented Mar 25, 2024

Can you try again with the above change?

@demin-han
Copy link
Author

Can you try again with the above change?

It's OK now.

@rui314
Copy link
Owner

rui314 commented Mar 25, 2024

Cool, thank you for confirming!

@rui314 rui314 closed this Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants