unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#64129] [PATCH] gnu: clang-runtime-15: Fix address sanitizer support
@ 2023-06-17 13:31 Tobias Kortkamp
  2023-07-10 12:37 ` Philippe Virouleau
  0 siblings, 1 reply; 4+ messages in thread
From: Tobias Kortkamp @ 2023-06-17 13:31 UTC (permalink / raw)
  To: 64129; +Cc: Tobias Kortkamp

$ guix shell clang-toolchain@15 -- clang -o test -fsanitize=address test.c
ld: cannot find /gnu/store/i429h17s15g48ir9vl1bzp3cv39l5pib-clang-runtime-15.0.7/lib/linux/libclang_rt.asan_static-x86_64.a: No such file or directory
ld: cannot find /gnu/store/i429h17s15g48ir9vl1bzp3cv39l5pib-clang-runtime-15.0.7/lib/linux/libclang_rt.asan-x86_64.a: No such file or directory
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

* gnu/packages/llvm.scm (clang-runtime-15): Fix address sanitizer
support by bringing back the static libraries.
---

Hi,

I'm unable to compile programs with -fsanitize=address with
clang-toolchain@15:

#+name test.c
#+begin_src c
int main() { return 0; }
#+end_src

#+begin_quote
$ guix describe
Generation 46	Jun 12 2023 09:12:12	(current)
  guix dffaf42
    repository URL: https://git.savannah.gnu.org/git/guix.git
    branch: master
    commit: dffaf42e5eac3822bd6b44e9749fc8e5f48fb99c
$ guix shell clang-toolchain -- clang -o test -fsanitize=address test.c
ld: cannot find /gnu/store/i429h17s15g48ir9vl1bzp3cv39l5pib-clang-runtime-15.0.7/lib/linux/libclang_rt.asan_static-x86_64.a: No such file or directory
ld: cannot find /gnu/store/i429h17s15g48ir9vl1bzp3cv39l5pib-clang-runtime-15.0.7/lib/linux/libclang_rt.asan-x86_64.a: No such file or directory
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
#+end_quote

Similar with -shared-libsan:

#+begin_quote
$ guix shell clang-toolchain -- clang -o test -shared-libsan -fsanitize=address test.c
ld: cannot find /gnu/store/i429h17s15g48ir9vl1bzp3cv39l5pib-clang-runtime-15.0.7/lib/linux/libclang_rt.asan-preinit-x86_64.a: No such file or directory
ld: cannot find /gnu/store/i429h17s15g48ir9vl1bzp3cv39l5pib-clang-runtime-15.0.7/lib/linux/libclang_rt.asan_static-x86_64.a: No such file or directory
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
#+end_quote

With clang-toolchain@14 everything works fine.

Unless I'm missing some magic flag in the clang command, I'm guessing
that the reason for this is the following bad phase in the
clang-runtime-15 package which is missing in clang-runtime-14:

#+begin_src scheme
  (add-after 'install 'delete-static-libraries
    ;; Reduce size from 33 MiB to 7.4 MiB.
    (lambda _
      (for-each delete-file
		(find-files #$output "\\.a(\\.syms)?$"))))
#+end_src

If I remove it then the toolchain works fine again. The phase needs to
removed or fixed to not outright delete all static libraries. The
patch just removes it since that's easiest.

Best regards,

Tobias

gnu/packages/llvm.scm | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index f59c8e9592..9764552a62 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -699,12 +699,7 @@ (define-public clang-runtime-15
           #~(modify-phases #$phases
               (add-after 'unpack 'change-directory
                 (lambda _
-                  (chdir "compiler-rt")))
-              (add-after 'install 'delete-static-libraries
-                ;; Reduce size from 33 MiB to 7.4 MiB.
-                (lambda _
-                  (for-each delete-file
-                            (find-files #$output "\\.a(\\.syms)?$"))))))))
+                  (chdir "compiler-rt")))))))
       (native-inputs
        (modify-inputs (package-native-inputs template)
          (prepend gcc-12)))             ;libfuzzer fails to build with GCC 11

base-commit: 52f2980fa3feaf6e59b9e5144391faf8feb52a87
-- 
2.40.1





^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#64129] [PATCH] gnu: clang-runtime-15: Fix address sanitizer support
  2023-06-17 13:31 [bug#64129] [PATCH] gnu: clang-runtime-15: Fix address sanitizer support Tobias Kortkamp
@ 2023-07-10 12:37 ` Philippe Virouleau
  2023-07-13 16:02   ` bug#64129: " Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Virouleau @ 2023-07-10 12:37 UTC (permalink / raw)
  To: 64129

[-- Attachment #1: Type: text/plain, Size: 1444 bytes --]

Hi Tobias and all, 

I can confirm instrumented builds are also broken with [ mailto:clang-runtime@15 | clang-runtime@15 ] at the moment(using `clang -fprofile-instr-generate`) because `libclang_rt.profile-x86_64.a` doesn't exist. 
In my opinion your suggested patch is just fine, as I believe we have to keep static files for this package: 
- clang's driver actually explicitly link static files for some of them: [ https://github.com/llvm/llvm-project/blob/4c6f95be29c6ce0f89663a5103c58ee63d76cda3/clang/lib/Driver/ToolChains/CommonArgs.cpp#L1070-L1072 | https://github.com/llvm/llvm-project/blob/4c6f95be29c6ce0f89663a5103c58ee63d76cda3/clang/lib/Driver/ToolChains/CommonArgs.cpp#L1070-L1072 ] 
- I couldn't find a recent explanation for this and all compiler-rt components, but this forum post explains why there are both static libs and shared libs: [ https://discourse.llvm.org/t/asan-static-linking-on-android/29223/3 | https://discourse.llvm.org/t/asan-static-linking-on-android/29223/3 ] (basically they use static linking to intercept only calls from the main binary and not from dependent libraries, thanks to a glibc load order behavior, but the trick doesn't work on android and other platforms so they LD_PRELOAD a shared lib). 

By a quick glance at the installed components I couldn't find any static library that we can remove (most of them only exist as a static library, and the others are sanitizers). 

Regards, 
Philippe 

[-- Attachment #2: Type: text/html, Size: 1957 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#64129: [PATCH] gnu: clang-runtime-15: Fix address sanitizer support
  2023-07-10 12:37 ` Philippe Virouleau
@ 2023-07-13 16:02   ` Ludovic Courtès
  2023-07-16 20:06     ` [bug#64129] " Philippe Virouleau
  0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2023-07-13 16:02 UTC (permalink / raw)
  To: Philippe Virouleau, Tobias Kortkamp; +Cc: 64129-done

Hi Tobias & Philippe,

I was reluctant about keeping all those .a files due to the extra size,
but based on your analysis, we have no choice but to keep them.

So pushed as commit ae92d98b9375e1d753bd9ab495ed5c7dcd3f1af5.

Thank you!

Ludo’.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [bug#64129] [PATCH] gnu: clang-runtime-15: Fix address sanitizer support
  2023-07-13 16:02   ` bug#64129: " Ludovic Courtès
@ 2023-07-16 20:06     ` Philippe Virouleau
  0 siblings, 0 replies; 4+ messages in thread
From: Philippe Virouleau @ 2023-07-16 20:06 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 64129-done, Tobias Kortkamp

Thanks Ludo!

----- Mail original -----
> De: "Ludovic Courtès" <ludovic.courtes@inria.fr>
> À: "Philippe Virouleau" <philippe.virouleau@inria.fr>, "Tobias Kortkamp" <tobias.kortkamp@gmail.com>
> Cc: 64129-done@debbugs.gnu.org
> Envoyé: Jeudi 13 Juillet 2023 18:02:41
> Objet: Re: bug#64129: [PATCH] gnu: clang-runtime-15: Fix address sanitizer support

> Hi Tobias & Philippe,
> 
> I was reluctant about keeping all those .a files due to the extra size,
> but based on your analysis, we have no choice but to keep them.
> 
> So pushed as commit ae92d98b9375e1d753bd9ab495ed5c7dcd3f1af5.
> 
> Thank you!
> 
> Ludo’.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-16 20:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-17 13:31 [bug#64129] [PATCH] gnu: clang-runtime-15: Fix address sanitizer support Tobias Kortkamp
2023-07-10 12:37 ` Philippe Virouleau
2023-07-13 16:02   ` bug#64129: " Ludovic Courtès
2023-07-16 20:06     ` [bug#64129] " Philippe Virouleau

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).