Skip to content

[profile][test] Build Posix/instrprof-dlopen-norpath.test objects as PIC #106406

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

Merged

Conversation

rorth
Copy link
Collaborator

@rorth rorth commented Aug 28, 2024

Profile-x86_64 :: Posix/instrprof-dlopen-norpath.test FAILs on Solaris/amd64 and similarly on Solaris/sparcv9:

RUN: at line 10: ./a.out 2>&1 | FileCheck compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test -check-prefix=CHECK-FOO
+ ./a.out
+ FileCheck compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test -check-prefix=CHECK-FOO
compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test:24:12: error: CHECK-FOO: expected string not found in input
CHECK-FOO: foo:
           ^
<stdin>:1:1: note: scanning from here
unable to lookup symbol 'foo': ld.so.1: a.out: invalid handle: 0x0

The problem turned out to be two-fold: OPEN_AND_RUN didn't check the dlopen return value and the objects linked into the shared objects to be dlopened aren't built as PIC.

This patch fixes the latter.

Tested on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and x86_64-pc-linux-gnu.

`Profile-x86_64 :: Posix/instrprof-dlopen-norpath.test` `FAILs` on
Solaris/amd64 and similarly on Solaris/sparcv9:
```
RUN: at line 10: ./a.out 2>&1 | FileCheck compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test -check-prefix=CHECK-FOO
+ ./a.out
+ FileCheck compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test -check-prefix=CHECK-FOO
compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test:24:12: error: CHECK-FOO: expected string not found in input
CHECK-FOO: foo:
           ^
<stdin>:1:1: note: scanning from here
unable to lookup symbol 'foo': ld.so.1: a.out: invalid handle: 0x0
```
The problem turned out to be two-fold: `OPEN_AND_RUN` didn't check the
`dlopen` return value and the objects linked into the shared objects to be
`dlopen`ed aren't built as PIC.

This patch fixes the latter.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.
@rorth rorth requested review from vitalybuka and w2yehia August 28, 2024 15:24
@llvmbot llvmbot added compiler-rt PGO Profile Guided Optimizations labels Aug 28, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 28, 2024

@llvm/pr-subscribers-pgo

Author: Rainer Orth (rorth)

Changes

Profile-x86_64 :: Posix/instrprof-dlopen-norpath.test FAILs on Solaris/amd64 and similarly on Solaris/sparcv9:

RUN: at line 10: ./a.out 2&gt;&amp;1 | FileCheck compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test -check-prefix=CHECK-FOO
+ ./a.out
+ FileCheck compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test -check-prefix=CHECK-FOO
compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test:24:12: error: CHECK-FOO: expected string not found in input
CHECK-FOO: foo:
           ^
&lt;stdin&gt;:1:1: note: scanning from here
unable to lookup symbol 'foo': ld.so.1: a.out: invalid handle: 0x0

The problem turned out to be two-fold: OPEN_AND_RUN didn't check the dlopen return value and the objects linked into the shared objects to be dlopened aren't built as PIC.

This patch fixes the latter.

Tested on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and x86_64-pc-linux-gnu.


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

1 Files Affected:

  • (modified) compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test (+2-2)
diff --git a/compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test b/compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test
index 8a7cca737dc8a4..ba42433f98c296 100644
--- a/compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test
+++ b/compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test
@@ -1,6 +1,6 @@
 RUN: rm -rf %t && split-file %s %t && cd %t
-RUN: %clang_pgogen foo.c -c -Xclang -fprofile-instrument-path="default_foo_%m.profraw"
-RUN: %clang_pgogen foo2.c -c -Xclang -fprofile-instrument-path="default_foo2_%m.profraw"
+RUN: %clang_pgogen -fPIC foo.c -c -Xclang -fprofile-instrument-path="default_foo_%m.profraw"
+RUN: %clang_pgogen -fPIC foo2.c -c -Xclang -fprofile-instrument-path="default_foo2_%m.profraw"
 RUN: %clang_pgogen -shared foo.o -o shr_foo.o %if target={{.*aix.*}} %{ -bcdtors:mbr %}
 RUN: %clang_pgogen -shared foo2.o -o shr_foo2.o
 

@rorth rorth merged commit e03669a into llvm:main Aug 28, 2024
10 checks passed
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.

3 participants