Re: Clean up some signal usage mainly related to Windows - Mailing list pgsql-hackers

From Tristan Partin
Subject Re: Clean up some signal usage mainly related to Windows
Date
Msg-id CXHE5M1YJ97P.3N4VA08G6LH6R@neon.tech
Whole thread Raw
In response to Re: Clean up some signal usage mainly related to Windows  (Nathan Bossart <nathandbossart@gmail.com>)
Responses Re: Clean up some signal usage mainly related to Windows
List pgsql-hackers
On Wed Dec 6, 2023 at 10:18 AM CST, Nathan Bossart wrote:
> On Wed, Dec 06, 2023 at 10:23:52AM +0100, Peter Eisentraut wrote:
> > Ok, I have committed your 0001 patch.
>
> My compiler is unhappy about this one:
>
> ../postgresql/src/bin/pg_test_fsync/pg_test_fsync.c:605:2: error: ignoring return value of ‘write’, declared with
attributewarn_unused_result [-Werror=unused-result] 
>   605 |  write(STDOUT_FILENO, "\n", 1);
>       |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Some glibc source:

> /* If fortification mode, we warn about unused results of certain
>    function calls which can lead to problems.  */
> #if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
> # define __attribute_warn_unused_result__ \
>    __attribute__ ((__warn_unused_result__))
> # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
> #  define __wur __attribute_warn_unused_result__
> # endif
> #else
> # define __attribute_warn_unused_result__ /* empty */
> #endif
> #ifndef __wur
> # define __wur /* Ignore */
> #endif

> extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur
>     __attr_access ((__read_only__, 2, 3));

According to my setup, I am hitting the /* Ignore */ variant of __wur.
I am guessing that Fedora doesn't add fortification to the default
CFLAGS. What distro are you using? But yes, something like what you
proposed sounds good to me. Sorry for leaving this out!

Makes me wonder if setting -D_FORTIFY_SOURCE=2 in debug builds at least
would make sense, if not all builds. According to the OpenSSF[0], level
2 is only supposed to impact runtime performance by 0.1%.

[0]:
https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html#performance-implications

--
Tristan Partin
Neon (https://neon.tech)



pgsql-hackers by date:

Previous
From: Sehrope Sarkuni
Date:
Subject: Re: Emitting JSON to file using COPY TO
Next
From: Tom Lane
Date:
Subject: Re: Emitting JSON to file using COPY TO