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

[compiler-rt] Avoid assertions when using LLVM_ENABLE_PER_TARGET_RUNTIME_DIR #90127

Conversation

ilovepi
Copy link
Contributor

@ilovepi ilovepi commented Apr 25, 2024

Previously, the memprof and ctx_profile lit.site.cfg would assert
if the enable_per_target_runtime_dir was set and the
config.target_arch != config.host_arch. However, config.host_arch would
never be set, meaning this would always fail in a when using
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR.

This patch follows the example in the ASAN lit.site.cfg.py that updates
the compiler_rt_libdir appropriately.

Created using spr 1.3.4
@llvmbot llvmbot added compiler-rt PGO Profile Guided Optimizations labels Apr 25, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 25, 2024

@llvm/pr-subscribers-pgo

Author: Paul Kirth (ilovepi)

Changes

Previously, the memprof and ctx_profile lit.site.cfg would assert
if the enable_per_target_runtime_dir was set and the
config.target_arch != config.host_arch. However, config.host_arch would
never be set, meaning this would always fail in a when using
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR.

This patch follows the example in the ASAN lit.site.cfg.py that updates
the compiler_rt_libdir appropriately.


Full diff: https://github.com/llvm/llvm-project/pull/90127.diff

2 Files Affected:

  • (modified) compiler-rt/test/ctx_profile/Unit/lit.site.cfg.py.in (+8-4)
  • (modified) compiler-rt/test/memprof/Unit/lit.site.cfg.py.in (+8-5)
diff --git a/compiler-rt/test/ctx_profile/Unit/lit.site.cfg.py.in b/compiler-rt/test/ctx_profile/Unit/lit.site.cfg.py.in
index 32a8c48e9c1c79..bf586bfab55237 100644
--- a/compiler-rt/test/ctx_profile/Unit/lit.site.cfg.py.in
+++ b/compiler-rt/test/ctx_profile/Unit/lit.site.cfg.py.in
@@ -21,7 +21,11 @@ config.test_source_root = config.test_exec_root
 # When LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on, the initial value of
 # config.compiler_rt_libdir (COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR) has the
 # host triple as the trailing path component. The value is incorrect for i386
-# tests on x86_64 hosts and vice versa. But, since only x86_64 is enabled as
-# target, and we don't support different environments for building and,
-# respectivelly, running tests, we shouldn't see this case.
-assert not config.enable_per_target_runtime_dir or config.target_arch == config.host_arch
+# tests on x86_64 hosts and vice versa. Adjust config.compiler_rt_libdir
+# accordingly.
+if config.enable_per_target_runtime_dir and config.target_arch != config.host_arch:
+    if config.target_arch == 'i386':
+        config.compiler_rt_libdir = re.sub(r'/x86_64(?=-[^/]+$)', '/i386', config.compiler_rt_libdir)
+    elif config.target_arch == 'x86_64':
+        config.compiler_rt_libdir = re.sub(r'/i386(?=-[^/]+$)', '/x86_64', config.compiler_rt_libdir)
+
diff --git a/compiler-rt/test/memprof/Unit/lit.site.cfg.py.in b/compiler-rt/test/memprof/Unit/lit.site.cfg.py.in
index c968e403a44d09..b9485024fa5082 100644
--- a/compiler-rt/test/memprof/Unit/lit.site.cfg.py.in
+++ b/compiler-rt/test/memprof/Unit/lit.site.cfg.py.in
@@ -21,10 +21,13 @@ config.test_source_root = config.test_exec_root
 # When LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on, the initial value of
 # config.compiler_rt_libdir (COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR) has the
 # host triple as the trailing path component. The value is incorrect for i386
-# tests on x86_64 hosts and vice versa.  But, since only x86_64 is enabled as
-# target, and we don't support different environments for building and,
-# respectivelly, running tests, we shouldn't see this case.
-assert not config.enable_per_target_runtime_dir or config.target_arch == config.host_arch
+# tests on x86_64 hosts and vice versa. Adjust config.compiler_rt_libdir
+# accordingly.
+if config.enable_per_target_runtime_dir and config.target_arch != config.host_arch:
+    if config.target_arch == 'i386':
+        config.compiler_rt_libdir = re.sub(r'/x86_64(?=-[^/]+$)', '/i386', config.compiler_rt_libdir)
+    elif config.target_arch == 'x86_64':
+        config.compiler_rt_libdir = re.sub(r'/i386(?=-[^/]+$)', '/x86_64', config.compiler_rt_libdir)
 
 if not config.parallelism_group:
-  config.parallelism_group = 'shadow-memory'
\ No newline at end of file
+  config.parallelism_group = 'shadow-memory'

@ilovepi ilovepi requested a review from petrhosek April 25, 2024 21:30
assert not config.enable_per_target_runtime_dir or config.target_arch == config.host_arch
# tests on x86_64 hosts and vice versa. Adjust config.compiler_rt_libdir
# accordingly.
if config.enable_per_target_runtime_dir and config.target_arch != config.host_arch:
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer not having the general handling of asan, because we don't mean to be here for 32 bit anyway. so if config.host_arch is not set in your case, what's the rest - I assume config.target_arch is exactly x86_64 and then we could assert that and do the behavior on line 30?

Copy link
Contributor Author

@ilovepi ilovepi Apr 25, 2024

Choose a reason for hiding this comment

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

I would prefer not having the general handling of asan, because we don't mean to be here for 32 bit anyway.

Fair.

so if config.host_arch is not set in your case, what's the rest - I assume config.target_arch is exactly x86_64 and then we could assert that and do the behavior on line 30?

The config.target_arch is set as expected. There is already an assert that its X86_64 on line 14. So maybe just

if config.enable_per_target_runtime_dir:
  ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, but that's only for the CTX_PROFILE.

Maybe a better approach is to assert it isn't i386? Then you have the ASAN like fixup on the libdir and 32-bit is still unsupported

Copy link
Member

Choose a reason for hiding this comment

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

sgtm. we have an assert earlier. OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we have the assert in both ctx_profile and memprof, I think this simplified check is appropriate.

Copy link
Member

@mtrofin mtrofin left a comment

Choose a reason for hiding this comment

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

lgtm for ctx_profile

@ilovepi ilovepi merged commit eb4a510 into main Apr 25, 2024
3 of 4 checks passed
@ilovepi ilovepi deleted the users/ilovepi/spr/compiler-rt-avoid-assertions-when-using-llvm_enable_per_target_runtime_dir branch April 25, 2024 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants