aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-03-12 23:12:46 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-03-12 23:12:46 +0000
commit312912c958a49b652a75a91d2f2acf239802d9fc (patch)
treeb2b38ba9690a888c48c52f0dae9281f1e528ceef
parent4bb95c6e764a40c1e493cc57e4aa8047ad5f1adc (diff)
parent55ae73b19d05d518d0eb7c23b4609b420f8e6909 (diff)
downloadslang-android10-d4-s1-release.tar.gz
Snap for 6290860 from 55ae73b19d05d518d0eb7c23b4609b420f8e6909 to qt-d4-releaseandroid-10.0.0_r45android-10.0.0_r44android-10.0.0_r43android-10.0.0_r42android10-d4-s1-releaseandroid10-d4-release
Change-Id: Iaca317c5ae812737f9f3910d54d346d93ccfefe3
-rw-r--r--Android.bp18
-rw-r--r--lld_main.cpp66
2 files changed, 84 insertions, 0 deletions
diff --git a/Android.bp b/Android.bp
index c8fe151..2bc5269 100644
--- a/Android.bp
+++ b/Android.bp
@@ -194,6 +194,24 @@ cc_binary_host {
},
}
+cc_binary_host {
+ name: "lld",
+ srcs: ["lld_main.cpp"],
+ ldflags: ["-static"],
+ stl: "libc++_static",
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ linux: {
+ enabled: false,
+ },
+ windows: {
+ enabled: true,
+ },
+ },
+}
+
subdirs = [
"BitWriter_2_9",
"BitWriter_2_9_func",
diff --git a/lld_main.cpp b/lld_main.cpp
new file mode 100644
index 0000000..dc095bd
--- /dev/null
+++ b/lld_main.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2020, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cstdio>
+#include <cstdlib>
+#include <string>
+#include <vector>
+#include <unistd.h>
+
+int main(int argc, const char **argv) {
+ // Create a copy of argv strings that we can modify, and then eventually
+ // const_cast away the const-ness of the buffers to call execv().
+ std::vector<std::unique_ptr<std::string>> argv_strings;
+ std::vector<const char *> argv_chars;
+
+ // Replace lld.exe with lld-bin\lld.exe instead on Windows.
+ argv_strings.push_back(std::make_unique<std::string>(argv[0]));
+ size_t idx = argv_strings[0]->rfind("lld.exe");
+ argv_strings[0]->insert(idx, "lld-bin\\");
+ argv_chars.push_back(argv_strings[0]->c_str());
+
+ // Make a copy of every other argv entry, and map a pointer to the C string
+ // buffer as argv_chars for use with execv() later.
+ for (int i = 1; i < argc; ++i) {
+ argv_strings.push_back(std::make_unique<std::string>(argv[i]));
+ argv_chars.push_back(argv_strings[i]->c_str());
+ }
+
+ // execv() expects a nullptr to terminate the argument list for argv.
+ argv_chars.push_back(nullptr);
+
+ // We cast away the const-ness of the char buffers, but it should be safe,
+ // since we own these strings.
+ int status = execv(argv_chars[0], const_cast<char **>(argv_chars.data()));
+
+ // We shouldn't get here unless we failed to execute the new binary.
+ if (status != 0) {
+ std::string command;
+ bool first = true;
+ for (auto arg : argv_chars) {
+ if (arg) {
+ if (!first) {
+ command.append(" ");
+ } else {
+ first = false;
+ }
+ command.append(arg);
+ }
+ }
+ fprintf(stderr, "Failed to execute command: %s\n", command.c_str());
+ }
+ return status;
+}