[compiler-rt] r232936 - [ASan] Distinguish between read, write and read-write file access modes in OpenFile.

H.J. Lu hjl.tools at gmail.com
Mon Mar 23 10:35:18 PDT 2015


On Mon, Mar 23, 2015 at 10:09 AM, H.J. Lu <hjl.tools at gmail.com> wrote:
> On Mon, Mar 23, 2015 at 3:10 AM, Alexander Potapenko <glider at google.com> wrote:
>> Author: glider
>> Date: Mon Mar 23 05:10:46 2015
>> New Revision: 232936
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=232936&view=rev
>> Log:
>> [ASan] Distinguish between read, write and read-write file access modes in OpenFile.
>> This is to fix mapping coverage files into memory on OSX.
>>
>> Added:
>>     compiler-rt/trunk/test/asan/TestCases/Posix/coverage-direct.cc
>>       - copied unchanged from r232935, compiler-rt/trunk/test/asan/TestCases/Linux/coverage-direct.cc
>> Removed:
>>     compiler-rt/trunk/test/asan/TestCases/Linux/coverage-direct.cc
>> Modified:
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
>>     compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc
>>
> ...
>> Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc?rev=232936&r1=232935&r2=232936&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc Mon Mar 23 05:10:46 2015
>> @@ -78,14 +78,14 @@ TEST(SanitizerCommon, FileOps) {
>>
>>    char tmpfile[128];
>>    temp_file_name(tmpfile, sizeof(tmpfile), "sanitizer_common.fileops.tmp.");
>> -  uptr openrv = OpenFile(tmpfile, true);
>> +  uptr openrv = OpenFile(tmpfile, WrOnly);
>>    EXPECT_FALSE(internal_iserror(openrv));
>>    fd_t fd = openrv;
>>    EXPECT_EQ(len1, internal_write(fd, str1, len1));
>>    EXPECT_EQ(len2, internal_write(fd, str2, len2));
>>    internal_close(fd);
>>
>> -  openrv = OpenFile(tmpfile, false);
>> +  openrv = OpenFile(tmpfile, WrOnly);
>>    EXPECT_FALSE(internal_iserror(openrv));
>>    fd = openrv;
>>    uptr fsize = internal_filesize(fd);
>> @@ -134,7 +134,7 @@ TEST(SanitizerCommon, InternalMmapWithOf
>>    char tmpfile[128];
>>    temp_file_name(tmpfile, sizeof(tmpfile),
>>                   "sanitizer_common.internalmmapwithoffset.tmp.");
>> -  uptr res = OpenFile(tmpfile, true);
>> +  uptr res = OpenFile(tmpfile, WrOnly);
>                                                ^^^^^^^^^Is this a typo
> or intentional?
>>    ASSERT_FALSE(internal_iserror(res));
>>    fd_t fd = res;
>>
>>

Since sanitizer_linux.cc used to have

-uptr OpenFile(const char *filename, bool write) {
-  return internal_open(filename,
-      write ? O_RDWR | O_CREAT /*| O_CLOEXEC*/ : O_RDONLY, 0660);
                  ^^^^^^^^^^^
-}

you can't do

-  uptr res = OpenFile(tmpfile, true);
+  uptr res = OpenFile(tmpfile, WrOnly);

for Linux tests.

-- 
H.J.



More information about the llvm-commits mailing list