Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-musl-libc: Commit

external/musl/libc


Commit MetaInfo

Revision422c2ce76ddb8003d12864aae0a70aa095acd8cb (tree)
Time2019-11-01 18:28:31
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

Add rules to build musl-libc executables

Change Summary

Incremental Difference

--- a/Android.mk
+++ b/Android.mk
@@ -10,24 +10,28 @@ LOCAL_PATH := $(call my-dir)
1010 include $(CLEAR_VARS)
1111
1212 LOCAL_MODULE := libc-musl
13-LOCAL_MULTILIB := first
14-LOCAL_VENDOR_MODULE := true
15-LOCAL_MODULE_CLASS := SHARED_LIBRARIES
13+LOCAL_CC := $(TARGET_CC)
14+
15+include $(LOCAL_PATH)/common.mk
1616
1717 MUSL_ARCH := $(TARGET_ARCH)
18-MUSL_SRC_DIRS := $(addprefix $(LOCAL_PATH)/,src/* ldso)
18+MUSL_SRC_DIRS := $(addprefix $(LOCAL_PATH)/,src/* crt ldso)
1919 MUSL_BASE_SRCS := $(sort $(wildcard $(addsuffix /*.c,$(MUSL_SRC_DIRS))))
2020 MUSL_ARCH_SRCS := $(sort $(wildcard $(addsuffix /$(MUSL_ARCH)/*.[csS],$(MUSL_SRC_DIRS))))
21-MUSL_REPLACED_SRCS = $(addsuffix .c,$(subst $(MUSL_ARCH)/,,$(basename $(MUSL_ARCH_SRCS))))
21+MUSL_REPLACED_SRCS := $(addsuffix .c,$(subst $(MUSL_ARCH)/,,$(basename $(MUSL_ARCH_SRCS))))
22+MUSL_LDSO_PATHNAME := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/$(LOCAL_MODULE).so
23+MUSL_EMPTY_LIB_NAMES := m rt pthread crypt util xnet resolv dl
2224
23-LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(filter-out $(MUSL_REPLACED_SRCS),$(MUSL_BASE_SRCS)) $(MUSL_ARCH_SRCS))
25+MUSL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(filter-out $(MUSL_REPLACED_SRCS),$(MUSL_BASE_SRCS)) $(MUSL_ARCH_SRCS))
26+MUSL_CRT_SRCS := $(filter crt/%,$(MUSL_SRC_FILES))
27+LOCAL_SRC_FILES := $(filter-out $(MUSL_CRT_SRCS),$(MUSL_SRC_FILES))
2428
2529 LOCAL_C_INCLUDES := $(addprefix $(LOCAL_PATH)/, \
2630 arch/$(MUSL_ARCH) \
2731 arch/generic \
2832 src/include \
2933 src/internal \
30- include) \
34+ include)
3135
3236 LOCAL_CFLAGS := -std=c99 -nostdinc \
3337 -ffreestanding -fexcess-precision=standard -frounding-math \
@@ -35,10 +39,13 @@ LOCAL_CFLAGS := -std=c99 -nostdinc \
3539 -fno-unwind-tables -fno-asynchronous-unwind-tables \
3640 -ffunction-sections -fdata-sections \
3741 -Werror=implicit-function-declaration -Werror=implicit-int \
38- -Werror=pointer-sign -Werror=pointer-arith \
39- -Os -pipe \
42+ -Werror=pointer-sign -Werror=pointer-arith -fno-stack-protector \
43+ -Os -pipe
4044
41-intermediates := $(call local-generated-sources-dir)
45+intermediates := $(call local-intermediates-dir)
46+MUSL_LIBC_SYS := $(intermediates)
47+
48+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_C_INCLUDES)
4249
4350 LOCAL_GENERATED_SOURCES := \
4451 $(intermediates)/bits/alltypes.h \
@@ -55,13 +62,15 @@ $(intermediates)/bits/syscall.h: $(LOCAL_PATH)/arch/$(MUSL_ARCH)/bits/syscall.h.
5562 $(intermediates)/version.h: $(wildcard $(LOCAL_PATH)/VERSION $(LOCAL_PATH)/.git)
5663 echo "#define VERSION \"$$(cd $(<D); sh tools/version.sh)\"" > $@
5764
58-LOCAL_CXX_STL := none
59-LOCAL_SANITIZE := never
60-LOCAL_SYSTEM_SHARED_LIBRARIES :=
61-LOCAL_NO_CRT := true
62-LOCAL_NO_DEFAULT_COMPILER_FLAGS := true
63-LOCAL_NO_LIBCOMPILER_RT := true
64-LOCAL_NO_STANDARD_LIBRARIES := true
65+MUSL_CRT_OBJS := $(addsuffix .o,$(basename $(MUSL_CRT_SRCS:%=$(intermediates)/%)))
66+$(MUSL_CRT_OBJS): PRIVATE_CFLAGS := $(LOCAL_CFLAGS) $(addprefix -I,$(intermediates) $(LOCAL_C_INCLUDES)) -DCRT
67+$(filter $(intermediates)/crt/$(MUSL_ARCH)/%.o,$(MUSL_CRT_OBJS)): $(intermediates)/%.o: $(LOCAL_PATH)/%.s
68+ $(TARGET_CC) $(PRIVATE_CFLAGS) -o $@ -c $< && ln -sf crt/$(MUSL_ARCH)/$(@F) $(@D)/../..
69+$(filter-out $(intermediates)/crt/$(MUSL_ARCH)/%.o,$(MUSL_CRT_OBJS)): $(intermediates)/%.o: $(LOCAL_PATH)/%.c
70+ $(TARGET_CC) $(PRIVATE_CFLAGS) $(if $(filter %/crt1.c,$<),,-fPIC) -o $@ -c $< && ln -sf crt/$(@F) $(@D)/..
71+
72+LOCAL_ADDITIONAL_DEPENDENCIES := $(MUSL_CRT_OBJS)
73+
6574 LOCAL_LDFLAGS := \
6675 -Wl,--sort-common \
6776 -Wl,--gc-sections \
@@ -69,6 +78,37 @@ LOCAL_LDFLAGS := \
6978 -Wl,--no-undefined \
7079 -Wl,--exclude-libs=ALL \
7180 -Wl,--dynamic-list=$(LOCAL_PATH)/dynamic.list \
72- -Wl,-e,_dlstart -v
81+ -Wl,-e,_dlstart
82+
83+LOCAL_POST_INSTALL_CMD := ln -sf $(LOCAL_MODULE).so $(MUSL_LIBC_SYS)/libc.so
7384
7485 include $(BUILD_SHARED_LIBRARY)
86+
87+include $(CLEAR_VARS)
88+
89+LOCAL_MODULE := musl-gcc
90+LOCAL_MODULE_CLASS := EXECUTABLES
91+LOCAL_IS_HOST_MODULE := true
92+
93+intermediates := $(call local-generated-sources-dir)
94+MUSL_GCC_SPECS := $(intermediates)/$(LOCAL_MODULE).specs
95+LOCAL_PREBUILT_MODULE_FILE := $(basename $(MUSL_GCC_SPECS))
96+LOCAL_GENERATED_SOURCES := $(LOCAL_PREBUILT_MODULE_FILE)
97+
98+$(MUSL_GCC_SPECS): $(LOCAL_PATH)/tools/musl-gcc.specs.sh
99+ sh $< "$(MUSL_LIBC_SYS)" "$(MUSL_LIBC_SYS)" "$(subst $(PRODUCT_OUT),,$(MUSL_LDSO_PATHNAME))" > $@
100+
101+$(LOCAL_PREBUILT_MODULE_FILE): $(MUSL_GCC_SPECS)
102+ echo -e "#!/bin/sh\ncd \$$(dirname \$$0)/../../../..\nexec $(TARGET_CC) \$$(cat $(MUSL_LIBC_SYS)/export_includes) -specs $(MUSL_GCC_SPECS) \"\$$@\"\n" > $@
103+
104+MUSL_EMPTY_LIBS := $(MUSL_EMPTY_LIB_NAMES:%=$(MUSL_LIBC_SYS)/lib%.a)
105+$(MUSL_EMPTY_LIBS):
106+ $(hide) rm -f $@; $(LLVM_PREBUILTS_PATH)/llvm-ar rc $@
107+
108+LOCAL_ADDITIONAL_DEPENDENCIES := $(MUSL_EMPTY_LIBS)
109+
110+include $(BUILD_PREBUILT)
111+
112+MUSL_GCC := $(LOCAL_INSTALLED_MODULE)
113+
114+include $(call all-makefiles-under,$(LOCAL_PATH))
--- /dev/null
+++ b/binary.mk
@@ -0,0 +1,32 @@
1+#
2+# Copyright (C) 2019 The Android-x86 Open Source Project
3+#
4+# Licensed under the standard MIT license.
5+# See the COPYRIGHT in the same directory.
6+#
7+
8+LOCAL_CC := $(MUSL_GCC)
9+LOCAL_SHARED_LIBRARIES += libc-musl
10+LOCAL_VENDOR_MODULE := true
11+
12+intermediates := $(call local-intermediates-dir)
13+
14+LOCAL_PREBUILT_MODULE_FILE := $(intermediates)/$(LOCAL_MODULE)-musl
15+LOCAL_GENERATED_SOURCES := $(LOCAL_PREBUILT_MODULE_FILE)
16+
17+c_normal_sources := $(filter-out ../%,$(filter %.c,$(LOCAL_SRC_FILES)))
18+c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
19+$(c_normal_objects): PRIVATE_CC := $(MUSL_GCC)
20+$(c_normal_objects): PRIVATE_CFLAGS := $(LOCAL_CFLAGS)
21+$(c_normal_objects): $(intermediates)/%.o: $(LOCAL_PATH)/%.c | $(MUSL_GCC)
22+ $(transform-c-to-o)
23+
24+LOCAL_CPP_EXTENSION := $(if $(LOCAL_CPP_EXTENSION),$(LOCAL_CPP_EXTENSION),.cpp)
25+cpp_normal_sources := $(filter-out ../%,$(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES)))
26+cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
27+$(cpp_normal_objects): PRIVATE_CXX := $(MUSL_GCC)
28+$(cpp_normal_objects): PRIVATE_CPPFLAGS := $(LOCAL_CPPFLAGS)
29+$(cpp_normal_objects): $(intermediates)/%.o: $(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) | $(MUSL_GCC)
30+ $(transform-cpp-to-o)
31+
32+all_objects := $(c_normal_objects) $(cpp_normal_objects)
--- /dev/null
+++ b/common.mk
@@ -0,0 +1,14 @@
1+LOCAL_CXX ?= $(HOST_OUT_EXECUTABLES)/musl-g++
2+LOCAL_CLANG := none
3+LOCAL_MULTILIB := first
4+LOCAL_VENDOR_MODULE := true
5+LOCAL_CXX_STL := none
6+LOCAL_SANITIZE := never
7+LOCAL_SYSTEM_SHARED_LIBRARIES :=
8+LOCAL_NO_CRT := true
9+LOCAL_NO_DEFAULT_COMPILER_FLAGS := true
10+LOCAL_NO_LIBCOMPILER_RT := true
11+LOCAL_NO_STANDARD_LIBRARIES := true
12+LOCAL_LDFLAGS += -v
13+
14+$(if $(LOCAL_MODULE_CLASS),,$(eval LOCAL_MODULE_CLASS := SHARED_LIBRARIES))
--- /dev/null
+++ b/executable.mk
@@ -0,0 +1,14 @@
1+#
2+# Copyright (C) 2019 The Android-x86 Open Source Project
3+#
4+# Licensed under the standard MIT license.
5+# See the COPYRIGHT in the same directory.
6+#
7+
8+LOCAL_MODULE_CLASS := EXECUTABLES
9+include $(call my-dir)/binary.mk
10+
11+$(LOCAL_PREBUILT_MODULE_FILE): $(all_objects)
12+ $(hide) $(MUSL_GCC) $^ -o $@ -Wl,-rpath=$(subst $(PRODUCT_OUT),,$(TARGET_OUT_VENDOR_SHARED_LIBRARIES))
13+
14+include $(BUILD_PREBUILT)
--- /dev/null
+++ b/test/Android.mk
@@ -0,0 +1,10 @@
1+LOCAL_PATH := $(call my-dir)
2+
3+include $(CLEAR_VARS)
4+
5+LOCAL_MODULE := hello
6+
7+LOCAL_SRC_FILES := hello.cpp main.c
8+
9+#include $(BUILD_MUSL_EXECUTABLE)
10+include $(LOCAL_PATH)/../executable.mk
--- /dev/null
+++ b/test/hello.cpp
@@ -0,0 +1,12 @@
1+#include <stdio.h>
2+
3+class Hello {
4+public:
5+ Hello(const char *s) { printf(s); }
6+};
7+
8+extern "C" void hello()
9+{
10+ Hello("Hello C world!\n");
11+ Hello("Hello C++ world!!\n");
12+}
--- /dev/null
+++ b/test/main.c
@@ -0,0 +1,7 @@
1+void hello();
2+
3+main()
4+{
5+ hello();
6+ return 0;
7+}
Show on old repository browser