Skip to content

Commit a52eac5

Browse files
authored
Merge pull request #1664 from PatKamin/loader-map-files
Add loader API map/def files
2 parents 201ccf1 + de6da74 commit a52eac5

File tree

7 files changed

+1165
-4
lines changed

7 files changed

+1165
-4
lines changed

scripts/generate_code.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ def _mako_info_hpp(path, namespace, tags, version, specs, meta):
328328
specs=specs,
329329
meta=meta)
330330

331+
331332
"""
332333
Entry-point:
333334
generates linker version scripts
334335
"""
335-
def _mako_linker_scripts(path, ext, namespace, tags, version, specs, meta):
336-
name = "adapter"
336+
def _mako_linker_scripts(path, name, ext, namespace, tags, version, specs, meta):
337337
filename = f"{name}.{ext}.in"
338338
fin = os.path.join(templates_dir, f"{filename}.mako")
339339
fout = os.path.join(path, filename)
@@ -347,6 +347,7 @@ def _mako_linker_scripts(path, ext, namespace, tags, version, specs, meta):
347347
specs=specs,
348348
meta=meta)
349349

350+
350351
"""
351352
Entry-point:
352353
generates lib code
@@ -370,6 +371,12 @@ def generate_loader(path, section, namespace, tags, version, specs, meta):
370371
loc = 0
371372
loc += _mako_loader_cpp(dstpath, namespace, tags, version, specs, meta)
372373
loc += _mako_print_cpp(dstpath, namespace, tags, version, specs, meta)
374+
loc += _mako_linker_scripts(
375+
dstpath, "loader", "map", namespace, tags, version, specs, meta
376+
)
377+
loc += _mako_linker_scripts(
378+
dstpath, "loader", "def", namespace, tags, version, specs, meta
379+
)
373380
print("Generated %s lines of code.\n"%loc)
374381

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

383390
loc = 0
384391
loc += _mako_null_adapter_cpp(dstpath, namespace, tags, version, specs, meta)
385-
loc += _mako_linker_scripts(dstpath, "map", namespace, tags, version, specs, meta)
386-
loc += _mako_linker_scripts(dstpath, "def", namespace, tags, version, specs, meta)
392+
loc += _mako_linker_scripts(
393+
dstpath, "adapter", "map", namespace, tags, version, specs, meta
394+
)
395+
loc += _mako_linker_scripts(
396+
dstpath, "adapter", "def", namespace, tags, version, specs, meta
397+
)
387398
print("Generated %s lines of code.\n"%loc)
388399

389400
"""

scripts/templates/helper.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
# allow imports from top-level scripts directory
1414
sys.path.append("..")
15+
from .print_helper import get_api_types_funcs
1516
from version import Version
1617

18+
1719
"""
1820
Extracts traits from a spec object
1921
"""
@@ -656,6 +658,32 @@ def get_adapter_handles(specs):
656658

657659
return objs
658660

661+
"""
662+
Public:
663+
returns a list of all loader API functions' names
664+
"""
665+
def get_loader_functions(specs, meta, n, tags):
666+
func_names = []
667+
668+
# Main API functions
669+
for s in specs:
670+
for obj in s["objects"]:
671+
if obj_traits.is_function(obj):
672+
func_names.append(make_func_name(n, tags, obj))
673+
674+
# Process address tables functions
675+
for tbl in get_pfntables(specs, meta, n, tags):
676+
func_names.append(tbl['export']['name'])
677+
678+
# Print functions
679+
api_types_funcs = get_api_types_funcs(specs, meta, n, tags)
680+
for func in api_types_funcs:
681+
func_names.append(func.c_name)
682+
func_names.append(f"{tags['$x']}PrintFunctionParams")
683+
684+
return sorted(func_names)
685+
686+
659687
"""
660688
Private:
661689
removes 'const' from c++ type

scripts/templates/loader.def.in.mako

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%!
2+
import re
3+
from templates import helper as th
4+
%><%
5+
n=namespace
6+
%>\
7+
LIBRARY @TARGET_LIBNAME@
8+
EXPORTS
9+
%for line in th.get_loader_functions(specs, meta, n, tags):
10+
${line}
11+
%endfor

scripts/templates/loader.map.in.mako

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<%!
2+
import re
3+
from templates import helper as th
4+
%><%
5+
n=namespace
6+
%>\
7+
@TARGET_LIBNAME@ {
8+
global:
9+
%for line in th.get_loader_functions(specs, meta, n, tags):
10+
${line};
11+
%endfor
12+
local:
13+
*;
14+
};

source/loader/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ add_ur_library(ur_loader
1515
${CMAKE_CURRENT_BINARY_DIR}/UrLoaderVersion.rc
1616
)
1717

18+
if (MSVC)
19+
set(TARGET_LIBNAME ur_loader)
20+
string(TOUPPER ${TARGET_LIBNAME} TARGET_LIBNAME)
21+
22+
set(LOADER_VERSION_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/ur_loader.def)
23+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader.def.in ${LOADER_VERSION_SCRIPT} @ONLY)
24+
set_target_properties(ur_loader PROPERTIES
25+
LINK_FLAGS "/DEF:${LOADER_VERSION_SCRIPT}"
26+
)
27+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
28+
set(TARGET_LIBNAME libur_loader_${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
29+
string(TOUPPER ${TARGET_LIBNAME} TARGET_LIBNAME)
30+
31+
set(LOADER_VERSION_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/ur_loader.map)
32+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader.map.in ${LOADER_VERSION_SCRIPT} @ONLY)
33+
target_link_options(ur_loader PRIVATE "-Wl,--version-script=${LOADER_VERSION_SCRIPT}")
34+
endif()
35+
1836
set_target_properties(ur_loader PROPERTIES
1937
LIBRARY_OUTPUT_NAME ur_loader
2038
RUNTIME_OUTPUT_NAME ur_loader

0 commit comments

Comments
 (0)