This is an archive of the discontinued LLVM Phabricator instance.

[Compiler-rt][Sanitizer][MSan][i386] Adding support for i386
Needs ReviewPublic

Authored by mohit.bhakkad on Nov 27 2014, 3:04 AM.

Details

Summary

Most of the changes are specific to i386 architecture to support Memory Sanitizer.

Diff Detail

Event Timeline

mohit.bhakkad retitled this revision from to [Compiler-rt][Sanitizer][MSan][i386] Adding support for i386.
mohit.bhakkad updated this object.
mohit.bhakkad edited the test plan for this revision. (Show Details)
mohit.bhakkad added reviewers: kcc, eugenis, samsonov.
mohit.bhakkad set the repository for this revision to rL LLVM.
mohit.bhakkad added subscribers: Unknown Object (MLST), sdkie.
eugenis edited edge metadata.Nov 27 2014, 4:34 AM

Are you sure you are testing i386? :)
It would require changes to lib/msan/tests/CMakeLists.txt and something under test/msan, and this CL does not touch those files. I've tried this patch and 32-bit tests are not getting built.

In D6433#5, @eugenis wrote:

Are you sure you are testing i386? :)
It would require changes to lib/msan/tests/CMakeLists.txt and something under test/msan, and this CL does not touch those files. I've tried this patch and 32-bit tests are not getting built.

Yes I am sure. But in test/msan all the tests contain hardcoded -m64.
Currently for the sake of testing, I have replaced all these -m64 with -m32.

Ah, OK. In ASan tests there is code (in lit.cfg) that adds -m32 or -m64 to %clangxx depending on the test suite configuration, could you copy that to msan and remove hardcoded -m64?

Please don't forget about msan_test.cc.

I'm sure you'll run into issues with va-arg functions: see VarArgAMD64Helper in MemorySanitizer.cpp, it needs to be reimplemented for i386 and probably both MIPS variants. Tests for that are in msan_test.cc.

mohit.bhakkad edited the test plan for this revision. (Show Details)
mohit.bhakkad edited edge metadata.
mohit.bhakkad set the repository for this revision to rL LLVM.
mohit.bhakkad added a subscriber: slthakur.

I am not able to test it using lit, as while building compiler-rt my clang is not supporting i386.
I have posted this issue in mailing list also.
Right now I have used gcc/g++ to build it and tests on this doc are giving correct results, when tested using clang individually.

@eugenis could you please comment on this, as I am looking forward to provide VarArgHelper for i386 too.

I've replied in the email thread.

Update:

  • Thanks @eugenis, issue with i386 support is resolved.
  • Right now, while testing msan32 using lit, most of the tests are failing with:
FATAL: Code 0x5556aec0 is out of application range. Non-PIE build?
FATAL: MemorySanitizer can not mmap the shadow memory.
FATAL: Make sure to compile with -fPIE and to link with -pie.
FATAL: Disabling ASLR is known to cause this error.
FATAL: If running under GDB, try 'set disable-randomization off'.
==23092==Process memory map follows:
	0x55555000-0x555ed000	/home/mohit/compiler-rt_build/test/msan/Output/strlen_of_shadow.cc.tmp
	0x555ed000-0x555ee000	/home/mohit/compiler-rt_build/test/msan/Output/strlen_of_shadow.cc.tmp
	0x555ee000-0x555f1000	/home/mohit/compiler-rt_build/test/msan/Output/strlen_of_shadow.cc.tmp
	0x555f1000-0x56648000	
	0x56648000-0x56668000	/lib/i386-linux-gnu/ld-2.19.so
	0x56668000-0x56669000	/lib/i386-linux-gnu/ld-2.19.so
	0x56669000-0x5666a000	/lib/i386-linux-gnu/ld-2.19.so
	0x5666a000-0x5666b000	[vdso]
	0x5666b000-0x56672000	
	0x5668c000-0x56768000	/usr/lib/i386-linux-gnu/libstdc++.so.6.0.19
	0x56768000-0x56769000	/usr/lib/i386-linux-gnu/libstdc++.so.6.0.19
	0x56769000-0x5676d000	/usr/lib/i386-linux-gnu/libstdc++.so.6.0.19
	0x5676d000-0x5676e000	/usr/lib/i386-linux-gnu/libstdc++.so.6.0.19
	0x5676e000-0x56775000	
	0x56775000-0x567b9000	/lib/i386-linux-gnu/libm-2.19.so
	0x567b9000-0x567ba000	/lib/i386-linux-gnu/libm-2.19.so
	0x567ba000-0x567bb000	/lib/i386-linux-gnu/libm-2.19.so
	0x567bb000-0x567bc000	
	0x567bc000-0x567d4000	/lib/i386-linux-gnu/libpthread-2.19.so
	0x567d4000-0x567d5000	/lib/i386-linux-gnu/libpthread-2.19.so
	0x567d5000-0x567d6000	/lib/i386-linux-gnu/libpthread-2.19.so
	0x567d6000-0x567d8000	
	0x567d8000-0x567df000	/lib/i386-linux-gnu/librt-2.19.so
	0x567df000-0x567e0000	/lib/i386-linux-gnu/librt-2.19.so
	0x567e0000-0x567e1000	/lib/i386-linux-gnu/librt-2.19.so
	0x567e1000-0x567e4000	/lib/i386-linux-gnu/libdl-2.19.so
	0x567e4000-0x567e5000	/lib/i386-linux-gnu/libdl-2.19.so
	0x567e5000-0x567e6000	/lib/i386-linux-gnu/libdl-2.19.so
	0x567e6000-0x56802000	/lib/i386-linux-gnu/libgcc_s.so.1
	0x56802000-0x56803000	/lib/i386-linux-gnu/libgcc_s.so.1
	0x56803000-0x569ac000	/lib/i386-linux-gnu/libc-2.19.so
	0x569ac000-0x569ae000	/lib/i386-linux-gnu/libc-2.19.so
	0x569ae000-0x569af000	/lib/i386-linux-gnu/libc-2.19.so
	0x569af000-0x56b5f000	
	0xffac2000-0xffae3000	[stack]
==23092==End of process memory map.

but when I run tests individually, almost all tests are giving expected o/p:
for eg:(see that I have used exact options that of in lit suite)

mohit@mohit:~$ /home/mohit/LLVM_x86/install/bin/clang --driver-mode=g++ -fsanitize=memory -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls  -gline-tables-only -m32 -fsanitize-memory-track-origins=2  -O3 /home/mohit/compiler-rt/test/msan/chained_origin.cc
mohit@mohit:~$ ./a.out 
==23140== WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0xf77b17dd in main /home/mohit/compiler-rt/test/msan/chained_origin.cc:47:3
    #1 0xf73e6a82 in __libc_start_main (/lib/i386-linux-gnu/libc.so.6+0x19a82)
    #2 0xf774be95 in _start (/home/mohit/a.out+0x14e95)

  Uninitialized value was stored to memory at
    #0 0xf77b1722 in fn_h() /home/mohit/compiler-rt/test/msan/chained_origin.cc:35:5
    #1 0xf77b17a2 in main /home/mohit/compiler-rt/test/msan/chained_origin.cc:46:3
    #2 0xf73e6a82 in __libc_start_main (/lib/i386-linux-gnu/libc.so.6+0x19a82)

  Uninitialized value was stored to memory at
    #0 0xf77b1692 in fn_g(int) /home/mohit/compiler-rt/test/msan/chained_origin.cc:25:5
    #1 0xf77b16bb in fn_f(int) /home/mohit/compiler-rt/test/msan/chained_origin.cc:30:3
    #2 0xf77b179d in main /home/mohit/compiler-rt/test/msan/chained_origin.cc:45:3
    #3 0xf73e6a82 in __libc_start_main (/lib/i386-linux-gnu/libc.so.6+0x19a82)

  Uninitialized value was created by an allocation of 'z' in the stack frame of function 'main'
    #0 0xf77b1730 in main /home/mohit/compiler-rt/test/msan/chained_origin.cc:38

SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/mohit/compiler-rt/test/msan/chained_origin.cc:47 main
Exiting

I am pretty sure about the correctness of address ranges in this patch. It looks like it is failing some check, investigating it now.

tl;dr: most of the test cases are passing individually, but with lit test suite, almost all are failing due to conflict in addresses.

0x555 is where a PIE binary is mapped when ASLR is disabled (1/3rd of
the address space). No idea why that happens with lit.