all: better workaround for __FILE_NAME__

There's only a few legacy releases of gcc and clang that
support -fmacro-prefix-map but not __FILE_NAME__.
Thus the originial workaround is not very beneficial.

Switching to a more portable `__FILE__ + offset` workaround
that works for any standard-compliant compiler, even TinyCC.

However, this workaround may produce binaries that leak
information about the build environment, especially when using
an exotic build path.
This commit is contained in:
CismonX 2025-02-01 23:13:39 +08:00
parent 5286cda051
commit c17d6ebadf
No known key found for this signature in database
GPG key ID: 3094873E29A482FB
3 changed files with 8 additions and 15 deletions

View file

@ -198,17 +198,11 @@ AC_COMPILE_IFELSE([
AC_LANG_SOURCE([[char const *name = __FILE_NAME__;]]) AC_LANG_SOURCE([[char const *name = __FILE_NAME__;]])
], [ ], [
AC_MSG_RESULT([yes]) AC_MSG_RESULT([yes])
AS_VAR_SET([no_file_name], [no])
], [ ], [
AC_MSG_RESULT([no]) AC_MSG_RESULT([no])
AX_CHECK_COMPILE_FLAG([-fmacro-prefix-map==], [
AS_VAR_SET([macro_prefix_map], [yes])
], [
AC_MSG_WARN(m4_normalize([
The `-fmacro-prefix-map' preprocessor flag is not supported.
]))
])
]) ])
AM_CONDITIONAL([MACRO_PREFIX_MAP], [test x${macro_prefix_map} != xno]) AM_CONDITIONAL([NO_FILE_NAME], [test x${no_file_name} != xno])
AC_SYS_LARGEFILE AC_SYS_LARGEFILE
AS_VAR_IF([ac_have_largefile], [no], [ AS_VAR_IF([ac_have_largefile], [no], [

View file

@ -14,9 +14,9 @@ lib_LTLIBRARIES =
pkglib_LTLIBRARIES = pkglib_LTLIBRARIES =
BASE_CPPFLAGS_ = -DBUILDING_BOOKMARKFS BASE_CPPFLAGS_ = -DBUILDING_BOOKMARKFS
if MACRO_PREFIX_MAP if NO_FILE_NAME
BASE_CPPFLAGS_ += -fmacro-prefix-map=$(srcdir)/= BASE_CPPFLAGS_ += -DBOOKMARKFS_SRCDIR=\"$(srcdir)\"
endif # MACRO_PREFIX_MAP endif # NO_FILE_NAME
MODULE_CFLAGS_ = MODULE_CFLAGS_ =
if HIDE_MODULE_SYMBOLS if HIDE_MODULE_SYMBOLS
@ -55,7 +55,8 @@ endif # BOOKMARKFS_UTIL
if BOOKMARKCTL if BOOKMARKCTL
bin_PROGRAMS += bookmarkctl bin_PROGRAMS += bookmarkctl
bookmarkctl_SOURCES = bookmarkctl.c fsck_util.c bookmarkctl_CPPFLAGS = $(BASE_CPPFLAGS_)
bookmarkctl_SOURCES = bookmarkctl.c fsck_util.c
endif # BOOKMARKCTL endif # BOOKMARKCTL
if BOOKMARKFS_FSCK if BOOKMARKFS_FSCK

View file

@ -114,9 +114,7 @@
#ifdef __FILE_NAME__ #ifdef __FILE_NAME__
# define FILE_NAME_ __FILE_NAME__ # define FILE_NAME_ __FILE_NAME__
#else #else
// NOTE: Using __FILE__ may produce ugly logs and break reproducible build. # define FILE_NAME_ ( __FILE__ + sizeof(BOOKMARKFS_SRCDIR) )
// Workaround with `-fmacro-prefix-map=${srcdir}/=` CPPFLAGS.
# define FILE_NAME_ __FILE__
#endif #endif
#define BOOKMARKFS_HOMEPAGE_URL "https://nongnu.org/bookmarkfs" #define BOOKMARKFS_HOMEPAGE_URL "https://nongnu.org/bookmarkfs"