You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucy.apache.org by Logan Bell <lo...@gmail.com> on 2012/06/07 07:11:05 UTC

[lucy-dev] Clang/Charmonizer

Devs,

This last weekend I was attempting to build Lucy from trunk but was
failing. My console was being flooded with these sorts of errors:

./charmony.h:292:31: note: expanded from macro 'CHY_EXPORT'
#define CHY_EXPORT __declspec(dllexport)
                              ^
In file included from ../core/Lucy/Index/SegLexicon.c:18:
In file included from ../core/Lucy/Util/ToolSet.h:40:
autogen/include/Lucy/Object/BitVector.h:349:8: warning: unknown attribute
'dllexport' ignored [-Wattributes]
extern CHY_EXPORT size_t Lucy_BitVec_Is_A_OFFSET;

After doing some spelunking through the charmonizer code I found that we're
doing some probing in src/Charmonizer/Probe/SymbolVisibility.c to set some
macros CHY_EXPORT/CHY_IMPORT based on if some code fragments can compile.
The problem is that this probe is failing for my version of clang,
charmonizer believes my platform is windows. Reading through the clang
documentation it looks like clang will by default drop the Microsoft
specific "__declspec(dllexport)" constructs, thus making the test true in
this instance. Further, it appears that clang does support most of the gcc
specific attributes. So as a hack and potential fix I reversed the logic in
this code. This made the build happy with no errors. I have yet to commit
this since I'm a bit new to charmonizer and to the various macros it
creates and would appreciate any feedback to this patch.

The patch is attached to JIRA 237:
https://issues.apache.org/jira/browse/LUCY-237

The clang documentation that I reference is the following:
http://clang.llvm.org/docs/UsersManual.html#c_ms
http://clang.llvm.org/docs/UsersManual.html#analyzer_annotations

And for what it's worth my platform information:

Mac OS X (Lion)
Apple clang version 3.1 (tags/Apple/clang-318.0.45) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.0
Thread model: posix

Thanks,
Logan

Re: [lucy-dev] Clang/Charmonizer

Posted by Logan Bell <lo...@gmail.com>.
Nick,

Thanks for the feedback and good catch on that oversight :). I agree with
that I'll make that change.

Thanks,
Logan

On Tue, Jun 12, 2012 at 4:25 AM, Nick Wellnhofer <we...@aevum.de>wrote:

> On 09/06/2012 00:19, Logan Bell wrote:
>
>> Thanks Nick/Marvin for the suggestions and feedback. I implemented the
>> approach that Marvin outlined and it seems to fix the problem for me.
>>
>> The patch is available here:
>> https://issues.apache.org/**jira/secure/attachment/**
>> 12531455/potential_fix2.patch<https://issues.apache.org/jira/secure/attachment/12531455/potential_fix2.patch>
>>
>> Let me know if this seems like a more reasonable hack.
>>
>
> It's reasonable, but it seems that after calling
> CC_set_warnings_as_errors(0), error_flag won't be reset to "". Maybe
> CC_set_warnings_as_errors should set error_flag directly.
>
> Nick
>

Re: [lucy-dev] Clang/Charmonizer

Posted by Nick Wellnhofer <we...@aevum.de>.
On 09/06/2012 00:19, Logan Bell wrote:
> Thanks Nick/Marvin for the suggestions and feedback. I implemented the
> approach that Marvin outlined and it seems to fix the problem for me.
>
> The patch is available here:
> https://issues.apache.org/jira/secure/attachment/12531455/potential_fix2.patch
>
> Let me know if this seems like a more reasonable hack.

It's reasonable, but it seems that after calling 
CC_set_warnings_as_errors(0), error_flag won't be reset to "". Maybe 
CC_set_warnings_as_errors should set error_flag directly.

Nick

Re: [lucy-dev] Clang/Charmonizer

Posted by Logan Bell <lo...@gmail.com>.
Thanks Nick/Marvin for the suggestions and feedback. I implemented the
approach that Marvin outlined and it seems to fix the problem for me.

The patch is available here:
https://issues.apache.org/jira/secure/attachment/12531455/potential_fix2.patch

Let me know if this seems like a more reasonable hack.

Thanks,
Logan

On Thu, Jun 7, 2012 at 10:44 AM, Marvin Humphrey <ma...@rectangular.com>wrote:

> On Thu, Jun 7, 2012 at 7:10 AM, Logan Bell <lo...@gmail.com> wrote:
> > It would seem that having a "CC_capture_warnings" would probably be a
> > useful general purpose function to have.
>
> That approach is plausible: compile twice capturing compiler warnings and
> fail if the warnings differ.
>
> It's not a route we typically want to take because we'd like to verify that
> compiler features actually *work* -- but we're backed into a corner here.
>
> > I would also volunteer to try to implement the technical details for this
> > function, unless there are any objections creating such a method?
>
> This would be a nice feature to have.  However, coding it up would actually
> take a fair amount of refactoring, as the assumption that we throw away
> compiler output is pretty deeply baked in.
>
> It might be quicker to try enabling warnings as errors.  This is done with
> -Werror on GCC and Clang, and with /WX on MSVC.
>
> Since this is likely to be a rarely used feature, I'd propose a
> CC_warnings_as_errors(int enabled) setter that controls a static variable
> within Compiler.c.  If that static variable is non-zero, then we tack on
> the
> extra flag when generating the compiler command within CC_compile_exe() and
> CC_compile_obj().
>
> Then in SymbolVisibility.c, we'd enable that setting for only as long as
> necessary.
>
> > Or, perhaps the reason it doesn't exist is because it's not trivial for
> all
> > of the various compilers we support?
>
> It's doable but not trivial, both because of the compiler and the shell.
>  MSVC
> writes its boilerplate to stderr, so I'm not sure the approach is
> generalizable to all compilers.  And redirection syntax is different under
> cmd.exe than under Unix shells.
>
> Marvin Humphrey
>

Re: [lucy-dev] Clang/Charmonizer

Posted by Marvin Humphrey <ma...@rectangular.com>.
On Thu, Jun 7, 2012 at 7:10 AM, Logan Bell <lo...@gmail.com> wrote:
> It would seem that having a "CC_capture_warnings" would probably be a
> useful general purpose function to have.

That approach is plausible: compile twice capturing compiler warnings and
fail if the warnings differ.

It's not a route we typically want to take because we'd like to verify that
compiler features actually *work* -- but we're backed into a corner here.

> I would also volunteer to try to implement the technical details for this
> function, unless there are any objections creating such a method?

This would be a nice feature to have.  However, coding it up would actually
take a fair amount of refactoring, as the assumption that we throw away
compiler output is pretty deeply baked in.

It might be quicker to try enabling warnings as errors.  This is done with
-Werror on GCC and Clang, and with /WX on MSVC.

Since this is likely to be a rarely used feature, I'd propose a
CC_warnings_as_errors(int enabled) setter that controls a static variable
within Compiler.c.  If that static variable is non-zero, then we tack on the
extra flag when generating the compiler command within CC_compile_exe() and
CC_compile_obj().

Then in SymbolVisibility.c, we'd enable that setting for only as long as
necessary.

> Or, perhaps the reason it doesn't exist is because it's not trivial for all
> of the various compilers we support?

It's doable but not trivial, both because of the compiler and the shell.  MSVC
writes its boilerplate to stderr, so I'm not sure the approach is
generalizable to all compilers.  And redirection syntax is different under
cmd.exe than under Unix shells.

Marvin Humphrey

Re: [lucy-dev] Clang/Charmonizer

Posted by Logan Bell <lo...@gmail.com>.
It would seem that having a "CC_capture_warnings" would probably be a
useful general purpose function to have.  I would also volunteer to try to
implement the technical details for this function, unless there are any
objections creating such a method? Or, perhaps the reason it doesn't exist
is because it's not trivial for all of the various compilers we support?

Thanks,
Logan



On Thu, Jun 7, 2012 at 5:54 AM, Nick Wellnhofer <we...@aevum.de> wrote:

> On 07/06/2012 07:11, Logan Bell wrote:
>
>> Devs,
>>
>> This last weekend I was attempting to build Lucy from trunk but was
>> failing. My console was being flooded with these sorts of errors:
>>
>> ./charmony.h:292:31: note: expanded from macro 'CHY_EXPORT'
>> #define CHY_EXPORT __declspec(dllexport)
>>                               ^
>> In file included from ../core/Lucy/Index/SegLexicon.**c:18:
>> In file included from ../core/Lucy/Util/ToolSet.h:**40:
>> autogen/include/Lucy/Object/**BitVector.h:349:8: warning: unknown
>> attribute
>> 'dllexport' ignored [-Wattributes]
>> extern CHY_EXPORT size_t Lucy_BitVec_Is_A_OFFSET;
>>
>> After doing some spelunking through the charmonizer code I found that
>> we're
>> doing some probing in src/Charmonizer/Probe/**SymbolVisibility.c to set
>> some
>> macros CHY_EXPORT/CHY_IMPORT based on if some code fragments can compile.
>> The problem is that this probe is failing for my version of clang,
>> charmonizer believes my platform is windows. Reading through the clang
>> documentation it looks like clang will by default drop the Microsoft
>> specific "__declspec(dllexport)" constructs, thus making the test true in
>> this instance. Further, it appears that clang does support most of the gcc
>> specific attributes. So as a hack and potential fix I reversed the logic
>> in
>> this code. This made the build happy with no errors. I have yet to commit
>> this since I'm a bit new to charmonizer and to the various macros it
>> creates and would appreciate any feedback to this patch.
>>
>> The patch is attached to JIRA 237:
>> https://issues.apache.org/**jira/browse/LUCY-237<https://issues.apache.org/jira/browse/LUCY-237>
>>
>
> Yes, the symbol visibility probe still needs some work. The problem is
> that GCC and as it seems also clang only warn about unsupported function
> attributes.
>
> Unfortunately, your patch will break GCC on Windows which relies on the
> old order of probes. For a better solution we'll have to extend Charmonizer
> so that it can either detect compiler warnings or support tests that create
> DLLs and link against them.
>
> Nick
>

Re: [lucy-dev] Clang/Charmonizer

Posted by Nick Wellnhofer <we...@aevum.de>.
On 07/06/2012 07:11, Logan Bell wrote:
> Devs,
>
> This last weekend I was attempting to build Lucy from trunk but was
> failing. My console was being flooded with these sorts of errors:
>
> ./charmony.h:292:31: note: expanded from macro 'CHY_EXPORT'
> #define CHY_EXPORT __declspec(dllexport)
>                                ^
> In file included from ../core/Lucy/Index/SegLexicon.c:18:
> In file included from ../core/Lucy/Util/ToolSet.h:40:
> autogen/include/Lucy/Object/BitVector.h:349:8: warning: unknown attribute
> 'dllexport' ignored [-Wattributes]
> extern CHY_EXPORT size_t Lucy_BitVec_Is_A_OFFSET;
>
> After doing some spelunking through the charmonizer code I found that we're
> doing some probing in src/Charmonizer/Probe/SymbolVisibility.c to set some
> macros CHY_EXPORT/CHY_IMPORT based on if some code fragments can compile.
> The problem is that this probe is failing for my version of clang,
> charmonizer believes my platform is windows. Reading through the clang
> documentation it looks like clang will by default drop the Microsoft
> specific "__declspec(dllexport)" constructs, thus making the test true in
> this instance. Further, it appears that clang does support most of the gcc
> specific attributes. So as a hack and potential fix I reversed the logic in
> this code. This made the build happy with no errors. I have yet to commit
> this since I'm a bit new to charmonizer and to the various macros it
> creates and would appreciate any feedback to this patch.
>
> The patch is attached to JIRA 237:
> https://issues.apache.org/jira/browse/LUCY-237

Yes, the symbol visibility probe still needs some work. The problem is 
that GCC and as it seems also clang only warn about unsupported function 
attributes.

Unfortunately, your patch will break GCC on Windows which relies on the 
old order of probes. For a better solution we'll have to extend 
Charmonizer so that it can either detect compiler warnings or support 
tests that create DLLs and link against them.

Nick