-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[libc] warn when depending on public entrypoints #146163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
michaelrj-google
wants to merge
1
commit into
llvm:main
Choose a base branch
from
michaelrj-google:libcCmakeEntrypointWarning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,32 @@ | ||
set(OBJECT_LIBRARY_TARGET_TYPE "OBJECT_LIBRARY") | ||
set(ENTRYPOINT_OBJ_TARGET_TYPE "ENTRYPOINT_OBJ") | ||
set(ENTRYPOINT_EXT_TARGET_TYPE "ENTRYPOINT_EXT") | ||
|
||
# Rule to check if a list of dependencies contains any entrypoint objects. Returns a list in entrypoint_deps. | ||
function(check_entrypoint_deps fq_deps_list) | ||
set(PUBLIC_DEPS "") | ||
foreach(dep IN LISTS fq_deps_list) | ||
if(NOT TARGET ${dep}) | ||
continue() | ||
endif() | ||
#don't warn for deps that are allowed, such as errno | ||
set(ALLOWED_DEPS | ||
"libc.src.errno.errno" | ||
"libc.src.setjmp.longjmp" | ||
) | ||
LIST(FIND ALLOWED_DEPS ${dep} dep_index) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before the
|
||
if(NOT ${dep_index} EQUAL -1) | ||
continue() | ||
endif() | ||
|
||
get_target_property(target_type ${dep} "TARGET_TYPE") | ||
if(${target_type} STREQUAL ${ENTRYPOINT_OBJ_TARGET_TYPE}) | ||
list(APPEND PUBLIC_DEPS ${dep}) | ||
endif() | ||
endforeach() | ||
set(entrypoint_deps ${PUBLIC_DEPS} PARENT_SCOPE) | ||
endfunction() | ||
|
||
|
||
# Rule which is essentially a wrapper over add_library to compile a set of | ||
# sources to object files. | ||
|
@@ -65,6 +93,18 @@ function(create_object_library fq_target_name) | |
target_include_directories(${fq_target_name} PRIVATE ${LIBC_SOURCE_DIR}) | ||
target_compile_options(${fq_target_name} PRIVATE ${compile_options}) | ||
|
||
#TODO: combine this with the identical check in create_entrypoint_object | ||
#loop through the deps, check if any have the TARGET_TYPE of ENTRYPOINT_OBJ_TARGET_TYPE, and print a warning if they do. | ||
if(LIBC_CMAKE_VERBOSE_LOGGING) | ||
set(entrypoint_deps "") | ||
if(NOT "${fq_deps_list}" STREQUAL "") | ||
check_entrypoint_deps("${fq_deps_list}") | ||
endif() | ||
if(NOT "${entrypoint_deps}" STREQUAL "") | ||
message(WARNING "Object ${fq_target_name} depends on public entrypoint(s) ${entrypoint_deps}.\nDepending on public entrypoints is not allowed in internal code.") | ||
endif() | ||
endif() | ||
|
||
if(SHOW_INTERMEDIATE_OBJECTS) | ||
message(STATUS "Adding object library ${fq_target_name}") | ||
if(${SHOW_INTERMEDIATE_OBJECTS} STREQUAL "DEPS") | ||
|
@@ -110,7 +150,6 @@ function(add_object_library target_name) | |
${ARGN}) | ||
endfunction(add_object_library) | ||
|
||
set(ENTRYPOINT_OBJ_TARGET_TYPE "ENTRYPOINT_OBJ") | ||
|
||
# A rule for entrypoint object targets. | ||
# Usage: | ||
|
@@ -179,7 +218,6 @@ function(create_entrypoint_object fq_target_name) | |
|
||
get_target_property(obj_type ${fq_dep_name} "TARGET_TYPE") | ||
if((NOT obj_type) OR (NOT ${obj_type} STREQUAL ${ENTRYPOINT_OBJ_TARGET_TYPE})) | ||
|
||
message(FATAL_ERROR "The aliasee of an entrypoint alias should be an entrypoint.") | ||
endif() | ||
|
||
|
@@ -230,6 +268,18 @@ function(create_entrypoint_object fq_target_name) | |
_get_common_compile_options(common_compile_options "${ADD_ENTRYPOINT_OBJ_FLAGS}") | ||
list(APPEND common_compile_options ${ADD_ENTRYPOINT_OBJ_COMPILE_OPTIONS}) | ||
get_fq_deps_list(fq_deps_list ${ADD_ENTRYPOINT_OBJ_DEPENDS}) | ||
|
||
#loop through the deps, check if any have the TARGET_TYPE of entrypoint_target_type, and print a warning if they do. | ||
if(LIBC_CMAKE_VERBOSE_LOGGING) | ||
set(entrypoint_deps "") | ||
if(NOT "${fq_deps_list}" STREQUAL "") | ||
check_entrypoint_deps("${fq_deps_list}") | ||
endif() | ||
if(NOT "${entrypoint_deps}" STREQUAL "") | ||
message(WARNING "Entrypoint ${fq_target_name} depends on public entrypoint(s) ${entrypoint_deps}.\nDepending on public entrypoints is not allowed in internal code.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: break the string into multiple lines |
||
endif() | ||
endif() | ||
|
||
set(full_deps_list ${fq_deps_list} libc.src.__support.common) | ||
|
||
if(SHOW_INTERMEDIATE_OBJECTS) | ||
|
@@ -390,8 +440,6 @@ function(add_entrypoint_object target_name) | |
) | ||
endfunction(add_entrypoint_object) | ||
|
||
set(ENTRYPOINT_EXT_TARGET_TYPE "ENTRYPOINT_EXT") | ||
|
||
# A rule for external entrypoint targets. | ||
# Usage: | ||
# add_entrypoint_external( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't have implicit out-parameter
entrypoint_deps
, make it a required first argument of this call.fq_dep_list
can be implicitly collected inARGN
is another option:then all the strings provided in the calls
check_entrypoint_deps(entrypoint_deps ...)
will be collected inARGN
list. So inside the loop, you just needand this function can be called as: