summaryrefslogtreecommitdiffstats
path: root/libc/cmake/modules
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2019-10-15 13:25:36 -0700
committerSiva Chandra Reddy <sivachandra@google.com>2019-11-01 11:06:12 -0700
commit9364107cf348c7d4a2d05b8906bda6ba384ce6f6 (patch)
tree6e9b56d55d882f360a19eb927be5af4e1998640e /libc/cmake/modules
parent9b0dfdf5e1939b4129df75cc8e8d57fcf451b786 (diff)
downloadbcm5719-llvm-9364107cf348c7d4a2d05b8906bda6ba384ce6f6.tar.gz
bcm5719-llvm-9364107cf348c7d4a2d05b8906bda6ba384ce6f6.zip
Illustrate a redirector using the example of round function from math.h.
Setup demonstrated in this patch is only for ELF-ish platforms. Also note: 1. Use of redirectors is a temporary scheme. They will be removed once LLVM-libc has implementations for the redirected functions. 2. Redirectors are optional. One can choose to not include them in the LLVM-libc build for their platform. 3. Even with redirectors used, we want to link to the system libc dynamically. Reviewers: dlj, hfinkel, jakehehrlich, phosek, stanshebs, theraven, alexshap Subscribers: mgorny, libc-commits Tags: #libc-project Differential Revision: https://reviews.llvm.org/D69020
Diffstat (limited to 'libc/cmake/modules')
-rw-r--r--libc/cmake/modules/LLVMLibCRules.cmake76
1 files changed, 72 insertions, 4 deletions
diff --git a/libc/cmake/modules/LLVMLibCRules.cmake b/libc/cmake/modules/LLVMLibCRules.cmake
index 026cd38a3ef..f35afdc2db1 100644
--- a/libc/cmake/modules/LLVMLibCRules.cmake
+++ b/libc/cmake/modules/LLVMLibCRules.cmake
@@ -100,6 +100,7 @@ set(ENTRYPOINT_OBJ_TARGET_TYPE "ENTRYPOINT_OBJ")
# Usage:
# add_entrypoint_object(
# <target_name>
+# [REDIRECTED] # Specified if the entrypoint is redirected.
# SRCS <list of .cpp files>
# HDRS <list of .h files>
# DEPENDS <list of dependencies>
@@ -107,7 +108,7 @@ set(ENTRYPOINT_OBJ_TARGET_TYPE "ENTRYPOINT_OBJ")
function(add_entrypoint_object target_name)
cmake_parse_arguments(
"ADD_ENTRYPOINT_OBJ"
- "" # No optional arguments
+ "REDIRECTED" # Optional argument
"" # No single value arguments
"SRCS;HDRS;DEPENDS" # Multi value arguments
${ARGN}
@@ -131,7 +132,7 @@ function(add_entrypoint_object target_name)
${target_name}_objects
BEFORE
PRIVATE
- -fpie -std=${LLVM_CXX_STD_default}
+ -fpie ${LLVM_CXX_STD_default}
)
target_include_directories(
${target_name}_objects
@@ -158,10 +159,16 @@ function(add_entrypoint_object target_name)
COMMAND ${CMAKE_LINKER} -r $<TARGET_OBJECTS:${target_name}_objects> -o ${object_file_raw}
)
+ set(alias_attributes "0,function,global")
+ if(ADD_ENTRYPOINT_OBJ_REDIRECTED)
+ set(alias_attributes "${alias_attributes},hidden")
+ endif()
+
add_custom_command(
OUTPUT ${object_file}
- DEPENDS ${object_file_raw}
- COMMAND ${CMAKE_OBJCOPY} --add-symbol "${target_name}=.llvm.libc.entrypoint.${target_name}:0,function,weak,global" ${object_file_raw} ${object_file}
+ # We llvm-objcopy here as GNU-binutils objcopy does not support the 'hidden' flag.
+ DEPENDS ${object_file_raw} ${llvm-objcopy}
+ COMMAND $<TARGET_FILE:llvm-objcopy> --add-symbol "${target_name}=.llvm.libc.entrypoint.${target_name}:${alias_attributes}" ${object_file_raw} ${object_file}
)
add_custom_target(
@@ -219,6 +226,67 @@ function(add_entrypoint_library target_name)
)
endfunction(add_entrypoint_library)
+# Rule build a redirector object file.
+function(add_redirector_object target_name)
+ cmake_parse_arguments(
+ "REDIRECTOR_OBJECT"
+ "" # No optional arguments
+ "SRC" # The cpp file in which the redirector is defined.
+ "" # No multivalue arguments
+ ${ARGN}
+ )
+ if(NOT REDIRECTOR_OBJECT_SRC)
+ message(FATAL_ERROR "'add_redirector_object' rule requires SRC option listing one source file.")
+ endif()
+
+ add_library(
+ ${target_name}
+ OBJECT
+ ${REDIRECTOR_OBJECT_SRC}
+ )
+ target_compile_options(
+ ${target_name}
+ BEFORE PRIVATE -fPIC
+ )
+endfunction(add_redirector_object)
+
+# Rule to build a shared library of redirector objects
+function(add_redirector_library target_name)
+ cmake_parse_arguments(
+ "REDIRECTOR_LIBRARY"
+ ""
+ ""
+ "DEPENDS"
+ ${ARGN}
+ )
+
+ set(obj_files "")
+ foreach(dep IN LISTS REDIRECTOR_LIBRARY_DEPENDS)
+ # TODO: Ensure that each dep is actually a add_redirector_object target.
+ list(APPEND obj_files $<TARGET_OBJECTS:${dep}>)
+ endforeach(dep)
+
+ # TODO: Call the linker explicitly instead of calling the compiler driver to
+ # prevent DT_NEEDED on C++ runtime.
+ add_library(
+ ${target_name}
+ SHARED
+ ${obj_files}
+ )
+ set_target_properties(${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+
+ target_link_libraries(
+ ${target_name}
+ -nostdlib -lc -lm
+ )
+
+ set_target_properties(
+ ${target_name}
+ PROPERTIES
+ LINKER_LANGUAGE "C"
+ )
+endfunction(add_redirector_library)
+
function(add_libc_unittest target_name)
if(NOT LLVM_INCLUDE_TESTS)
return()
OpenPOWER on IntegriCloud