![]() |
wtools 4.0.0-pre7
ESO waf tools
|
objcopy.First load tool, nominally in the top-level wscript:
Then the following taskgen attributes with expected type and default value (indicated with (<type>) and [<default>]) controls the feature:
embed_target (str): Used in generated symbol names and intermediate files.embed_source (stringlist/nodelist): Files to embed.embed_dest (str) [""] : Destination path used.embed_relative_trick (bool) [False]: Whether to record paths as seen from embed_relative_base.embed_relative_base (str/node) [bld.path]: The embed root which determines the recorded relative path to each embed_source. Default is to use the taskgen path. note: If source file is in the build directory the relative path will be recorded as relative to the corresponding path in build dir.embed_section (str) [".rodata,alloc,load,readonly,data,contents"]: Section and flags as expected by objcopy --rename-section to place embedded files. Default is the large read only data section ".lrodata".embed_gnustack (bool) [True]: When true a .note.GNU-stack section will be added to generated objects, which prevents ld from assuming that stack must be made executable.To facilitate use both in simple flat lookup or as a sort of embedded filesystem the paths of embedded files can:
Be flattened if embed_relative_trick=False.
With e.g. embed_dest="/root" and embed_source="src/file.txt" this results in the path /root/file.txt
Record with relative component if embed_relative_trick=True.
With e.g. embed_dest="/root" and embed_source="src/file.txt" this results in the path /root/src/file.txt. The relative base can be configured with embed_relative_base.
Note: In both cases the paths are normalized so e.g. /root/../file.txt yields /file.txt
This feature will produce the following:
{embed_targe}_index and {embed_target}_data containing an index used to enumerate embedded files and the merged files to be embedded together with file path information.Two ELF object files {embed_target}_data.o and {embed_target}_index.o containing the generated data as well as symbols used to access the data. The object files are added to the waf taskgen attribute compile_tasks which means the object files will be linked in automatically when used in e.g. applications or libraries.
The (global) linker symbols are:
embed_{embed_target}_index_first and embed_{embed_target}_index_last (in `{embed_target}_index.o) which points to beginning and one-past end of index entries. See below for how to read the index.embed_{embed_target}_data (in {embed_target}_data.o) which points to the embedded data. The index is used to access individual files.The index contains offets and sizes of file paths and corresponding file contents which is used to to safely access the correct ranges of the symbol embed_{embed_target}_data
Each file has an entry and each entry is equivalent to the following C-struct on x86-64 (i.e. 4 8-byte unsigned integers):
Index is accessed as an array of IndexEntry in the half-open range [embed_{embed_target}_index_first, embed_{embed_target}_index_last)
Example iterating all entries using embed_target="foo":
C++ example which prints file name and content of the embedded files "src/first.txt" and "src/second.txt" using embed_target="foo":
Example build script:
Example program: