Bug 1678240 - Clang with -m32 and -fsanitize looks for library in wrong directory
Summary: Clang with -m32 and -fsanitize looks for library in wrong directory
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: clang
Version: 29
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: serge_sans_paille
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-02-18 10:58 UTC by thranur
Modified: 2020-07-16 11:04 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-06-28 13:54:12 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Symlinks are not removed when erasing the packages. (12.85 KB, text/plain)
2019-07-22 16:34 UTC, Vasil Velichkov
no flags Details

Description thranur 2019-02-18 10:58:20 UTC
Description of problem: Trying to compile any program with clang -m32 -fsanitize=undefined (or -fsanitize=address, or -fsanitize=leak), even when the required i686 packages are installed, results in:

/usr/bin/ld: cannot find /usr/lib64/clang/6.0.1/lib/linux/libclang_rt.asan-i386.a: No such file or directory
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)

This is because it looks for the 32-bit library of the sanitizer in /usr/lib64, and not in /usr/lib, where the file is actually installed.

Version-Release number of selected component (if applicable):
Fedora 28
clang version 6.0.1

How reproducible: always


Steps to Reproduce:
1. echo "int main(){return 0;}" > a.c
2. clang -m32 -fsanitize=address a.c

Actual results:
/usr/bin/ld: cannot find /usr/lib64/clang/6.0.1/lib/linux/libclang_rt.asan-i386.a: No such file or directory
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)

Expected results:
File should compile normally.

Additional info:

Comment 1 thranur 2019-02-20 18:20:46 UTC
For information, I just upgraded to Fedora 29, and the problem persists, although it is using clang 7 this time:

/usr/bin/ld: cannot find /usr/lib64/clang/7.0.1/lib/linux/libclang_rt.ubsan_standalone-i386.a: No such file or directory
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

Once again, the correct path should refer to /usr/lib, not /usr/lib64.

Comment 2 serge_sans_paille 2019-06-18 14:29:08 UTC
The problem is still there for rawhide, creating a few symlinks appropriately should do the trick, let me investigate that.

Comment 3 serge_sans_paille 2019-06-28 13:54:12 UTC
Fixed as of compiler-rt-8.0.0-2.fc31

Comment 4 Vasil Velichkov 2019-07-03 15:16:30 UTC
Would it be possible to backport this fix and release versions for FC29 and FC30? Thanks.

Comment 5 Fedora Update System 2019-07-05 08:55:46 UTC
FEDORA-2019-271b8968c9 has been submitted as an update to Fedora 30. https://bodhi.fedoraproject.org/updates/FEDORA-2019-271b8968c9

Comment 6 Fedora Update System 2019-07-05 10:25:38 UTC
FEDORA-2019-819537896d has been submitted as an update to Fedora 29. https://bodhi.fedoraproject.org/updates/FEDORA-2019-819537896d

Comment 7 Fedora Update System 2019-07-06 04:18:45 UTC
compiler-rt-8.0.0-2.fc30 has been pushed to the Fedora 30 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-271b8968c9

Comment 8 Fedora Update System 2019-07-06 06:41:26 UTC
compiler-rt-7.0.1-2.fc29 has been pushed to the Fedora 29 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-819537896d

Comment 9 Vasil Velichkov 2019-07-16 16:03:59 UTC
Thanks for backporting the fix.

I just tested the new versions from the updates-testing repositories on FC29 and found two problems


1. The package needs to create symlinks in /usr/lib64/clang/7.0.1/lib/linux directory as well because clangs search the library there and not in /usr/lib64/clang/7.0.1/lib/

    /usr/bin/ld: cannot find /usr/lib64/clang/7.0.1/lib/linux/libclang_rt.asan-i386.a: No such file or directory

    $ find /usr/lib /usr/lib64 -name libclang_rt.asan-i386.a 
    /usr/lib/clang/7.0.1/lib/libclang_rt.asan-i386.a
    /usr/lib/clang/7.0.1/lib/linux/libclang_rt.asan-i386.a
    /usr/lib64/clang/7.0.1/lib/libclang_rt.asan-i386.a


2 The pre and post install scripts do not check whether the package is being upgraded or removed. For example reinstall prints errors and remove the symlinks. I guess that in the future update will do the same.

    $ sudo dnf reinstall compiler-rt compiler-rt.i686 --enablerepo=updates-testing
    
    Running transaction
      Preparing        :                                                                                                                              1/1 
      Reinstalling     : compiler-rt-7.0.1-2.fc29.x86_64                                                                                              1/4 
      Reinstalling     : compiler-rt-7.0.1-2.fc29.i686                                                                                                2/4 
      Running scriptlet: compiler-rt-7.0.1-2.fc29.i686                                                                                                2/4 
    ln: failed to create symbolic link '../../../../lib64/clang/7.0.1/lib/libclang_rt.asan_cxx-i386.a': File exists
    ln: failed to create symbolic link '../../../../lib64/clang/7.0.1/lib/libclang_rt.asan-i386.a': File exists
    ln: failed to create symbolic link '../../../../lib64/clang/7.0.1/lib/libclang_rt.asan-preinit-i386.a': File exists

    $ find /usr/lib /usr/lib64 -name libclang_rt.asan-i386.a
    /usr/lib/clang/7.0.1/lib/libclang_rt.asan-i386.a
    /usr/lib/clang/7.0.1/lib/linux/libclang_rt.asan-i386.a

Comment 10 serge_sans_paille 2019-07-18 20:04:21 UTC
Vasil, can you tell me if https://koji.fedoraproject.org/koji/taskinfo?taskID=36325500 fixes your issue? Thanks!

Comment 11 Vasil Velichkov 2019-07-18 22:28:08 UTC
Hi serge_sans_paille,

Sorry, it does not solve any of the two issues. I've downloaded the x86_64 and i686 rpms from https://koji.fedoraproject.org/koji/buildinfo?buildID=1309391 as the link you gave me is only for x86_64. The upgrade from compiler-rt-7.0.1-1.fc29.x86_64 works as expected.

$ sudo dnf upgrade ./compiler-rt-7.0.1-2.fc29.x86_64.rpm ./compiler-rt-7.0.1-2.fc29.i686.rpm
Dependencies resolved.
======================================================================================================================================================
 Package                             Architecture                   Version                                Repository                            Size
======================================================================================================================================================
Upgrading:
 compiler-rt                         x86_64                         7.0.1-2.fc29                           @commandline                         2.5 M
 compiler-rt                         i686                           7.0.1-2.fc29                           @commandline                         1.2 M

Transaction Summary
======================================================================================================================================================
Upgrade  2 Packages

Total size: 3.8 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                              1/1 
  Upgrading        : compiler-rt-7.0.1-2.fc29.x86_64                                                                                              1/4 
  Upgrading        : compiler-rt-7.0.1-2.fc29.i686                                                                                                2/4 
  Running scriptlet: compiler-rt-7.0.1-2.fc29.i686                                                                                                2/4 
  Cleanup          : compiler-rt-7.0.1-1.fc29.i686                                                                                                3/4 
  Cleanup          : compiler-rt-7.0.1-1.fc29.x86_64                                                                                              4/4 
  Running scriptlet: compiler-rt-7.0.1-1.fc29.x86_64                                                                                              4/4 
  Verifying        : compiler-rt-7.0.1-2.fc29.x86_64                                                                                              1/4 
  Verifying        : compiler-rt-7.0.1-1.fc29.x86_64                                                                                              2/4 
  Verifying        : compiler-rt-7.0.1-2.fc29.i686                                                                                                3/4 
  Verifying        : compiler-rt-7.0.1-1.fc29.i686                                                                                                4/4 

But reinstall still prints "ln: failed to create symbolic link" errors although it succeed.

$ sudo dnf reinstall ./compiler-rt-7.0.1-2.fc29.x86_64.rpm ./compiler-rt-7.0.1-2.fc29.i686.rpm
Last metadata expiration check: 0:15:57 ago on 2019-07-19T00:50:30 EEST.
Dependencies resolved.
======================================================================================================================================================
 Package                             Architecture                   Version                                Repository                            Size
======================================================================================================================================================
Reinstalling:
 compiler-rt                         x86_64                         7.0.1-2.fc29                           @commandline                         2.5 M
 compiler-rt                         i686                           7.0.1-2.fc29                           @commandline                         1.2 M

Transaction Summary
======================================================================================================================================================

Total size: 3.8 M
Installed size: 35 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                              1/1 
  Reinstalling     : compiler-rt-7.0.1-2.fc29.x86_64                                                                                              1/4 
  Reinstalling     : compiler-rt-7.0.1-2.fc29.i686                                                                                                2/4 
  Running scriptlet: compiler-rt-7.0.1-2.fc29.i686                                                                                                2/4 
ln: failed to create symbolic link '../../../../lib64/clang/7.0.1/lib/libclang_rt.asan_cxx-i386.a': File exists
ln: failed to create symbolic link '../../../../lib64/clang/7.0.1/lib/libclang_rt.asan-i386.a': File exists
ln: failed to create symbolic link '../../../../lib64/clang/7.0.1/lib/libclang_rt.asan-preinit-i386.a': File exists
ln: failed to create symbolic link '../../../../lib64/clang/7.0.1/lib/libclang_rt.builtins-i386.a': File exists
ln: failed to create symbolic link '../../../../lib64/clang/7.0.1/lib/libclang_rt.cfi_diag-i386.a': File exists
.......
ln: failed to create symbolic link '../../../../lib64/clang/7.0.1/lib/libclang_rt.ubsan_standalone-i386.so': File exists
warning: %post(compiler-rt-7.0.1-2.fc29.i686) scriptlet failed, exit status 1

Error in POSTIN scriptlet in rpm package compiler-rt
  Running scriptlet: compiler-rt-7.0.1-2.fc29.i686                                                                                                3/4 
  Cleanup          : compiler-rt-7.0.1-2.fc29.i686                                                                                                3/4 
  Cleanup          : compiler-rt-7.0.1-2.fc29.x86_64                                                                                              4/4 
  Running scriptlet: compiler-rt-7.0.1-2.fc29.x86_64                                                                                              4/4 
  Verifying        : compiler-rt-7.0.1-2.fc29.x86_64                                                                                              1/4 
  Verifying        : compiler-rt-7.0.1-2.fc29.x86_64                                                                                              2/4 
  Verifying        : compiler-rt-7.0.1-2.fc29.i686                                                                                                3/4 
  Verifying        : compiler-rt-7.0.1-2.fc29.i686                                                                                                4/4 

Reinstalled:
  compiler-rt-7.0.1-2.fc29.x86_64                                            compiler-rt-7.0.1-2.fc29.i686                                           

Complete!

$ echo $?
0

And linking still fails with

    /usr/bin/ld: cannot find /usr/lib64/clang/7.0.1/lib/linux/libclang_rt.asan-i386.a: No such file or directory

as clang looks for libclang_rt.asan-i386.a in `/usr/lib64/clang/7.0.1/lib/linux/` directory and not in `/usr/lib64/clang/7.0.1/lib/` where you create the symlinks. See also the original report.

$ rpm -q --scripts compiler-rt-7.0.1-2.fc29.i686.rpm
postinstall scriptlet (using /bin/sh):
if test "`uname -m`" = x86_64
then
	cd /usr/lib/clang/7.0.1/lib
	mkdir -p ../../../../lib64/clang/7.0.1/lib
	for i in *.a *.so
	do
		ln -s ../../../../lib/clang/7.0.1/lib/$i ../../../../lib64/clang/7.0.1/lib/$i
	done
fi
preuninstall scriptlet (using /bin/sh):

if test "`uname -m`" = x86_64
then
	cd /usr/lib/clang/7.0.1/lib
	for i in *.a *.so
	do
		rm ../../../../lib64/clang/7.0.1/lib/$i
	done
	rmdir -p ../../../../lib64/clang/7.0.1/lib 2>/dev/null 1>/dev/null || :
fi

Not quite sure whether the symlink in `/usr/lib64/clang/7.0.1/lib/` is needed but for sure you need to create one in the `linux` subdirectory. 

In my opinion you need to either:

* Check the first argument in the pre/post scripts that indicates whether the package is being installed, upgraded or removed. 
https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax

* Create the symlinks in the %install section and then package them in the %files section.

Hope this helps and many thanks for your efforts on this issue.

Regards,
Vasil

Comment 12 serge_sans_paille 2019-07-19 11:50:53 UTC
Vasil : you've been reinstalling the 7.0.1-2 version while the above link was pointing to 7.0.1-3. Anyway I've updated the script, tested it and everything looks fine on my side, can you check https://koji.fedoraproject.org/koji/taskinfo?taskID=36344238?

Concerning your suggestions:

* Create the symlinks in the %install section and then package them in the %files section. << I don't want to do that because I need to check if I'm running on x86_64 from a i686 package, something I can only do at runtime

* Check the first argument in the pre/post scripts that indicates whether the package is being installed << That's an option, I've settled for a small rm instead

Please let me know if the above package works nice.

Comment 13 Vasil Velichkov 2019-07-19 15:12:09 UTC
(In reply to serge_sans_paille from comment #12)
> Vasil : you've been reinstalling the 7.0.1-2 version while the above link
> was pointing to 7.0.1-3. 

Oops, sorry, my mistake.

> Anyway I've updated the script, tested it and
> everything looks fine on my side, can you check
> https://koji.fedoraproject.org/koji/taskinfo?taskID=36344238?
>
> Concerning your suggestions:
> 
> * Create the symlinks in the %install section and then package them in the
> %files section. << I don't want to do that because I need to check if I'm
> running on x86_64 from a i686 package, something I can only do at runtime

OK

> * Check the first argument in the pre/post scripts that indicates whether
> the package is being installed << That's an option, I've settled for a small
> rm instead
> 
> Please let me know if the above package works nice.

I've just tested version 7.0.1-3. On the first install/upgrade the symlinks are created in the `linux` subdirectory and the linking problem is solved.
But there still is a problem with reinstalling the packages and I guess with updating from 7.0.1-3 to any newer version.

The symlinks are removed after reinstall

$ find /usr/lib /usr/lib64 -name libclang_rt.asan-i386.a
/usr/lib/clang/7.0.1/lib/libclang_rt.asan-i386.a
/usr/lib/clang/7.0.1/lib/linux/libclang_rt.asan-i386.a
/usr/lib64/clang/7.0.1/lib/linux/libclang_rt.asan-i386.a

$ sudo dnf reinstall ./compiler-rt-7.0.1-3.fc29.i686.rpm ./compiler-rt-7.0.1-3.fc29.x86_64.rpm 
Dependencies resolved.
======================================================================================================================================================
 Package                             Architecture                   Version                                Repository                            Size
======================================================================================================================================================
Reinstalling:
 compiler-rt                         i686                           7.0.1-3.fc29                           @commandline                         1.2 M
 compiler-rt                         x86_64                         7.0.1-3.fc29                           @commandline                         2.5 M

Transaction Summary
======================================================================================================================================================

Total size: 3.8 M
Installed size: 35 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                              1/1 
  Reinstalling     : compiler-rt-7.0.1-3.fc29.x86_64                                                                                              1/4 
  Reinstalling     : compiler-rt-7.0.1-3.fc29.i686                                                                                                2/4 
  Running scriptlet: compiler-rt-7.0.1-3.fc29.i686                                                                                                2/4 
  Running scriptlet: compiler-rt-7.0.1-3.fc29.i686                                                                                                3/4 
  Cleanup          : compiler-rt-7.0.1-3.fc29.i686                                                                                                3/4 
  Cleanup          : compiler-rt-7.0.1-3.fc29.x86_64                                                                                              4/4 
  Running scriptlet: compiler-rt-7.0.1-3.fc29.x86_64                                                                                              4/4 
  Verifying        : compiler-rt-7.0.1-3.fc29.i686                                                                                                1/4 
  Verifying        : compiler-rt-7.0.1-3.fc29.i686                                                                                                2/4 
  Verifying        : compiler-rt-7.0.1-3.fc29.x86_64                                                                                              3/4 
  Verifying        : compiler-rt-7.0.1-3.fc29.x86_64                                                                                              4/4 

Reinstalled:
  compiler-rt-7.0.1-3.fc29.i686                                            compiler-rt-7.0.1-3.fc29.x86_64                                           

Complete!

$ find /usr/lib /usr/lib64 -name libclang_rt.asan-i386.a
/usr/lib/clang/7.0.1/lib/libclang_rt.asan-i386.a
/usr/lib/clang/7.0.1/lib/linux/libclang_rt.asan-i386.a

Comment 14 serge_sans_paille 2019-07-19 15:38:02 UTC
We're making progress! What about https://koji.fedoraproject.org/koji/taskinfo?taskID=36349588?

Comment 15 Vasil Velichkov 2019-07-22 16:34:44 UTC
Created attachment 1592621 [details]
Symlinks are not removed when erasing the packages.

(In reply to serge_sans_paille from comment #14)
> We're making progress!

Yes, we are!.

> What about https://koji.fedoraproject.org/koji/taskinfo?taskID=36349588?

The only small problem I've found is that symlinks are not removed when erasing the packages. See the attached log.

Comment 16 serge_sans_paille 2020-07-16 11:04:13 UTC
Somehow resurecting the thread, but I think the issue was still there on rawhide, and https://src.fedoraproject.org/rpms/compiler-rt/pull-request/24 should fix it.


Note You need to log in before you can comment on or make changes to this bug.