This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer][MIPS] Add --target flag for MIPS32
ClosedPublic

Authored by slthakur on Apr 24 2015, 3:55 AM.

Details

Summary

Without the --target flag, clang uses the mips64 triple which selects the n64 abi. We need to add --target=mips-linux-gnu, so that clang can select the correct abi for mips32r2.

Diff Detail

Repository
rL LLVM

Event Timeline

slthakur updated this revision to Diff 24373.Apr 24 2015, 3:55 AM
slthakur retitled this revision from to [sanitizer][MIPS] Add --target flag for MIPS32.
slthakur updated this object.
slthakur edited the test plan for this revision. (Show Details)
slthakur added reviewers: dsanders, samsonov, kcc.
slthakur set the repository for this revision to rL LLVM.
slthakur added subscribers: mohit.bhakkad, jaydeep, Unknown Object (MLST).
slthakur added inline comments.Apr 24 2015, 3:59 AM
cmake/config-ix.cmake
187 ↗(On Diff #24373)

I used the tab escape sequence here because while generating asan tests I get the following error :

Scanning dependencies of target Asan-mips64el-with-calls-Noinst-Test
[ 76%] Generating ASAN_NOINST_TEST_OBJECTS.gtest-all.cc.mips64el-with-calls.o
clang-3.7: error: unknown argument: '-mips64r2 -mabi=n64'

samsonov added inline comments.Apr 24 2015, 11:27 AM
cmake/config-ix.cmake
187 ↗(On Diff #24373)

Please test if you can provide multiple flags to test_target_arch function:

test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu")

If it doesn't work, we should fix it.

slthakur updated this revision to Diff 24461.Apr 27 2015, 2:56 AM

I am able to give multiple flags to test_target_arch function.
But with this the tests under AddressSanitizer-mips64-linux don't get the flags properly.
Since cmake list elements are glued with a semicolon, this semicolon gets inserted in between the two mips flags which divides the compile command into two parts. Therefore I have replaced this semicolon in get_target_flags_for_arch function with a tab.

samsonov added inline comments.Apr 30 2015, 1:40 PM
cmake/config-ix.cmake
222 ↗(On Diff #24461)

You shouldn't modify TARGET_${arch}_CFLAGS here, or do a string replacement. Just glue all flags into a string using foreach() loop, e.g. see set_target_compile_flags in CompilerRTUtils.cmake

slthakur updated this revision to Diff 25012.May 6 2015, 12:10 AM

Addressed review comments

samsonov edited edge metadata.May 6 2015, 1:50 PM

No, I believe you should fix get_target_flags_for_arch function instead, so that it returns the string instead of the list.

slthakur updated this revision to Diff 25141.May 7 2015, 1:25 AM
slthakur edited edge metadata.

Addressed review comments

slthakur added inline comments.May 7 2015, 1:30 AM
cmake/Modules/CompilerRTCompile.cmake
49 ↗(On Diff #25141)

Unit tests for ASan, MSan and TSan get their TARGET_CFLAGS from get_target_flags_for_arch () function. And TARGET_CFLAGS need to be in list form, otherwise unit tests fail to compile :

Generating tsan_test.cc.mips64.o
cd /home/kms/sagar/compiler-rt_build/lib/tsan/tests/rtl && /home/kms/sagar/bin/MyLLVM/install/bin/clang -Wall -std=c++11 -Wno-unknown-warning-option -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fvisibility=hidden -fno-function-sections -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fPIE -fno-rtti -DGTEST_NO_LLVM_RAW_OSTREAM=1 -DGTEST_HAS_RTTI=0 -I/home/kms/sagar/bin/MyLLVM/llvm/utils/unittest/googletest/include -I/home/kms/sagar/bin/MyLLVM/llvm/utils/unittest/googletest -I/home/kms/sagar/compiler-rt/lib -I/home/kms/sagar/compiler-rt/lib/tsan/rtl -DGTEST_HAS_RTTI=0 \ -mips64r2\ -mabi=n64 -c -o tsan_test.cc.mips64.o /home/kms/sagar/compiler-rt/lib/tsan/tests/rtl/tsan_test.cc
clang-3.7: error: no such file or directory: ' -mips64r2 -mabi=n64'

As get_target_flags_for_arch function now returns a string instead of a list, TARGET_CFLAGS will be passed to clang_compile macro as a string.
Therefore we need to convert these flags back to list here to fix the above shown error.

cmake/config-ix.cmake
187 ↗(On Diff #24373)

I am able to give multiple flags to test_target_arch funtion.
But with this the tests under AddressSanitizer-mips64-linux don't get the flags properly.
Since cmake list elements are glued with a semicolon, this semicolon gets inserted in between the two mips flags which divides the compile command into two parts. Therefore I have replaced this semicolon in get_target_flags_for_arch with a tab.

slthakur added inline comments.May 7 2015, 1:33 AM
cmake/config-ix.cmake
187 ↗(On Diff #24373)

Sorry this comment was sent by mistake. It was not getting deleted.

Alright, so here's the problem: get_target_flags_for_arch is used in two places:

  1. Fetching flags eventually passed to clang_compile macro to build unit tests. They *should* be represented as list, as clang_compile description clearly says.
  2. Fetching flags passed to clang in lit-tests (through ASAN_TEST_TARGET_CFLAGS CMake variable, which is used while configuring lit.site.cfg.in. They should be represented in a string form (space-separated).

Working with lists is generally more convenient, so let's return to http://reviews.llvm.org/differential/diff/25012/, and correct the usage of get_target_flags_for_arch while generating lit configs. I'm OK with replacing ";" with space. Also note, that you should only do this when you actually call get_target_flags_for_arch, not when you obtain these flags from COMPILER_RT_TEST_COMPILER_CFLAGS variable, which is likely a string. A comment in get_target_flags_for_arch, specifying that it returns a *list* would also be convenient.

slthakur updated this revision to Diff 25315.May 8 2015, 5:41 AM

Returned to http://reviews.llvm.org/differential/diff/25012/ and corrected the usage of get_target_flags_for_arch only while generating lit configs.

samsonov accepted this revision.May 8 2015, 10:42 AM
samsonov edited edge metadata.

LGTM. Thanks for patience.

This revision is now accepted and ready to land.May 8 2015, 10:42 AM
This revision was automatically updated to reflect the committed changes.