3a7ea52f17
Compile the linker with -fvisibility=hidden. This reduces the number of symbols that show up in the .dynsym section of the linker. These symbols are never exported to other applications. In particular, this fixes a problem with setting -DLINKER_DEBUG=1 introduced in 468319ce4f3f7383d788b76c09cda2a405311f36. Because the symbols "debug_verbosity" and "format_log" have not been resolved before the linker links itself, any attempt to call PRINT / INFO / TRACE / WARN / ERROR will result in a segfault. This change allows the static linker to produce a relative reference to these symbols rather than relying on relocation. This also has a nice side effect of making the linker slightly smaller and slightly more optimized. The following symbols no longer in the .dynsym section of the linker after this change: -addr_to_name -call_constructors_recursi -calloc -debugger_init -debugger_signal_handler -debug_verbosity -dladdr -dlclose -dlerror -dl_lock -dlopen -dlsym -dl_unwind_find_exidx -find_containing_library -find_containing_symbol -find_library -format_buffer -free -libdl_info -linker_env_get -linker_env_init -linker_env_secure -linker_env_unset -linker_get_error -__linker_init -lookup -lookup_in_library -malloc -notify_gdb_of_libraries -notify_gdb_of_load -notify_gdb_of_unload -realloc -rtld_db_dlactivity -unload_library -vsnprintf Bug: 5827809 Change-Id: I5e8cd7dcf48c1d6831a970a67f63f24916c5e437
70 lines
1.8 KiB
Makefile
70 lines
1.8 KiB
Makefile
LOCAL_PATH:= $(call my-dir)
|
|
include $(CLEAR_VARS)
|
|
|
|
LOCAL_SRC_FILES:= \
|
|
arch/$(TARGET_ARCH)/begin.S \
|
|
linker.c \
|
|
linker_environ.c \
|
|
linker_format.c \
|
|
rt.c \
|
|
dlfcn.c \
|
|
debugger.c
|
|
|
|
LOCAL_LDFLAGS := -shared
|
|
|
|
LOCAL_CFLAGS += -fno-stack-protector \
|
|
-Wstrict-overflow=5 \
|
|
-fvisibility=hidden
|
|
|
|
# Set LINKER_DEBUG to either 1 or 0
|
|
#
|
|
LOCAL_CFLAGS += -DLINKER_DEBUG=0
|
|
|
|
# we need to access the Bionic private header <bionic_tls.h>
|
|
# in the linker; duplicate the HAVE_ARM_TLS_REGISTER definition
|
|
# from the libc build
|
|
ifeq ($(TARGET_ARCH)-$(ARCH_ARM_HAVE_TLS_REGISTER),arm-true)
|
|
LOCAL_CFLAGS += -DHAVE_ARM_TLS_REGISTER
|
|
endif
|
|
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/private
|
|
|
|
ifeq ($(TARGET_ARCH),arm)
|
|
LOCAL_CFLAGS += -DANDROID_ARM_LINKER
|
|
else
|
|
ifeq ($(TARGET_ARCH),x86)
|
|
LOCAL_CFLAGS += -DANDROID_X86_LINKER
|
|
endif
|
|
endif
|
|
|
|
LOCAL_MODULE:= linker
|
|
|
|
LOCAL_STATIC_LIBRARIES := libc_nomalloc
|
|
|
|
#LOCAL_FORCE_STATIC_EXECUTABLE := true # not necessary when not including BUILD_EXECUTABLE
|
|
|
|
#
|
|
# include $(BUILD_EXECUTABLE)
|
|
#
|
|
# Instead of including $(BUILD_EXECUTABLE), we execute the steps to create an executable by
|
|
# hand, as we want to insert an extra step that is not supported by the build system, and
|
|
# is probably specific the linker only, so there's no need to modify the build system for
|
|
# the purpose.
|
|
|
|
LOCAL_MODULE_CLASS := EXECUTABLES
|
|
LOCAL_MODULE_SUFFIX := $(TARGET_EXECUTABLE_SUFFIX)
|
|
|
|
# we don't want crtbegin.o (because we have begin.o), so unset it
|
|
# just for this module
|
|
LOCAL_NO_CRT := true
|
|
|
|
include $(BUILD_SYSTEM)/dynamic_binary.mk
|
|
|
|
$(linked_module): $(TARGET_CRTBEGIN_STATIC_O) $(all_objects) $(all_libraries) $(TARGET_CRTEND_O)
|
|
$(transform-o-to-static-executable)
|
|
@echo "target PrefixSymbols: $(PRIVATE_MODULE) ($@)"
|
|
$(hide) $(TARGET_OBJCOPY) --prefix-symbols=__dl_ $@
|
|
|
|
#
|
|
# end of BUILD_EXECUTABLE hack
|
|
#
|