Anastasia Klimchuk submitted this change.

View Change



5 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.

Approvals: build bot (Jenkins): Verified Felix Singer: Looks good to me, approved Peter Marheine: Looks good to me, but someone else must approve
tests: Undefine _FORTIFY_SOURCE for unit tests to avoid _chk variants

The option _FORTIFY_SOURCE, when enabled, can result in some functions
being expanded into _chk variants. For example, `fprintf` can get
expanded into `__fprintf_chk`. This makes sense for building a real
binary, but is not needed for unit tests.

In unit test environment all those functions are wrapped. In the
example above, both `fprintf` and `__fprintf_chk` needed to be mocked.
Disabling _FORTIFY_SOURCE avoids expanding functions into _chk
variants, without any loss of testing coverage because that would
be wrapped/mocked anyway.

This patch also removes two existing _chk wraps because they are not
needed anymore.

BUG=b:237606255
TEST=ninja test on
1) gcc 12.2.0 on Debian
2) clang 15.0 on Chromium OS

Ticket: https://ticket.coreboot.org/issues/411
Change-Id: I70cb1cd90d1f377ff4606acad3c1b514120ae4f7
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/68432
Reviewed-by: Peter Marheine <pmarheine@chromium.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
---
M tests/meson.build
M tests/tests.c
2 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/tests/meson.build b/tests/meson.build
index b0375a1..66adb92 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -69,9 +69,7 @@
'-Wl,--wrap=fsync',
'-Wl,--wrap=fread',
'-Wl,--wrap=fgets',
- '-Wl,--wrap=__fgets_chk',
'-Wl,--wrap=fprintf',
- '-Wl,--wrap=__vfprintf_chk',
'-Wl,--wrap=fclose',
'-Wl,--wrap=feof',
'-Wl,--wrap=ferror',
@@ -115,6 +113,7 @@
cargs,
'-ffunction-sections',
'-fdata-sections',
+ '-U_FORTIFY_SOURCE',
],
export_dynamic : true,
link_args : mocks,
diff --git a/tests/tests.c b/tests/tests.c
index 53bad65..77cb1ef 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -222,14 +222,6 @@
return NULL;
}

-char *__wrap___fgets_chk(char *buf, int len, FILE *fp)
-{
- LOG_ME;
- if (get_io() && get_io()->fgets)
- return get_io()->fgets(get_io()->state, buf, len, fp);
- return NULL;
-}
-
size_t __wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *fp)
{
LOG_ME;
@@ -282,14 +274,6 @@
return 0;
}

-int __wrap___vfprintf_chk(FILE *fp, const char *fmt, va_list args)
-{
- LOG_ME;
- if (get_io() && get_io()->fprintf)
- return get_io()->fprintf(get_io()->state, fp, fmt, args);
- return 0;
-}
-
int __wrap_fclose(FILE *fp)
{
LOG_ME;

To view, visit change 68432. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I70cb1cd90d1f377ff4606acad3c1b514120ae4f7
Gerrit-Change-Number: 68432
Gerrit-PatchSet: 7
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Felix Singer <felixsinger@posteo.net>
Gerrit-Reviewer: Peter Marheine <pmarheine@chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src@posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged