msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.25k stars 1.21k forks source link

[binutils] ld --verbose | grep SEARCH_DIR outputs misleading information on mingw-w64 environment #18892

Open DanilaBerezin opened 11 months ago

DanilaBerezin commented 11 months ago

Description / Steps to reproduce the issue

  1. Launch the msys mingw-w64 environment.
  2. Type in ld --verbose | grep SEARCH_DIR and press enter

Similar issues may exist in the other environments, but I haven't tested them.

Expected behavior

Ideally, the command should output the following: SEARCH_DIR("=/mingw64/x86_64-w64-mingw32/lib"); SEARCH_DIR("=/mingw64/lib"); Since these are the actual search paths for ld in the mingw-w64 environment.

Actual behavior

The following is what is output by the command: SEARCH_DIR("=/mingw64/x86_64-w64-mingw32/lib"); SEARCH_DIR("=/mingw64/lib"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");

Verification

Windows Version

MINGW64_NT-10.0-19045

MINGW environments affected

Are you willing to submit a PR?

I can, but I don't know much about ld so it would take me a while.

revelator commented 11 months ago

yeah i been seing the same is actually a really old bug that goes way back to the original mingw that ld's search path also includes the msys or msys2 paths. there was a trick i remember to force it to only search the mingw-w64-* paths ill try to look it up.

DanilaBerezin commented 11 months ago

@revelator damn didn't know that. But yeah it would be really sick to see the workaround

revelator commented 11 months ago

if i remember correctly there is an option in configure to do it, otherwise it was a bit more hacky as you needed to export the search paths in the correct format before building. not sure but i think its behaviour is a remnant from back in the days where the posix tools were part of the compiler itself like in djgpp and the windows port based on it.

revelator commented 11 months ago

found it you need to create a linker script containing the search paths eg. SEARCH_DIR("=/mingw32/i686-w64-mingw32/lib"); SEARCH_DIR("=/mingw32/lib"); then build binutils with gcc -Wl,-T,<path/tolinkerscript>

the = before the path is because our tools use the sysroot option otherwise it would just be SEARCH_DIR("/mingw32/i686-w64-mingw32/lib"); SEARCH_DIR("/mingw32/lib");

DanilaBerezin commented 10 months ago

found it you need to create a linker script containing the search paths eg. SEARCH_DIR("=/mingw32/i686-w64-mingw32/lib"); SEARCH_DIR("=/mingw32/lib"); then build binutils with gcc -Wl,-T,<path/tolinkerscript>

the = before the path is because our tools use the sysroot option otherwise it would just be SEARCH_DIR("/mingw32/i686-w64-mingw32/lib"); SEARCH_DIR("/mingw32/lib");

Nice! I'll take a look at it at some point. But I might not have a lot of time.

revelator commented 10 months ago

might even be enough adding SEARCH_DIR("=$(MINGW_PREFIX)/lib"); seeing as we dont use the cross prefixed compiler path anymore eg. all system libraries are now located in "$(MINGW_PREFIX)/lib" only the linker scripts still reside in "$(MINGW_PREFIX)/$(MINGW_CHOST)/lib"