Skip to content

Commit

Permalink
modpost: avoid using the alias attribute
Browse files Browse the repository at this point in the history
Aiden Leong reported modpost fails to build on macOS since commit
16a473f ("modpost: inform compilers that fatal() never returns"):

  scripts/mod/modpost.c:93:21: error: aliases are not supported on darwin

Nathan's research indicates that Darwin seems to support weak aliases
at least [1]. Although the situation might be improved in future Clang
versions, we can achieve a similar outcome without relying on it.

This commit makes fatal() a macro of error() + exit(1) in modpost.h, as
compilers recognize that exit() never returns.

[1]: llvm/llvm-project#71001

Fixes: 16a473f ("modpost: inform compilers that fatal() never returns")
Reported-by: Aiden Leong <aiden.leong@aibsd.com>
Closes: https://lore.kernel.org/all/d9ac2960-6644-4a87-b5e4-4bfb6e0364a8@aibsd.com/
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
  • Loading branch information
masahir0y committed Jan 27, 2024
1 parent e44ed91 commit 10a73af
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
12 changes: 1 addition & 11 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ void modpost_log(enum loglevel loglevel, const char *fmt, ...)
break;
case LOG_ERROR:
fprintf(stderr, "ERROR: ");
break;
case LOG_FATAL:
fprintf(stderr, "FATAL: ");
error_occurred = true;
break;
default: /* invalid loglevel, ignore */
break;
Expand All @@ -83,16 +81,8 @@ void modpost_log(enum loglevel loglevel, const char *fmt, ...)
va_start(arglist, fmt);
vfprintf(stderr, fmt, arglist);
va_end(arglist);

if (loglevel == LOG_FATAL)
exit(1);
if (loglevel == LOG_ERROR)
error_occurred = true;
}

void __attribute__((alias("modpost_log")))
modpost_log_noret(enum loglevel loglevel, const char *fmt, ...);

static inline bool strends(const char *str, const char *postfix)
{
if (strlen(str) < strlen(postfix))
Expand Down
6 changes: 1 addition & 5 deletions scripts/mod/modpost.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,11 @@ void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym);
enum loglevel {
LOG_WARN,
LOG_ERROR,
LOG_FATAL
};

void __attribute__((format(printf, 2, 3)))
modpost_log(enum loglevel loglevel, const char *fmt, ...);

void __attribute__((format(printf, 2, 3), noreturn))
modpost_log_noret(enum loglevel loglevel, const char *fmt, ...);

/*
* warn - show the given message, then let modpost continue running, still
* allowing modpost to exit successfully. This should be used when
Expand All @@ -218,4 +214,4 @@ modpost_log_noret(enum loglevel loglevel, const char *fmt, ...);
*/
#define warn(fmt, args...) modpost_log(LOG_WARN, fmt, ##args)
#define error(fmt, args...) modpost_log(LOG_ERROR, fmt, ##args)
#define fatal(fmt, args...) modpost_log_noret(LOG_FATAL, fmt, ##args)
#define fatal(fmt, args...) do { error(fmt, ##args); exit(1); } while (1)

0 comments on commit 10a73af

Please sign in to comment.