[libc-commits] [libc] [libc] Add program_invocation(_short)_name and tweak err.h functions (PR #212448)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Wed Jul 29 02:23:41 PDT 2026
================
@@ -23,21 +23,21 @@
#include "src/__support/printf_core/printf_main.h"
#include "src/__support/printf_core/writer.h"
-#ifdef __linux__
+#ifdef LIBC_FULL_BUILD
+#include "src/errno/program_invocation_short_name.h"
+#define PROGRAM_INVOCATION_SHORT_NAME \
+ LIBC_NAMESPACE::program_invocation_short_name
+#else
extern "C" char *program_invocation_short_name;
+#define PROGRAM_INVOCATION_SHORT_NAME ::program_invocation_short_name
#endif
namespace LIBC_NAMESPACE_DECL {
namespace err_reporting {
void report(bool show_err, int err_num, const char *fmt,
internal::ArgList &args) {
- const char *progname = "libllvmlibc";
- // TODO: Use a proper way to get progname if available.
-#ifdef __linux__
- progname = program_invocation_short_name;
-#endif
-
+ const char *progname = PROGRAM_INVOCATION_SHORT_NAME;
----------------
labath wrote:
I see three ways this could be null:
- this function is called before the variable is initialized. I think that's unlikely because we set it very early
- we're running on old kernel (see other comment). This will not be an issue if we add the independent mitigation.
- user code has modified this variable. If they start doing that, then all bets are off. We could try to make it harder by mprotecting the variables after initialization, though this will likely involve a linker script.
With this in mind I don't think the backup is necessary, though it also doesn't cost much, so I'm open to adding that, or a LIBC_CRASH_ON_NULLPTR.
https://github.com/llvm/llvm-project/pull/212448
More information about the libc-commits
mailing list