Skip to content
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

Add loader API map/def files #1664

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions scripts/generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,12 @@ def _mako_info_hpp(path, namespace, tags, version, specs, meta):
specs=specs,
meta=meta)


"""
Entry-point:
generates linker version scripts
"""
def _mako_linker_scripts(path, ext, namespace, tags, version, specs, meta):
name = "adapter"
def _mako_linker_scripts(path, name, ext, namespace, tags, version, specs, meta):
filename = f"{name}.{ext}.in"
fin = os.path.join(templates_dir, f"{filename}.mako")
fout = os.path.join(path, filename)
Expand All @@ -347,6 +347,7 @@ def _mako_linker_scripts(path, ext, namespace, tags, version, specs, meta):
specs=specs,
meta=meta)


"""
Entry-point:
generates lib code
Expand All @@ -370,6 +371,12 @@ def generate_loader(path, section, namespace, tags, version, specs, meta):
loc = 0
loc += _mako_loader_cpp(dstpath, namespace, tags, version, specs, meta)
loc += _mako_print_cpp(dstpath, namespace, tags, version, specs, meta)
loc += _mako_linker_scripts(
dstpath, "loader", "map", namespace, tags, version, specs, meta
)
loc += _mako_linker_scripts(
dstpath, "loader", "def", namespace, tags, version, specs, meta
)
print("Generated %s lines of code.\n"%loc)

"""
Expand All @@ -382,8 +389,12 @@ def generate_adapters(path, section, namespace, tags, version, specs, meta):

loc = 0
loc += _mako_null_adapter_cpp(dstpath, namespace, tags, version, specs, meta)
loc += _mako_linker_scripts(dstpath, "map", namespace, tags, version, specs, meta)
loc += _mako_linker_scripts(dstpath, "def", namespace, tags, version, specs, meta)
loc += _mako_linker_scripts(
dstpath, "adapter", "map", namespace, tags, version, specs, meta
)
loc += _mako_linker_scripts(
dstpath, "adapter", "def", namespace, tags, version, specs, meta
)
print("Generated %s lines of code.\n"%loc)

"""
Expand Down
28 changes: 28 additions & 0 deletions scripts/templates/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

# allow imports from top-level scripts directory
sys.path.append("..")
from .print_helper import get_api_types_funcs
from version import Version


"""
Extracts traits from a spec object
"""
Expand Down Expand Up @@ -656,6 +658,32 @@ def get_adapter_handles(specs):

return objs

"""
Public:
returns a list of all loader API functions' names
"""
def get_loader_functions(specs, meta, n, tags):
func_names = []

# Main API functions
for s in specs:
for obj in s["objects"]:
if obj_traits.is_function(obj):
func_names.append(make_func_name(n, tags, obj))

# Process address tables functions
for tbl in get_pfntables(specs, meta, n, tags):
func_names.append(tbl['export']['name'])

# Print functions
api_types_funcs = get_api_types_funcs(specs, meta, n, tags)
for func in api_types_funcs:
func_names.append(func.c_name)
func_names.append(f"{tags['$x']}PrintFunctionParams")

return sorted(func_names)


"""
Private:
removes 'const' from c++ type
Expand Down
11 changes: 11 additions & 0 deletions scripts/templates/loader.def.in.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%!
import re
from templates import helper as th
%><%
n=namespace
%>\
LIBRARY @TARGET_LIBNAME@
EXPORTS
%for line in th.get_loader_functions(specs, meta, n, tags):
${line}
%endfor
14 changes: 14 additions & 0 deletions scripts/templates/loader.map.in.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%!
import re
from templates import helper as th
%><%
n=namespace
%>\
@TARGET_LIBNAME@ {
global:
%for line in th.get_loader_functions(specs, meta, n, tags):
${line};
%endfor
local:
*;
};
18 changes: 18 additions & 0 deletions source/loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ add_ur_library(ur_loader
${CMAKE_CURRENT_BINARY_DIR}/UrLoaderVersion.rc
)

if (MSVC)
set(TARGET_LIBNAME ur_loader)
string(TOUPPER ${TARGET_LIBNAME} TARGET_LIBNAME)

set(LOADER_VERSION_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/ur_loader.def)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader.def.in ${LOADER_VERSION_SCRIPT} @ONLY)
set_target_properties(ur_loader PROPERTIES
LINK_FLAGS "/DEF:${LOADER_VERSION_SCRIPT}"
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(TARGET_LIBNAME libur_loader_${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
string(TOUPPER ${TARGET_LIBNAME} TARGET_LIBNAME)

set(LOADER_VERSION_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/ur_loader.map)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader.map.in ${LOADER_VERSION_SCRIPT} @ONLY)
target_link_options(ur_loader PRIVATE "-Wl,--version-script=${LOADER_VERSION_SCRIPT}")
endif()

set_target_properties(ur_loader PROPERTIES
LIBRARY_OUTPUT_NAME ur_loader
RUNTIME_OUTPUT_NAME ur_loader
Expand Down
Loading
Loading