r209503 - Fix '-main-file-name <name>' so that it is used for the ModuleID.

Alexey Samsonov vonosmas at gmail.com
Wed May 28 13:41:28 PDT 2014


On Wed, May 28, 2014 at 11:45 AM, Warren Hunt <whunt at google.com> wrote:

> This commit breaks functionality because asan uses the ModuleID when
> checking blacklists.  We're going to need to fix it and/or revert it.
>

To be more precise: all sanitizers assume that ModuleIdentifier contains
the path to the source file being compiled with Clang.
(e.g. if you run "clang path/to/file.cc" module identifier will be
"path/to/file.cc"). After this change the module identifier became only
the basename of a source file ("file.cc"). In particular, this:
1) breaks down -fsanitize-blacklist functionality - when ASan LLVM
instrumentation pass decides which globals should be instrumented,
it reads the contents of blacklist file and can drop the global from
instrumentation if it is contained in a blacklisted source file.
2) reduces the quality of ASan reports. ASan stores the module identifier
string in an executable to later print it in the error report if
necessary (this will work independent of whether there is debug info in
executable or no). Of course, printing the full path to the source file
is better than printing only the basename.

However, it seems that there are no guarantees whatsoever about the
ModuleID and sanitizers shouldn't depend on it. Instead, we should
put as much blacklist functionality as possible into the Clang itself (some
of that is already done). So:

regarding (1), we should instead exclude globals from instrumentation in
Clang. We'll probably be able to land this patch back after that, unless
there are more issues in TSan/MSan.

regarding (2), we need to design/implement a robust way to pass data from
Clang to sanitizer instrumentation passes anyway, which wouldn't
depend on LLVM ModuleID, or other obscure stuff like temporary names (
https://code.google.com/p/address-sanitizer/issues/detail?id=299).



>
> -Warren
>
>
> On Fri, May 23, 2014 at 12:34 AM, Robert Lytton <robert at xmos.com> wrote:
>
>> Author: rlytton
>> Date: Fri May 23 02:34:08 2014
>> New Revision: 209503
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=209503&view=rev
>> Log:
>> Fix '-main-file-name <name>' so that it is used for the ModuleID.
>>
>> Summary:
>> Previously, you could not specify the original file name when passing a
>> preprocessed file into the compiler
>> Now you can use 'clang -Xclang -main-file-name -Xclang <original file
>> name> ...'
>> Or 'clang -cc1 -main-file-name <original file name> ...'
>>
>> Added:
>>     cfe/trunk/test/CodeGen/main-file-name.c
>> Modified:
>>     cfe/trunk/lib/CodeGen/CodeGenAction.cpp
>>
>> Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=209503&r1=209502&r2=209503&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Fri May 23 02:34:08 2014
>> @@ -551,9 +551,12 @@ ASTConsumer *CodeGenAction::CreateASTCon
>>      LinkModuleToUse = ModuleOrErr.get();
>>    }
>>
>> +  StringRef MainFileName =
>> getCompilerInstance().getCodeGenOpts().MainFileName;
>> +  if (MainFileName.empty())
>> +    MainFileName = InFile;
>>    BEConsumer = new BackendConsumer(BA, CI.getDiagnostics(),
>> CI.getCodeGenOpts(),
>>                                     CI.getTargetOpts(), CI.getLangOpts(),
>> -                                   CI.getFrontendOpts().ShowTimers,
>> InFile,
>> +                                   CI.getFrontendOpts().ShowTimers,
>> MainFileName,
>>                                     LinkModuleToUse, OS.release(),
>> *VMContext);
>>    return BEConsumer;
>>  }
>>
>> Added: cfe/trunk/test/CodeGen/main-file-name.c
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/main-file-name.c?rev=209503&view=auto
>>
>> ==============================================================================
>> --- cfe/trunk/test/CodeGen/main-file-name.c (added)
>> +++ cfe/trunk/test/CodeGen/main-file-name.c Fri May 23 02:34:08 2014
>> @@ -0,0 +1,6 @@
>> +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
>> +// RUN: %clang_cc1 -emit-llvm -o - %s -main-file-name some.name |
>> FileCheck -check-prefix NAMED %s
>> +
>> +// CHECK: ; ModuleID = '{{.*}}main-file-name.c'
>> +// NAMED: ; ModuleID = 'some.name'
>> +
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>


-- 
Alexey Samsonov
vonosmas at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140528/aff5577f/attachment.html>


More information about the cfe-commits mailing list