[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
Mon Aug 3 02:16:12 PDT 2026


================
@@ -0,0 +1,103 @@
+//===-- Integration test for program_invocation_name ---------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/errno/program_invocation_name.h"
+#include "src/errno/program_invocation_short_name.h"
+#include "src/unistd/execve.h"
+#include "test/IntegrationTest/test.h"
+
+static bool my_streq(const char *lhs, const char *rhs) {
+  const char *l, *r;
+  for (l = lhs, r = rhs; *l != '\0' && *r != '\0'; ++l, ++r)
+    if (*l != *r)
+      return false;
+
+  return *l == '\0' && *r == '\0';
+}
+
+TEST_MAIN(int argc, char **argv, char **envp) {
----------------
labath wrote:

On second thought, I don't like the "independent mitigation" approach that much. To do that we'd need to either repack the stack (probably via asm) in _start, or call main with argv pointing to some other location. The first is fiddly (and nearly untestable), while the second one risks breaking assumptions (in our or user code) about the argv layout.

Technically, this is only a problem with argv. Pointing `program_invocation_name` to a different string is easier, but I think it's important to have program_invocation_name and argv[0] have the same value (point to the same string).

Going with the first option instead.

https://github.com/llvm/llvm-project/pull/212448


More information about the libc-commits mailing list