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 Xlinker rpath linker flags deduplication #5778

Closed

Conversation

Arthapz
Copy link
Member

@Arthapz Arthapz commented Nov 1, 2024

got this errors when trying to compile glm package on macOS with modules enabled and homebrew llvm

/usr/local/opt/llvm/bin/clang++ -o /var/folders/1p/6pvxmm0j5gl7xybkqpv74f8h0000gn/T/.xmake501/241101/_888C4D64A9F04E2084417958EBCDF730.b /var/folders/1p/6pvxmm0j5gl7xybkqpv74f8h0000gn/T/.xmake501/241101/_888C4D64A9F04E2084417958EBCDF730.o -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk -stdlib=libc++ -L/usr/local/opt/llvm/lib -rpath -Xlinker /usr/local/opt/llvm/lib -L/Users/arthapz/.xmake/packages/g/glm/1.0.1/9ea4f932f2f3409fa948476625677342/lib -lglm
ld: warning: -rpath missing <path>
ld: warning: -rpath missing <path>
ld: file cannot be mmap()ed, errno=22 path=/usr/local/opt/llvm/lib in '/usr/local/opt/llvm/lib'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
> checking for c++ links(glm)
> checking for c++ snippet(test)

@Arthapz Arthapz force-pushed the fix-xlinker-rpath-deduplication branch 2 times, most recently from 34590d5 to a64735d Compare November 1, 2024 20:40
xmake/core/tool/compiler.lua Outdated Show resolved Hide resolved
@waruqi
Copy link
Member

waruqi commented Nov 2, 2024

you can provide an example, i will test it.

@Arthapz Arthapz force-pushed the fix-xlinker-rpath-deduplication branch from a64735d to d941c63 Compare November 2, 2024 16:02
unique[flagkey] = true
if flagkey:startswith("-l") or flagkey:startswith("-L") or flagkey:startswith("/l") or flagkey:startswith("/L") then
unique[flagkey] = true
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to deduplicate more flags, e.g. -Dxx ...

So we shouldn't do this, hard coding is not universal.

@waruqi
Copy link
Member

waruqi commented Nov 2, 2024

if use table group, this flag will be not deduplicated,

if #flag > 0 then

{{"-x", "dd"}, {"-x", "yy"}}

@Arthapz
Copy link
Member Author

Arthapz commented Nov 2, 2024

you can provide an example, i will test it.

Okay so with an xmake.lua like

add_requires("glm", {configs = {modules = true}})

target("foo")
    set_languages("c++23")
    add_files("src/**.cpp")
    set_policy("build.c++.modules", true)
    add_packages("glm")

and src/main.cpp

import glm;

int main() {
  auto foo = glm::vec2{};
}

i get this output on macOS with brew llvm

> xmake f --toolchain=llvm --sdk=/usr/local/opt/llvm --runtimes=c++_shared --yes -vD
...
> /usr/local/opt/llvm/bin/clang++ -o /var/folders/1p/6pvxmm0j5gl7xybkqpv74f8h0000gn/T/.xmake501/241102/_CFC84609647941008B9ED106C125C040.b /var/folders/1p/6pvxmm0j5gl7xybkqpv74f8h0000gn/T/.xmake501/241102/_CFC84609647941008B9ED106C125C040.o -m64 -isysoot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk -stdlib=libc++ -L/usr/local/opt/llvm/lib -rpath -Xlinker /usr/local/opt/llvm/lib -L/Users/arthapz/.xmake/packages/g/glm/1.0.1/9ea4f932f2f3409fa948476625677342/lib -lglm
ld: warning: -rpath missing <path>
ld: warning: -rpath missing <path>
ld: file cannot be mmap()ed, errno=22 path=/usr/local/opt/llvm/lib in '/usr/local/opt/llvm/lib'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
> checking for c++ links(glm)
> checking for c++ snippet(test)
checkinfo: ...gramdir/core/sandbox/modules/import/core/tool/linker.lua:75: @programdir/core/sandbox/modules/os.lua:378: execv(/usr/local/opt/llvm/bin/clang++ -o /var/folders/1p/6pvxmm0j5gl7xybkqpv74f8h0000gn/T/.xmake501/241102/_CFC84609647941008B9ED106C125C040.b /var/folders/1p/6pvxmm0j5gl7xybkqpv74f8h0000gn/T/.xmake501/241102/_CFC84609647941008B9ED106C125C040.o -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk -stdlib=libc++ -L/usr/local/opt/llvm/lib -rpath -Xlinker /usr/local/opt/llvm/lib -L/Users/arthapz/.xmake/packages/g/glm/1.0.1/9ea4f932f2f3409fa948476625677342/lib -lglm) failed(1)
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:1004]:
    [@programdir/core/sandbox/modules/os.lua:378]: in function 'execv'
    [@programdir/modules/core/tools/gcc.lua:599]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:244]:
    [@programdir/core/tool/linker.lua:232]: in function 'link'
    [...gramdir/core/sandbox/modules/import/core/tool/linker.lua:73]: in function 'link'
    [@programdir/modules/lib/detect/check_cxsnippets.lua:249]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:244]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/lib/detect/check_cxsnippets.lua:236]:
    [.../.xmake/repositories/xmake-repo/packages/g/glm/xmake.lua:59]: in function 'script'
    [...dir/modules/private/action/require/impl/utils/filter.lua:114]: in function 'call'
    [...dir/modules/private/action/require/impl/actions/test.lua:41]:
    [.../modules/private/action/require/impl/actions/install.lua:432]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:244]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [.../modules/private/action/require/impl/actions/install.lua:361]:
    [...modules/private/action/require/impl/install_packages.lua:496]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:241]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:244]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/async/runjobs.lua:223]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

-Xlinker flags from check_cxsnippet is getting deduplicated

-L/usr/local/opt/llvm/lib -rpath -Xlinker /usr/local/opt/llvm/lib

should be

-L/usr/local/opt/llvm/lib -Xlinker -rpath -Xlinker /usr/local/opt/llvm/lib

@Arthapz
Copy link
Member Author

Arthapz commented Nov 2, 2024

if use table group, this flag will be not deduplicated,

if #flag > 0 then

{{"-x", "dd"}, {"-x", "yy"}}

i tried that before, but it broke other things, the xmake f work but

> xmake b
[ 71%]: compiling.release src/main.cpp
/usr/local/opt/llvm/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk -std=c++23 -stdlib=libc++ -cxx-isystem/usr/local/opt/llvm/include/c++/v1 -isystem /Users/arthapz/.xmake/packages/g/glm/1.0.1/9ea4f932f2f3409fa948476625677342/include -fmodule-file=glm=build/.gens/foo/macosx/x86_64/release/rules/bmi/cache/modules/3319d13e/glm.pcm -o build/.objs/foo/macosx/x86_64/release/src/main.cpp.o src/main.cpp
error: invalid value (table) at index 3 in table for 'concat'

@waruqi
Copy link
Member

waruqi commented Nov 4, 2024

try this patch. #5782

@waruqi waruqi added this to the v2.9.7 milestone Nov 4, 2024
@waruqi waruqi closed this Nov 4, 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