PATCH COMMITTED: PR 6493: Work around -D_FORTIFY_SOURCE
Ian Lance Taylor
iant@google.com
Fri May 9 15:20:00 GMT 2008
Michael Hennebry <hennebry@web.cs.ndsu.nodak.edu> writes:
> On Fri, 9 May 2008, Ian Lance Taylor wrote:
>
>> PR 6493 is about a warning in gold when compiling with
>> -D_FORTIFY_SOURCE (at least, I assume they are using that -D option,
>> as otherwise the bug report does not make sense). In this case gold
>> is calling write in an error case, so it is correctly ignoring the
>> return value. This patch adds some pointless uses of the return value
>> to avoid the warning.
>
> I thought that was what coercion to void was for.
> It would also have the side-effect of being
> more informative to subsequent readers.
As you can see in the comment I added in the patch, casting to void
did not eliminate the warning when using gcc 4.3.0. This may be a bug
in gcc 4.3.0; I haven't looked.
Ian
>> Index: gold.cc
>> ===================================================================
>> RCS file: /cvs/src/src/gold/gold.cc,v
>> retrieving revision 1.55
>> diff -p -u -r1.55 gold.cc
>> --- gold.cc 7 May 2008 06:08:01 -0000 1.55
>> +++ gold.cc 9 May 2008 14:12:14 -0000
>> @@ -60,9 +60,18 @@ gold_nomem()
>> // We are out of memory, so try hard to print a reasonable message.
>> // Note that we don't try to translate this message, since the
>> // translation process itself will require memory.
>> - write(2, program_name, strlen(program_name));
>> - const char* const s = ": out of memory\n";
>> - write(2, s, strlen(s));
>> +
>> + // LEN only exists to avoid a pointless warning when write is
>> + // declared with warn_use_result, as when compiling with
>> + // -D_USE_FORTIFY on GNU/Linux. Casting to void does not appear to
>> + // work, at least not with gcc 4.3.0.
>> +
>> + ssize_t len = write(2, program_name, strlen(program_name));
>> + if (len >= 0)
>> + {
>> + const char* const s = ": out of memory\n";
>> + len = write(2, s, strlen(s));
>
> (void)write(2, s, strlen(s));
>
>
>> + }
>> gold_exit(false);
>> }
>
> --
> Michael hennebry@web.cs.ndsu.NoDak.edu
> "Those parts of the system that you can hit with a hammer (not advised)
> are called Hardware; those program instructions that you can only
> curse at are called Software."
More information about the Binutils
mailing list