Merge "Reimplement realpath."
diff --git a/docs/status.md b/docs/status.md
index 5470668..fb88dd2 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -33,7 +33,11 @@
Missing functionality:
* `<aio.h>`
* `<wordexp.h>`
- * Thread cancellation (`pthread_cancel`).
+ * Thread cancellation (`pthread_cancel`). Unlikely to ever be implemented
+ because of the difficulty and cost of implementing it, and the difficulty
+ of using it correctly. See
+ [This is why we can't have safe cancellation points](https://lwn.net/Articles/683118/)
+ for more about thread cancellation.
* Robust mutexes
Run `./libc/tools/check-symbols-glibc.py` in bionic/ for the current
diff --git a/libc/NOTICE b/libc/NOTICE
index fd2fd32..87d39c9 100644
--- a/libc/NOTICE
+++ b/libc/NOTICE
@@ -1096,6 +1096,34 @@
-------------------------------------------------------------------
+Copyright (C) 2020 The Android Open Source Project
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
Copyright (c) 1980, 1983, 1988, 1993
The Regents of the University of California. All rights reserved.
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index d64a6bd..b3f4f3d 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -94,7 +94,7 @@
// Initialize various globals.
environ = __libc_shared_globals()->init_environ;
errno = 0;
- __progname = __libc_shared_globals()->init_progname ?: "<unknown>";
+ setprogname(__libc_shared_globals()->init_progname ?: "<unknown>");
#if !defined(__LP64__)
__check_max_thread_id();
diff --git a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
index c405c7f..1298df7 100644
--- a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
+++ b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
@@ -1532,7 +1532,8 @@
BacktraceUnwindFake(
std::vector<unwindstack::LocalFrameData>{{nullptr, 0x1100, 0x100, "fake1", 10},
{nullptr, 0x1200, 0x200, "fake2", 20}});
- unwindstack::MapInfo map_info{nullptr, 0x10000, 0x20000, 0, PROT_READ | PROT_EXEC, "/data/fake.so"};
+ unwindstack::MapInfo map_info{nullptr, nullptr, 0x10000, 0x20000, 0,
+ PROT_READ | PROT_EXEC, "/data/fake.so"};
BacktraceUnwindFake(
std::vector<unwindstack::LocalFrameData>{{&map_info, 0x1a000, 0xa000, "level1", 0},
{&map_info, 0x1b000, 0xb000, "level2", 10}});
diff --git a/linker/arch/arm_neon/linker_gnu_hash_neon.cpp b/linker/arch/arm_neon/linker_gnu_hash_neon.cpp
index f4127ce..11cf5a3 100644
--- a/linker/arch/arm_neon/linker_gnu_hash_neon.cpp
+++ b/linker/arch/arm_neon/linker_gnu_hash_neon.cpp
@@ -156,7 +156,7 @@
// Reverse the is-NUL vector so we can use clz to count the number of remaining bytes.
is_nul = vrev64_u8(is_nul);
const uint64_t is_nul_u64 = vget_lane_u64(vreinterpret_u64_u8(is_nul), 0);
- const uint32_t num_valid_bits = is_nul_u64 == 0 ? 64 : __builtin_clzll(is_nul_u64);
+ const uint32_t num_valid_bits = __builtin_clzll(is_nul_u64);
const uint32_t name_len = reinterpret_cast<const char*>(chunk_ptr) - name + (num_valid_bits >> 3);
diff --git a/tests/dl_test.cpp b/tests/dl_test.cpp
index 05bba05..2b963c7 100644
--- a/tests/dl_test.cpp
+++ b/tests/dl_test.cpp
@@ -135,7 +135,7 @@
std::string expected_output =
"ctor: argc=1 argv[0]=" + helper + "\n" +
"main: argc=1 argv[0]=" + helper + "\n" +
- "__progname=" + helper + "\n" +
+ "__progname=exec_linker_helper\n" +
"helper_func called\n";
ExecTestHelper eth;
eth.SetArgs({ path_to_linker, helper.c_str(), nullptr });
@@ -151,7 +151,7 @@
std::string expected_output =
"ctor: argc=1 argv[0]=" + helper + "\n" +
"main: argc=1 argv[0]=" + helper + "\n" +
- "__progname=" + helper + "\n" +
+ "__progname=exec_linker_helper\n" +
"helper_func called\n";
ExecTestHelper eth;
eth.SetArgs({ path_to_linker, helper.c_str(), nullptr });
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index c522fff..3f1ec86 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -926,3 +926,24 @@
ASSERT_TRUE(fabs(expected[1] - load[1]) < 0.5) << expected[1] << ' ' << load[1];
ASSERT_TRUE(fabs(expected[2] - load[2]) < 0.5) << expected[2] << ' ' << load[2];
}
+
+TEST(stdlib, getprogname) {
+#if defined(__GLIBC__)
+ GTEST_SKIP() << "glibc doesn't have getprogname()";
+#else
+ // You should always have a name.
+ ASSERT_TRUE(getprogname() != nullptr);
+ // The name should never have a slash in it.
+ ASSERT_TRUE(strchr(getprogname(), '/') == nullptr);
+#endif
+}
+
+TEST(stdlib, setprogname) {
+#if defined(__GLIBC__)
+ GTEST_SKIP() << "glibc doesn't have setprogname()";
+#else
+ // setprogname() only takes the basename of what you give it.
+ setprogname("/usr/bin/muppet");
+ ASSERT_STREQ("muppet", getprogname());
+#endif
+}