Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
loader: set PT_INTERP to itself
Browse files Browse the repository at this point in the history
Some versions of kernel set AT_BASE to 0
if dynamic loader does not have PT_INTERP
set.

Bug: http://b/30739481
Test: run /system/bin/linker64 and /system/bin/linker
Change-Id: I1b67777166fe917d3ee1a97277045ca6f5db0084
  • Loading branch information
dimitry- committed Feb 25, 2017
1 parent 5927b04 commit 2a6955e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions linker/Android.bp
Expand Up @@ -39,29 +39,35 @@ cc_binary {
srcs: ["arch/arm/begin.S"],

cflags: ["-D__work_around_b_24465209__"],
ldflags: ["-Wl,-dynamic-linker,/system/bin/linker"],
},
arm64: {
srcs: ["arch/arm64/begin.S"],
ldflags: ["-Wl,-dynamic-linker,/system/bin/linker64"],
},
x86: {
srcs: ["arch/x86/begin.c"],

cflags: ["-D__work_around_b_24465209__"],
ldflags: ["-Wl,-dynamic-linker,/system/bin/linker"],
},
x86_64: {
srcs: ["arch/x86_64/begin.S"],
ldflags: ["-Wl,-dynamic-linker,/system/bin/linker64"],
},
mips: {
srcs: [
"arch/mips/begin.S",
"linker_mips.cpp",
],
ldflags: ["-Wl,-dynamic-linker,/system/bin/linker"],
},
mips64: {
srcs: [
"arch/mips64/begin.S",
"linker_mips.cpp",
],
ldflags: ["-Wl,-dynamic-linker,/system/bin/linker64"],
},
},

Expand Down
2 changes: 1 addition & 1 deletion linker/linker_main.cpp
Expand Up @@ -496,7 +496,7 @@ extern "C" ElfW(Addr) __linker_init(void* raw_args) {
// see also https://code.google.com/p/android/issues/detail?id=63174
if (reinterpret_cast<ElfW(Addr)>(&_start) == entry_point) {
__libc_format_fd(STDOUT_FILENO,
"This is %s, the helper program for shared library executables.\n",
"This is %s, the helper program for dynamic executables.\n",
args.argv[0]);
exit(0);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/dl_test.cpp
Expand Up @@ -24,6 +24,8 @@

#include <string>

#include "utils.h"

extern "C" int main_global_default_serial() {
return 3370318;
}
Expand Down Expand Up @@ -69,4 +71,19 @@ TEST(dl, lib_does_not_preempt_global_protected) {
ASSERT_EQ(3370318, lib_global_protected_get_serial());
}

TEST(dl, exec_linker) {
#if defined(__BIONIC__)
#if defined(__LP64__)
static constexpr const char* kPathToLinker = "/system/bin/linker64";
#else
static constexpr const char* kPathToLinker = "/system/bin/linker";
#endif
ExecTestHelper eth;
std::string expected_output = std::string("This is ") + kPathToLinker +
", the helper program for dynamic executables.\n";
eth.SetArgs( { kPathToLinker, nullptr });
eth.Run([&]() { execve(kPathToLinker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str());
#endif
}

// TODO: Add tests for LD_PRELOADs

0 comments on commit 2a6955e

Please sign in to comment.