gdb build problem (gdb/unittests/scoped_mmap-selftests.c)

Message ID 87sh3o91y2.fsf@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Aug. 8, 2018, 5:56 p.m. UTC
  >>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Simon> I think that enabling _FORTIFY_SOURCE can only do some good.

What do you think of the appended?
The check for __OPTIMIZE__ has to be done since otherwise a glibc header
will complain.

Building with this patch applied (after autoheader etc) let me reproduce
Steve's original problem.

Tom
  

Comments

Simon Marchi Aug. 8, 2018, 10:17 p.m. UTC | #1
On 2018-08-08 13:56, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
> 
> Simon> I think that enabling _FORTIFY_SOURCE can only do some good.
> 
> What do you think of the appended?
> The check for __OPTIMIZE__ has to be done since otherwise a glibc 
> header
> will complain.
> 
> Building with this patch applied (after autoheader etc) let me 
> reproduce
> Steve's original problem.
> 
> Tom
> 
> diff --git a/gdb/configure.ac b/gdb/configure.ac
> index 13bc5f9a8f2..76a1ba0364f 100644
> --- a/gdb/configure.ac
> +++ b/gdb/configure.ac
> @@ -2279,6 +2279,10 @@ dnl  At the moment, we just assume it's UTF-8.
>  AC_DEFINE(GDB_DEFAULT_HOST_CHARSET, "UTF-8",
>            [Define to be a string naming the default host character 
> set.])
> 
> +AH_BOTTOM([#if defined __OPTIMIZE__ && __OPTIMIZE__ > 0
> +#define _FORTIFY_SOURCE 2
> +#endif])
> +
>  if $development; then
>    AC_DEFINE(GDB_SELF_TEST, 1,
>              [Define if self-testing features should be enabled])

Oh right, _FORTIFY_SOURCE requires building with optimization.  That 
code will end up at the bottom of config.h, is that it?  If so, it LGTM.

Simon
  
Pedro Alves Aug. 9, 2018, 1:28 p.m. UTC | #2
On 08/08/2018 06:56 PM, Tom Tromey wrote:

> diff --git a/gdb/configure.ac b/gdb/configure.ac
> index 13bc5f9a8f2..76a1ba0364f 100644
> --- a/gdb/configure.ac
> +++ b/gdb/configure.ac
> @@ -2279,6 +2279,10 @@ dnl  At the moment, we just assume it's UTF-8.
>  AC_DEFINE(GDB_DEFAULT_HOST_CHARSET, "UTF-8",
>            [Define to be a string naming the default host character set.])
>  
> +AH_BOTTOM([#if defined __OPTIMIZE__ && __OPTIMIZE__ > 0
> +#define _FORTIFY_SOURCE 2
> +#endif])

Do we really need to put this in config.h?  Wouldn't putting it straight
in common/common-defs.h work out the same?  We already define
__STDC_CONSTANT_MACRO etc. there before any system header.

Thanks,
Pedro Alves
  
Tom Tromey Aug. 9, 2018, 2:33 p.m. UTC | #3
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> On 08/08/2018 06:56 PM, Tom Tromey wrote:
>> diff --git a/gdb/configure.ac b/gdb/configure.ac
>> index 13bc5f9a8f2..76a1ba0364f 100644
>> --- a/gdb/configure.ac
>> +++ b/gdb/configure.ac
>> @@ -2279,6 +2279,10 @@ dnl  At the moment, we just assume it's UTF-8.
>> AC_DEFINE(GDB_DEFAULT_HOST_CHARSET, "UTF-8",
>> [Define to be a string naming the default host character set.])
>> 
>> +AH_BOTTOM([#if defined __OPTIMIZE__ && __OPTIMIZE__ > 0
>> +#define _FORTIFY_SOURCE 2
>> +#endif])

Pedro> Do we really need to put this in config.h?  Wouldn't putting it straight
Pedro> in common/common-defs.h work out the same?  We already define
Pedro> __STDC_CONSTANT_MACRO etc. there before any system header.

That does seems simpler, and I think it will work just as well.

Tom
  

Patch

diff --git a/gdb/configure.ac b/gdb/configure.ac
index 13bc5f9a8f2..76a1ba0364f 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -2279,6 +2279,10 @@  dnl  At the moment, we just assume it's UTF-8.
 AC_DEFINE(GDB_DEFAULT_HOST_CHARSET, "UTF-8",
           [Define to be a string naming the default host character set.])
 
+AH_BOTTOM([#if defined __OPTIMIZE__ && __OPTIMIZE__ > 0
+#define _FORTIFY_SOURCE 2
+#endif])
+
 if $development; then
   AC_DEFINE(GDB_SELF_TEST, 1,
             [Define if self-testing features should be enabled])