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

[Issue]: linker/cxx flags issues #210

Open
AngryLoki opened this issue Jan 2, 2025 · 1 comment · May be fixed by #211
Open

[Issue]: linker/cxx flags issues #210

AngryLoki opened this issue Jan 2, 2025 · 1 comment · May be fixed by #211

Comments

@AngryLoki
Copy link

Problem Description

Hi,
There are multiple non-critical, but annoying issues when building from source:

  1. When clang is used as system compiler, libraries were built without respecting LDFLAGS. For example, this affected LTO flags, if any (and it only affected clang, not gcc).

  2. Linker flags are registered as CXX flags, which produces warnings during compilation:

clang++: warning: -Wl,-z,noexecstack: 'linker' input unused [-Wunused-command-line-argument]
clang++: warning: -Wl,-znoexecheap: 'linker' input unused [-Wunused-command-line-argument]
clang++: warning: -Wl,-z,relro: 'linker' input unused [-Wunused-command-line-argument]
clang++: warning: -Wl,-z,now: 'linker' input unused [-Wunused-command-line-argument]
  1. Clang does not support -Wtrampolines flag:
warning: unknown warning option '-Wtrampolines' [-Wunknown-warning-option]
  1. No linkers support noexecheap anymore. This was mentioned in Unknown linker flag 'noexecheap' for ld.gold #87 which was closed, but the issue is still active. noexecheap linker flag was a part of PaX patches to GNU ld, (which were dropped in 2017)[https://www.gentoo.org/support/news-items/2017-08-19-hardened-sources-removal.html]. Now ld/ld.lld/ld.gold don't support it and protection of heap is managed by NX bit. Therefore every compiler produces this warning:
ld.lld: warning: unknown -z value: noexecheap

Please see linked pull request which fixes these problems.

Operating System

Gentoo

CPU

GPU

ROCm Version

ROCm 6.3.0

ROCm Component

rocm_smi_lib

Steps to Reproduce

No response

(Optional for Linux users) Output of /opt/rocm/bin/rocminfo --support

No response

Additional Information

No response

AngryLoki added a commit to AngryLoki/rocm_smi_lib that referenced this issue Jan 2, 2025
1) When `clang` is used as system compiler, libraries were built without respecting LDFLAGS. For example, this affected LTO flags, if any (and it only affected clang, not gcc).

2) Linker flags are registered as CXX flags, which produces warnings during compilation:
```
clang++: warning: -Wl,-z,noexecstack: 'linker' input unused [-Wunused-command-line-argument]
clang++: warning: -Wl,-znoexecheap: 'linker' input unused [-Wunused-command-line-argument]
clang++: warning: -Wl,-z,relro: 'linker' input unused [-Wunused-command-line-argument]
clang++: warning: -Wl,-z,now: 'linker' input unused [-Wunused-command-line-argument]
```

3) Clang does not support `-Wtrampolines` flag:
```
warning: unknown warning option '-Wtrampolines' [-Wunknown-warning-option]
```

4) No linkers support `noexecheap` anymore. `noexecheap` linker flag was a part of PaX patches to GNU ld, (which were dropped in 2017)[https://www.gentoo.org/support/news-items/2017-08-19-hardened-sources-removal.html]. Now ld/ld.lld/ld.gold don't support it and protection of heap is managed by NX bit. Therefore every compiler produces this warning:
```
ld.lld: warning: unknown -z value: noexecheap
```

Closes ROCm#210.
@AngryLoki AngryLoki linked a pull request Jan 2, 2025 that will close this issue
@DustyOnly
Copy link

The Issues:
LDFLAGS Not Being Used: The linker flags (LDFLAGS) aren't being respected when using Clang, especially for optimizations like LTO (Link Time Optimization).
Unnecessary Warnings: Some linker flags are being passed incorrectly as compiler flags, causing Clang to throw warnings.
Unsupported Flags: Certain flags, like -Wtrampolines, -znoexecheap, and -zrelro, are no longer supported by modern linkers.
How to Fix It:
Make Sure LDFLAGS are Used:

Sometimes the build system (like CMake or Make) doesn't pass LDFLAGS correctly. You can manually set them before building:
bash
Zkopírovat kód
export LDFLAGS="-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now"
make
Fix the Linker Flag Warnings:

It seems linker flags like -znoexecheap are being treated as compiler flags (CXXFLAGS), which causes warnings.
If you're using CMake, add this line to separate linker flags from compiler flags:
cmake
Zkopírovat kód
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
Remove Unsupported Flags:

The flags -Wtrampolines and -znoexecheap are no longer needed and cause warnings.
Remove these flags from your build settings, as modern linkers (like ld.lld and ld.gold) don’t support them anymore.
Use the Latest Version:

If you're still facing these issues, make sure you're using the latest version of the ROCm libraries. Sometimes these problems get fixed in newer versions.
Quick Steps:
Check and update the CMakeLists.txt or Makefile to remove old flags.
Set LDFLAGS manually if needed.
Look for any updated patches for your build (since you're using Gentoo, there might be patches that make things easier).

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 a pull request may close this issue.

2 participants