This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Fix a broken asan 64-bit test using ld_preload
ClosedPublic

Authored by etienneb on Sep 22 2016, 12:04 PM.

Details

Summary

The 'asan_preload_test-1.cc' is not working with the i686 architecture.
To repro the error, run on a linux 64-bit:

ninja check-asan-dynamic

The following error occurs:

--
Exit Code: 1

Command Output (stderr):
--
/home/llvm/llvm/projects/compiler-rt/test/asan/TestCases/Linux/asan_preload_test-1.cc:18:12: error: expected string not found in input
 // CHECK: AddressSanitizer: heap-buffer-overflow
           ^
<stdin>:1:1: note: scanning from here
ERROR: ld.so: object 'libclang_rt.asan-i686.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
^
<stdin>:2:10: note: possible intended match here
==25982==AddressSanitizer CHECK failed: /home/llvm/llvm/projects/compiler-rt/lib/asan/asan_interceptors.cc:736 "((__interception::real_memcpy)) != (0)" (0x0, 0x0)

The unittest is running (where %shared_libasan is replaced by libclang_rt.asan-i686.so):

// RUN: env LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s

But the executable also has a dependancy on libclang_rt.asan-i386.so (added by the clang driver):

linux-gate.so.1 =>  (0xf77cc000)
libclang_rt.asan-i386.so => not found
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xf76ba000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xf7673000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xf7656000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf74a7000)

By looking to the clang driver (tools.cpp) we can see that every x86 architecture are mapped to 'i386'.

StringRef MyArch;
   switch (getToolChain().getArch()) {
   case llvm::Triple::arm:
     MyArch = "arm";
     break;
   case llvm::Triple::x86:
     MyArch = "i386";
     break;
   case llvm::Triple::x86_64:
     MyArch = "amd64";
     break;
   default:
     llvm_unreachable("Unsupported architecture");
   }

This patch is implementing the same mapping but in the compiler-rt unittest.

Diff Detail

Event Timeline

etienneb updated this revision to Diff 72199.Sep 22 2016, 12:04 PM
etienneb retitled this revision from to [compiler-rt] Fix a broken asan 64-bit test using ld_preload.
etienneb updated this object.
etienneb added reviewers: rnk, vitalybuka.
etienneb added subscribers: chrisha, llvm-commits.
etienneb updated this revision to Diff 72200.Sep 22 2016, 12:07 PM

fix comment

vitalybuka accepted this revision.Sep 23 2016, 10:29 AM
vitalybuka edited edge metadata.

LGTM

This revision is now accepted and ready to land.Sep 23 2016, 10:29 AM
etienneb closed this revision.Sep 23 2016, 10:49 AM