diff options
author | Bill XIE <persmule@hardenedlinux.org> | 2022-07-08 16:53:21 +0800 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2022-07-14 23:08:09 +0000 |
commit | ac136250b26ddcb54d61ed8428f110b607cb3c88 (patch) | |
tree | 40be3a5d3f1674bd18b44e3c45cc3ac1ef9af017 /src/commonlib | |
parent | f7ba881f98db6561e8c4964663f8774e1a82f41b (diff) |
commonlib: Substitude macro "__unused" in compiler.h
Since there are many identifiers whose name contain "__unused" in
headers of musl libc, introducing a macro which expands "__unused" to
the source of a util may have disastrous effect during its compiling
under a musl-based platform.
However, it is hard to detect musl at build time as musl is notorious
for having explicitly been refusing to add a macro like "__MUSL__" to
announce its own presence.
Using __always_unused and __maybe_unused for everything may be a good
idea. This is how it works in the Linux kernel, so that would at least
make us match some other standard rather than doing our own thing
(especially since the other compiler.h shorthand macros are also
inspired by Linux).
Signed-off-by: Bill XIE <persmule@hardenedlinux.org>
Change-Id: I547ae3371d7568f5aed732ceefe0130a339716a9
Reviewed-on: https://review.coreboot.org/c/coreboot/+/65717
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src/commonlib')
-rw-r--r-- | src/commonlib/bsd/include/commonlib/bsd/compiler.h | 17 | ||||
-rw-r--r-- | src/commonlib/region.c | 9 |
2 files changed, 20 insertions, 6 deletions
diff --git a/src/commonlib/bsd/include/commonlib/bsd/compiler.h b/src/commonlib/bsd/include/commonlib/bsd/compiler.h index 42f9235e8e..aada973749 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/compiler.h +++ b/src/commonlib/bsd/include/commonlib/bsd/compiler.h @@ -15,8 +15,21 @@ #define __aligned(x) __attribute__((__aligned__(x))) #endif -#ifndef __unused -#define __unused __attribute__((__unused__)) +/* Because there may be variables/parameters whose name contains "__unused" in + header files of libc, namely musl, these names consistent with ones in the + Linux kernel may be a better choice. */ + +/* This is used to mark identifiers unused in all conditions, e.g. a parameter + completely unused in all code branch, only present to fit an API. */ +#ifndef __always_unused +#define __always_unused __attribute__((__unused__)) +#endif + +/* This is used to mark identifiers unused in some conditions, e.g. a parameter + only unused in some code branches, a global variable only accessed with code + being conditionally preprocessed, etc. */ +#ifndef __maybe_unused +#define __maybe_unused __attribute__((__unused__)) #endif #ifndef __must_check diff --git a/src/commonlib/region.c b/src/commonlib/region.c index 04c3180754..252f6faf12 100644 --- a/src/commonlib/region.c +++ b/src/commonlib/region.c @@ -222,7 +222,7 @@ void xlate_window_init(struct xlate_window *window, const struct region_device * } static void *mdev_mmap(const struct region_device *rd, size_t offset, - size_t size __unused) + size_t size __always_unused) { const struct mem_region_device *mdev; @@ -231,8 +231,8 @@ static void *mdev_mmap(const struct region_device *rd, size_t offset, return &mdev->base[offset]; } -static int mdev_munmap(const struct region_device *rd __unused, - void *mapping __unused) +static int mdev_munmap(const struct region_device *rd __always_unused, + void *mapping __always_unused) { return 0; } @@ -368,7 +368,8 @@ static void *xlate_mmap(const struct region_device *rd, size_t offset, return rdev_mmap(xlwindow->access_dev, offset, size); } -static int xlate_munmap(const struct region_device *rd __unused, void *mapping __unused) +static int xlate_munmap(const struct region_device *rd __always_unused, + void *mapping __always_unused) { /* * xlate_region_device does not keep track of the access device that was used to service |