ramosian-glider / sanitizers

0 stars 0 forks source link

Chrome base_unittests do not work with the dynamic runtime #114

Closed ramosian-glider closed 9 years ago

ramosian-glider commented 9 years ago

Originally reported on Google Code with ID 113

$ out/Release/base_unittests  --gtest_filter=ProcessUtilTest.GetAppOutput:ProcessUtilTest.GetAppOutputWithExitCode
Note: Google Test filter = ProcessUtilTest.GetAppOutput:ProcessUtilTest.GetAppOutputWithExitCode
[==========] Running 2 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 2 tests from ProcessUtilTest
[ RUN      ] ProcessUtilTest.GetAppOutput
../../base/process_util_unittest.cc:773: Failure
Value of: base::GetAppOutput(CommandLine(FilePath("true")), &output)
  Actual: false
Expected: true
../../base/process_util_unittest.cc:782: Failure
Value of: base::GetAppOutput(CommandLine(argv), &output)
  Actual: false
Expected: true
../../base/process_util_unittest.cc:783: Failure
Value of: output.c_str()
  Actual: ""
Expected: "foobar42"
[  FAILED  ] ProcessUtilTest.GetAppOutput (110 ms)
[ RUN      ] ProcessUtilTest.GetAppOutputWithExitCode
../../base/process_util_unittest.cc:884: Failure
Value of: base::GetAppOutputWithExitCode(CommandLine(argv), &output, &exit_code)
  Actual: false
Expected: true
../../base/process_util_unittest.cc:885: Failure
Value of: output.c_str()
  Actual: ""
Expected: "foo\n"
../../base/process_util_unittest.cc:886: Failure
Value of: 0
Expected: exit_code
Which is: 1
../../base/process_util_unittest.cc:893: Failure
Value of: base::GetAppOutputWithExitCode(CommandLine(argv), &output, &exit_code)
  Actual: false
Expected: true
../../base/process_util_unittest.cc:894: Failure
Value of: output.c_str()
  Actual: ""
Expected: "foo\n"
../../base/process_util_unittest.cc:895: Failure
Value of: 2
Expected: exit_code
Which is: 1
[  FAILED  ] ProcessUtilTest.GetAppOutputWithExitCode (74 ms)
[----------] 2 tests from ProcessUtilTest (185 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 1 test case ran. (185 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 2 tests, listed below:
[  FAILED  ] ProcessUtilTest.GetAppOutput
[  FAILED  ] ProcessUtilTest.GetAppOutputWithExitCode

Reported by ramosian.glider on 2012-09-17 10:13:14

ramosian-glider commented 9 years ago

$ out/Release/base_unittests  --gtest_filter=ProcessUtilTest.LaunchProcess
Note: Google Test filter = ProcessUtilTest.LaunchProcess
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from ProcessUtilTest
[ RUN      ] ProcessUtilTest.LaunchProcess
dyld: could not load inserted library: /Users/glider/src/asan/llvm/build/tools/clang/runtime/compiler-rt/clang_darwin/asan_osx_dynamic/i386/libcompiler_rt.dylib

[38146:-1406602560:0917/141251:1129374519158731:FATAL:process_util_unittest.cc(656)]
Check failed: n > 0. : Invalid argument
[38146:-1406602560:0917/141251:1129374519158731:FATAL:process_util_unittest.cc(656)]
Check failed: n > 0. : Invalid argument
Trace/BPT trap: 5

Reported by ramosian.glider on 2012-09-17 10:13:22

ramosian-glider commented 9 years ago
$ svn diff build/common.gypi
Index: build/common.gypi
===================================================================
--- build/common.gypi   (revision 157094)
+++ build/common.gypi   (working copy)
@@ -2960,7 +2960,9 @@
               ['asan==1', {
                 'xcode_settings': {
                   'OTHER_LDFLAGS': [
-                    '-faddress-sanitizer',
+#                    '-faddress-sanitizer',
+                    '-L/Users/glider/src/asan/llvm/build/Release+Asserts/lib/clang/3.2/lib/darwin',
+                    '-lclang_rt.asan_osx_dynamic',
                   ],
                 },
               }],

Reported by ramosian.glider on 2012-09-17 10:13:45

ramosian-glider commented 9 years ago
All the tests pass if I explicitly set DYLD_INSERT_LIBRARIES=/Users/glider/src/asan/llvm/build/Release+Asserts/lib/clang/3.2/lib/darwin/libclang_rt.asan_osx_dynamic.dylib

But for some strange reason base_unittests depend on libcompiler_rt.dylib instead:

$ otool -L out/Release/base_unittests
out/Release/base_unittests:
    /Users/glider/src/asan/llvm/build/tools/clang/runtime/compiler-rt/clang_darwin/asan_osx_dynamic/i386/libcompiler_rt.dylib
(compatibility version 0.0.0, current version 0.0.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version
45.0.0, current version 1038.36.0)
    /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices
(compatibility version 1.0.0, current version 38.0.0)
    /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version
2.0.0, current version 152.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility
version 150.0.0, current version 550.43.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility
version 300.0.0, current version 751.62.0)
    /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version
1.0.0, current version 275.0.0)
    /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version
1.0.0, current version 55002.0.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
    /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility
version 1.0.0, current version 44.0.0)

Reported by ramosian.glider on 2012-09-17 10:39:52

ramosian-glider commented 9 years ago
The make and cmake LLVM builds behave differently here:

$ cat t.c
int main() { return 0; }

$ export ASAN_BIN=/Users/glider/src/asan/llvm/build/Release+Asserts/bin/ # make build
$ $ASAN_BIN/clang t.c -c -faddress-sanitizer
$ $ASAN_BIN/clang t.o -lclang_rt.asan_osx_dynamic -L$ASAN_BIN/../lib/clang/3.2/lib/darwin
-o t
$ otool -L t
t:
    /Users/glider/src/asan/llvm/build/tools/clang/runtime/compiler-rt/clang_darwin/asan_osx_dynamic/x86_64/libcompiler_rt.dylib
(compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

$ export ASAN_BIN=/Users/glider/src/asan/llvm/llvm_cmake_build/bin/
$ $ASAN_BIN/clang t.c -c -faddress-sanitizer
$ $ASAN_BIN/clang t.o -lclang_rt.asan_osx_dynamic -L$ASAN_BIN/../lib/clang/3.2/lib/darwin
-o t
$ otool -L t
t:
    /Users/glider/src/asan/llvm/llvm_cmake_build/lib/clang/3.2/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
(compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

Reported by ramosian.glider on 2012-09-17 11:50:36

ramosian-glider commented 9 years ago
Seems that the difference is in the libclang_rt.asan_osx_dynamic.dylib dependencies.

$ export ASAN_BIN=/Users/glider/src/asan/llvm/llvm_cmake_build/bin/
$ otool -L $ASAN_BIN/../lib/clang/3.2/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
/Users/glider/src/asan/llvm/llvm_cmake_build/bin//../lib/clang/3.2/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:
    /Users/glider/src/asan/llvm/llvm_cmake_build/lib/clang/3.2/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
(compatibility version 0.0.0, current version 0.0.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility
version 300.0.0, current version 833.20.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility
version 150.0.0, current version 635.15.0)

-- in CMake build libclang_rt.asan_osx_dynamic.dylib does not depend on any Clang dylibs.

$ export ASAN_BIN=/Users/glider/src/asan/llvm/build/Release+Asserts/bin/
$ otool -L $ASAN_BIN/../lib/clang/3.2/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
/Users/glider/src/asan/llvm/build/Release+Asserts/bin//../lib/clang/3.2/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:
    /Users/glider/src/asan/llvm/build/tools/clang/runtime/compiler-rt/clang_darwin/asan_osx_dynamic/x86_64/libcompiler_rt.dylib
(compatibility version 0.0.0, current version 0.0.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility
version 300.0.0, current version 833.25.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility
version 150.0.0, current version 635.21.0)

-- in make it does.

Reported by ramosian.glider on 2012-09-17 13:27:23

ramosian-glider commented 9 years ago
This happens because libcompiler_rt.dylib is being copied to libclang_rt.asan_osx_dynamic.dylib,
but its LC_ID_DYLIB load command is not fixed:

$ otool -l /Users/glider/src/asan/llvm/build/Release+Asserts/lib/clang/3.2/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
| grep libcompiler_rt -B3
Load command 3
          cmd LC_ID_DYLIB
      cmdsize 152
         name /Users/glider/src/asan/llvm/build/tools/clang/runtime/compiler-rt/clang_darwin/asan_osx_dynamic/x86_64/libcompiler_rt.dylib
(offset 24)

The following command fixes the tests for me:
$ install_name_tool /Users/glider/src/asan/llvm/build/Release+Asserts/lib/clang/3.2/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
-id /Users/glider/src/asan/llvm/build/Release+Asserts/lib/clang/3.2/lib/darwin/libclang_rt.asan_osx_dynamic.dylib

Reported by ramosian.glider on 2012-09-17 14:03:53

ramosian-glider commented 9 years ago
Fixed in Clang r164031.

Reported by ramosian.glider on 2012-09-17 14:23:01

ramosian-glider commented 9 years ago
Adding Project:AddressSanitizer as part of GitHub migration.

Reported by ramosian.glider on 2015-07-30 09:13:00