public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/64234] New: Statically sanitized executable does not export ASan symbols
@ 2014-12-09  9:35 y.gribov at samsung dot com
  2014-12-09 10:02 ` [Bug sanitizer/64234] " jakub at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: y.gribov at samsung dot com @ 2014-12-09  9:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64234

            Bug ID: 64234
           Summary: Statically sanitized executable does not export ASan
                    symbols
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: y.gribov at samsung dot com
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org

If executable is linked with -static-libasan, it won't export libasan public
API (__asan_reportXYZ, etc.), causing dlopens of sanitized shlibs to fail. Same
applies to other sanitizers (-static-libubsan, etc.).


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

* [Bug sanitizer/64234] Statically sanitized executable does not export ASan symbols
  2014-12-09  9:35 [Bug sanitizer/64234] New: Statically sanitized executable does not export ASan symbols y.gribov at samsung dot com
@ 2014-12-09 10:02 ` jakub at gcc dot gnu.org
  2014-12-09 10:18 ` y.gribov at samsung dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-12-09 10:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64234

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think we can only recommend not to do that, or suggest users to consider
-Wl,-E.  The linker automatically makes symbols mentioned in dependent
libraries exported from binaries, but e.g. implying -Wl,-E from -static-libasan
is IMNSHO undesirable, it doesn't make just the selected few symbols dynamic,
but all, and that really should be users decision whether it is desirable or
not.


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

* [Bug sanitizer/64234] Statically sanitized executable does not export ASan symbols
  2014-12-09  9:35 [Bug sanitizer/64234] New: Statically sanitized executable does not export ASan symbols y.gribov at samsung dot com
  2014-12-09 10:02 ` [Bug sanitizer/64234] " jakub at gcc dot gnu.org
@ 2014-12-09 10:18 ` y.gribov at samsung dot com
  2014-12-09 10:22 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: y.gribov at samsung dot com @ 2014-12-09 10:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64234

--- Comment #2 from Yury Gribov <y.gribov at samsung dot com> ---
(In reply to Jakub Jelinek from comment #1)
> I think we can only recommend not to do that

For legacy codebase (e.g. when sanitizing full distributions) you often don't
have a choice.

> implying -Wl,-E from -static-libasan is IMNSHO undesirable,
> it doesn't make just the selected few symbols dynamic, but all,

Right, -Wl,-E would be an overkill.  AFAIK Clang automatically appends
--dynamic-list=something.syms when it compiles sanitized executable.  Perhaps
we could do this as well?


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

* [Bug sanitizer/64234] Statically sanitized executable does not export ASan symbols
  2014-12-09  9:35 [Bug sanitizer/64234] New: Statically sanitized executable does not export ASan symbols y.gribov at samsung dot com
  2014-12-09 10:02 ` [Bug sanitizer/64234] " jakub at gcc dot gnu.org
  2014-12-09 10:18 ` y.gribov at samsung dot com
@ 2014-12-09 10:22 ` jakub at gcc dot gnu.org
  2014-12-09 10:35 ` y.gribov at samsung dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-12-09 10:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64234

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
But why do you want to use -static-libasan ?  Just link it dynamically...
--dynamic-list is hard to maintain, aren't there hundreds of symbols that are
exported from libasan?


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

* [Bug sanitizer/64234] Statically sanitized executable does not export ASan symbols
  2014-12-09  9:35 [Bug sanitizer/64234] New: Statically sanitized executable does not export ASan symbols y.gribov at samsung dot com
                   ` (2 preceding siblings ...)
  2014-12-09 10:22 ` jakub at gcc dot gnu.org
@ 2014-12-09 10:35 ` y.gribov at samsung dot com
  2022-05-31  8:36 ` mkh199740 at mail dot ru
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: y.gribov at samsung dot com @ 2014-12-09 10:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64234

--- Comment #4 from Yury Gribov <y.gribov at samsung dot com> ---
(In reply to Jakub Jelinek from comment #3)
> But why do you want to use -static-libasan ?  Just link it dynamically...

For one thing it can speed up code by avoiding PLT calls.  

> --dynamic-list is hard to maintain, aren't there hundreds of symbols that
> are exported from libasan?

Indeed there are, upstream has a special script to autogenerate file with
symbols.


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

* [Bug sanitizer/64234] Statically sanitized executable does not export ASan symbols
  2014-12-09  9:35 [Bug sanitizer/64234] New: Statically sanitized executable does not export ASan symbols y.gribov at samsung dot com
                   ` (3 preceding siblings ...)
  2014-12-09 10:35 ` y.gribov at samsung dot com
@ 2022-05-31  8:36 ` mkh199740 at mail dot ru
  2022-07-18 13:07 ` boris at kolpackov dot net
  2022-11-12  2:55 ` mkh199740 at mail dot ru
  6 siblings, 0 replies; 8+ messages in thread
From: mkh199740 at mail dot ru @ 2022-05-31  8:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64234

lo1ol <mkh199740 at mail dot ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mkh199740 at mail dot ru

--- Comment #6 from lo1ol <mkh199740 at mail dot ru> ---
I've the same problem when try to link at runtime shared library compiled with
static asan. Here is minimal example:

echo '
#include <stdlib.h>
#include <stdio.h>

void f(){
    int* x = new int;
    printf("kek\n");
}' > lib.cpp

echo '
#include <dlfcn.h>
#include <stdio.h>
int main() {
    printf("lol\n");
    void* handler = dlopen("./libkek.so", RTLD_NOW);
    if (!handler)
        return 1;

    void (* func)() = reinterpret_cast<void(*)()>(dlsym(handler, "_Z1fv"));
    printf("kek\n");
    func();
    printf("cheburek\n");
}' > main.cpp


g++ -fsanitize=address -static-libasan -static-libstdc++ -static-libgcc -fPIC
-shared lib.cpp -o libkek.so
g++ -fsanitize=address -static-libasan -static-libstdc++ -static-libgcc -ldl
main.cpp
LD_DEBUG=libs ./a.out; echo $?

Part of the output:
...
    347802:     initialize program: ./a.out
    347802:
    347802:
    347802:     transferring control: ./a.out
    347802:
lol
    347802:     ./libkek.so: error: symbol lookup error: undefined symbol:
__asan_unregister_globals (fatal)
    347802:
    347802:     calling fini: ./a.out [0]
    347802:
    347802:
    347802:     calling fini: /lib/x86_64-linux-gnu/libm.so.6 [0]
    347802:


With clang everything is ok....

GCC version 12.1
System: Ubuntu 21.10

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

* [Bug sanitizer/64234] Statically sanitized executable does not export ASan symbols
  2014-12-09  9:35 [Bug sanitizer/64234] New: Statically sanitized executable does not export ASan symbols y.gribov at samsung dot com
                   ` (4 preceding siblings ...)
  2022-05-31  8:36 ` mkh199740 at mail dot ru
@ 2022-07-18 13:07 ` boris at kolpackov dot net
  2022-11-12  2:55 ` mkh199740 at mail dot ru
  6 siblings, 0 replies; 8+ messages in thread
From: boris at kolpackov dot net @ 2022-07-18 13:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64234

Boris Kolpackov <boris at kolpackov dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |boris at kolpackov dot net

--- Comment #7 from Boris Kolpackov <boris at kolpackov dot net> ---
> But why do you want to use -static-libasan ?  Just link it dynamically...

Another reason is shared linking clobbers executable's RUNPATH:
https://github.com/google/sanitizers/issues/1219

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

* [Bug sanitizer/64234] Statically sanitized executable does not export ASan symbols
  2014-12-09  9:35 [Bug sanitizer/64234] New: Statically sanitized executable does not export ASan symbols y.gribov at samsung dot com
                   ` (5 preceding siblings ...)
  2022-07-18 13:07 ` boris at kolpackov dot net
@ 2022-11-12  2:55 ` mkh199740 at mail dot ru
  6 siblings, 0 replies; 8+ messages in thread
From: mkh199740 at mail dot ru @ 2022-11-12  2:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64234

--- Comment #8 from lo1ol <mkh199740 at mail dot ru> ---
https://www.youtube.com/watch?v=Ua3TiOSwVTI

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

end of thread, other threads:[~2022-11-12  2:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-09  9:35 [Bug sanitizer/64234] New: Statically sanitized executable does not export ASan symbols y.gribov at samsung dot com
2014-12-09 10:02 ` [Bug sanitizer/64234] " jakub at gcc dot gnu.org
2014-12-09 10:18 ` y.gribov at samsung dot com
2014-12-09 10:22 ` jakub at gcc dot gnu.org
2014-12-09 10:35 ` y.gribov at samsung dot com
2022-05-31  8:36 ` mkh199740 at mail dot ru
2022-07-18 13:07 ` boris at kolpackov dot net
2022-11-12  2:55 ` mkh199740 at mail dot ru

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).