llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.57k stars 11.81k forks source link

clang passes --plugin-opt=Os to the linker #35243

Open rui314 opened 6 years ago

rui314 commented 6 years ago
Bugzilla Link 35895
Version unspecified
OS Windows NT
CC @pawelsopensource

Extended Description

Clang passes -plugin-opt=Os to lld when LTO is enabled and -Os is passed. lld does not recognize the flag. It shows the following error message:

ld.lld: error: --plugin-opt: number expected, but got 's'

llvmbot commented 2 years ago

mentioned in issue llvm/llvm-bugzilla-archive#36035

llvmbot commented 6 years ago

Lets reassign to clang for now as both lld and the gold plugin reject this.

llvmbot commented 6 years ago

Is there any issue here? Seems invalid for me.

llvmbot commented 6 years ago

Should it work with gold ? Does not work for me, looks like expected behavior actually:

~/LLVM/build_goldplugin/bin/clang -fuse-ld=gold -Os -flto=thin 1.cpp -o out -v

...

"/usr/local/bin/ld.gold" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o out /usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/7.2.0/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/7.2.0 -L/usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../.. -L/home/umb/LLVM/build_goldplugin/bin/../lib -L/lib -L/usr/lib -plugin /home/umb/LLVM/build_goldplugin/bin/../lib/LLVMgold.so -plugin-opt=mcpu=x86-64 -plugin-opt=Os -plugin-opt=thinlto /tmp/1-f9536b.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/7.2.0/crtend.o /usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../../x86_64-linux-gnu/crtn.o /usr/local/bin/ld.gold: fatal error: Optimization level must be between 0 and 3 clang-7.0: error: linker command failed with exit code 1 (use -v to see invocation)

rui314 commented 6 years ago

What I do not understand is that gold plugin doesn't take -plugin-opt=Os as well.

https://github.com/llvm-project/llvm-project-20170507/blob/f3e906e172cc0bd090b6358859946c99851a9a41/llvm/tools/gold/gold-plugin.cpp#L232

How does it work?

llvmbot commented 6 years ago

there's no Os for LTO, as far as I can tell. So you can probably ignore?