-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL][CMake] Fix and apply hardening flags to sycl-rel-6_2
#19444
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
[SYCL][CMake] Fix and apply hardening flags to sycl-rel-6_2
#19444
Conversation
CMake has a notion of scopes for variables and we fell into a pitfall of setting local variables instead of applying changes globally to the whole project. For reference, see: - https://cmake.org/cmake/help/v3.20/command/set.html - https://cmake.org/cmake/help/v3.20/command/include.html
Co-authored-by: Alexey Sachkov <[email protected]>
CMake is capable of setting `-fPIE` correctly and we don't need to intervene with that. Without the patch, I see the following errors: ``` FAILED: lib/libze_trace_collector.so : && /usr/bin/clang++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite -strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wextra -fcf-protection=full -Wformat -Wformat-security -fPIC -fPIE -Wno-covered-switch-default -Wall -Wextra -Werror -O2 -g -DNDEBUG -Wl,-z,defs -Wl,-z,nodelete -pie -shared -Wl,-soname,libze_ trace_collector.so -o lib/libze_trace_collector.so tools/sycl/tools/sycl-trace/CMakeFiles/ze_trace_collector.dir/ze_trace_collector.cpp.o -Wl,-rpath,build/lib: lib/libxptifw.so -ldl && : clang++: error: argument unused during compilation: '-pie' [-Werror,-Wunused-command-line-argument] ```
We can't have this flag being applied globally, because it then affects SYCL RT which has plenty of libraries that are supposed to be `dlopen`ed by design. It probably makes sense to apply `nodlopen` for some of our executables, but that should be done on a case-by-case basis. For now, let's just fix the toolchain with hardening flags applied, any improvements can be done as a follow-up later.
The problem here is that the macro is actually handled by glibc and value `3` isn't supported with older compiler/glibc combinations, causing warnings about the macro redefinition. We still have to support older compilers/glibc and therefore two changes were made: - UR skips setting their own `_FORTIFY_SOURCE` in favor of a global one if it is built as part of LLVM (i.e. not standalone) - Before setting `_FORTIFY_SOURCE` globally we check the compiler and fallback to value `2` for older gcc
This reverts commit 00eb54c.
Notes for reviewers: Additional changes which have not been applied to the
I didn't put those commit references to the PR description, because they will be useless in the final squashed commit that will go into the repo. You can also see more commits in this PR, but this was a process of some trial and error in figuring out the best approach at getting the project buildable with hardening flags enabled. They were all effectively reverted and all changes that remained are outlined above. I also ran nightly validation for this PR to increase scope of testing here: https://github.com/intel/llvm/actions/runs/16271004049 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configure.py lgtm
We rely on CMake to set the right set of compliation and link flags to enable positition independent code and position independent execution. Before this commit, necessary compliation flags were applied just fine, but link flags were missing. To get link flags, some extra CMake functions should be called.
An updated nightly validation run which includes the new cherry-picked commit about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Pre-commit on this release branch isn't fully configured, because some CI scripts are out-of-date. However, I did perform nightly validation on the PR and its results were good, I will proceed with the merge |
This PR contains several cherry-picks and some unique changes which have not been applied to the
sycl
branch yet.The intent of this PR is to enable as much (quickly) possible hardening flags to be in better compliance with our SDL requirements.
The main thing this PR is after are things like immediate bindings, fortify source, stack protection and
relro
.The thing that this PR is not after are extra warning flags - some of them we can't apply globally because LLVM itself isn't warning free, some of them we can't apply even locally to SYCL RT because we haven't fixed corresponding warnings yet.
Patches which were cherry-picked from the
sycl
branch:-fPIE
handling #19235)nodlopen
from hardening flags #19357)-pie
hardening flag #19447)Additional changes which have not been applied to the
sycl
branch:configure.py
to the new way of-fPIE
handling/sdl
flag because LLVM isn't warning-freesycl
branch for future releases/analyze
flag because SYCL RT isn't warning-freesycl
branch for future releases