[PATCH][GOLD] Fix build breakage on OSX due to unintended macro substitution.

Doug Kwan (關振德) dougkwan@google.com
Mon Jan 11 07:41:00 GMT 2010


Your suggestion works.  Here is the committed patch.

Thank you.

-Doug

2010-01-10  Doug Kwan  <dougkwan@google.com>

       * options.h (DEFINE_var): Use parentheses around argument varname__
       in macro body to avoid any unintended subsequent substitutions.

Index: gold/options.h
===================================================================
RCS file: /cvs/src/src/gold/options.h,v
retrieving revision 1.136
diff -u -p -r1.136 options.h
--- gold/options.h      7 Jan 2010 18:31:30 -0000       1.136
+++ gold/options.h      11 Jan 2010 07:36:25 -0000
@@ -244,12 +244,18 @@ struct Struct_special : public Struct_va
 // var() and set_var() as General_options methods.  Arguments as are
 // for the constructor for One_option.  param_type__ is the same as
 // type__ for built-in types, and "const type__ &" otherwise.
+//
+// When we define the linker command option "assert", the macro argument
+// varname__ of DEFINE_var below will be replaced by "assert".  On Mac OSX
+// assert.h is included implicitly by one of the library headers we use.  To
+// avoid unintended macro substitution of "assert()", we need to enclose
+// varname__ with parenthese.
 #define DEFINE_var(varname__, dashes__, shortname__, default_value__,        \
                    default_value_as_string__, helpstring__, helparg__,       \
                    optional_arg__, type__, param_type__, parse_fn__)        \
  public:                                                                     \
   param_type__                                                               \
-  varname__() const                                                          \
+  (varname__)() const                                                        \
   { return this->varname__##_.value; }                                       \
                                                                              \
   bool                                                                       \


2010/1/10 Ian Lance Taylor <iant@google.com>:
> "Doug Kwan (關振德)" <dougkwan@google.com> writes:
>
>> +// This is defined to avoid unintended macro substitutions in DEFINE_var below.
>> +// On Mac OSX, assert.h is included transitively by some other library headers
>> +// we use.   We need to use EMPTY_PARAMETER_LIST to avoid assert() being
>> +// substituted as a macro when the "assert" command line option is defined.
>> +// Note that this only deals with function-like macros.
>> +
>> +#define EMPTY_PARAMETER_LIST ()
>>
>>  // These are helper macros use by DEFINE_uint64/etc below.
>>  // This macro is used inside the General_options_ class, so defines
>> @@ -249,7 +256,7 @@ struct Struct_special : public Struct_va
>>                     optional_arg__, type__, param_type__, parse_fn__)      \
>>   public:                                                                     \
>>    param_type__                                                               \
>> -  varname__() const                                                          \
>> +  varname__ EMPTY_PARAMETER_LIST const                                       \
>
> Does it work to write
>    (varname__)() const
> ?  If it does, please do that instead, with a short comment.  Thanks.
>
> Ian
>



More information about the Binutils mailing list