gopalshankar / address-sanitizer

Automatically exported from code.google.com/p/address-sanitizer
0 stars 0 forks source link

dyld: Symbol not found: ___asan_mapping_offset, when running ASanified binary #254

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This happens on Mac OS X when a binary is linked with 
"-exported_symbol,something" option to specify that only the listed symbols 
should be visible. 

All the other symbols are made hidden when -exported_symbol is specified. There 
are 2 possible solutions:
 - teach the compiler driver to pass the "-exported_symbol,__asan_mapping_offset" and "-exported_symbol,__asan_mapping_scale" to the linker when in ASan mode. 
 - the constructor/initializer can pass the address of the function to the runtime library directly. In that case, the symbols will not have to be exported and can stay hidden.

I saw this issue when building 2 projects and 
https://groups.google.com/forum/#!topic/address-sanitizer/aM-Tbw_zsD0 seems to 
be the same problem.

Original issue reported on code.google.com by zaks.a...@gmail.com on 18 Dec 2013 at 1:15

GoogleCodeExporter commented 9 years ago
On Linux we generate the file with all the symbols in ASan runtime that should 
be exported, and pass it to linker via --dynamic-list= option. Is there 
something similar in Mac OS X linker?

Original comment by samso...@google.com on 18 Dec 2013 at 7:17

GoogleCodeExporter commented 9 years ago
First option SGTM.
Unlike Linux, on OSX we only need to export these two symbols. Interceptors and 
runtime interface symbols are in a separate DSO and unaffected by the binary 
link flags.

Original comment by euge...@google.com on 18 Dec 2013 at 7:48

GoogleCodeExporter commented 9 years ago

Original comment by euge...@google.com on 18 Dec 2013 at 7:49

GoogleCodeExporter commented 9 years ago
You can pass along the file with exported symbols using -exported_symbols_list 
option. However, since there are only 2 symbols that need to be exported, you 
could just list them directly as options to the linker: 
-Wl,-exported_symbol,___asan_mapping_offset 
-Wl,-exported_symbol,___asan_mapping_scale.

Original comment by zaks.a...@gmail.com on 18 Dec 2013 at 6:01

GoogleCodeExporter commented 9 years ago
We should only pass -Wl,-exported_symbol,___asan_mapping_offset 
-Wl,-exported_symbol,___asan_mapping_scale if we know that the exported symbols 
are being whitelisted. For example, if there are no "-exported_symbol" on the 
command line, adding the as an symbols would lead to other symbols not being 
exported.

Original comment by zaks.a...@gmail.com on 18 Dec 2013 at 11:27

GoogleCodeExporter commented 9 years ago
What about -exported_symbols_list? Is it true that if we add it to link line, 
all the other symbols won't be exported?

Original comment by samso...@google.com on 19 Dec 2013 at 8:58

GoogleCodeExporter commented 9 years ago
maybe we should disable flexible mapping on Mac?
Then these symbols will be gone. 
This is a feature used mostly for experiments and most only Linux. 

Original comment by konstant...@gmail.com on 19 Dec 2013 at 9:02

GoogleCodeExporter commented 9 years ago
Let us keep it for now, it may be useful to shrink the shadow memory for 32-bit 
apps (think iossim)

Original comment by ramosian.glider@gmail.com on 19 Dec 2013 at 9:05

GoogleCodeExporter commented 9 years ago
Looks like exported_symbols_list has the same behavior as exported_symbol but 
is more convenient for longer lists.

From man ld:
     -exported_symbols_list filename
                 The specified filename contains a list of global symbol names that will remain as global symbols in the output file.  All other global symbols will be treated
                 as if they were marked as __private_extern__ (aka visibility=hidden) and will not be global in the output file. The symbol names listed in filename must be
                 one per line.  Leading and trailing white space are not part of the symbol name.  Lines starting with # are ignored, as are lines with only white space.  Some
                 wildcards (similar to shell file matching) are supported.  The * matches zero or more characters.  The ? matches one character.  [abc] matches one character
                 which must be an 'a', 'b', or 'c'.  [a-z] matches any single lower case letter from 'a' to 'z'.

     -exported_symbol symbol
                 The specified symbol is added to the list of global symbols names that will remain as global symbols in the output file.  This option can be used multiple
                 times.  For short lists, this can be more convenient than creating a file and using -exported_symbols_list.

Original comment by zaks.a...@gmail.com on 19 Dec 2013 at 5:28

GoogleCodeExporter commented 9 years ago
Looks like we can just check that -Wl,_exported_symbol* is present in the 
command line.
I haven't found an easy way to check for certain -Wl arguments yet, not sure if 
it's ok to do plain string matching.

Original comment by ramosian.glider@gmail.com on 20 Dec 2013 at 5:25

GoogleCodeExporter commented 9 years ago
Can we close this now (since the flexible mapping code is gone)?

Original comment by konstant...@gmail.com on 29 Jan 2014 at 1:17

GoogleCodeExporter commented 9 years ago
Ok

Original comment by ramosian.glider@gmail.com on 11 Feb 2014 at 11:03