bazelbuild / bazelbuild/rules_cc

FR: capability to embed binary data in CC object file.

Open
#116 3 comments 0 reactions 0 assignees View on GitHub
P3 type: feature request
Dominant language
Starlark
Stars
247
Forks
196
PR merge metrics
No merged PRs in 30d

Description

It is often extremely useful to embed a generated (or static) binary object directly in a C++ library. For example, the ICU library build compiles text files describing character attributes into compressed binary structures that can be evaluated at run time. The canonical technique is to
- generate a data structure that is appropriate for the target platform (in byte alignment and endian-ness)
- wrap it up just enough so that it becomes a linkable object (.o, .obj) file

Typically, the object file defines at least 2 symbols
unit8_t _DATA_OBJECT_NAME_start[]
unit32_t _DATA_OBJECT_NAME_size
Those are declared in a generated .h file and provided by the object module.

# Problem scope

- needs to support at least COFF & ELF object formats
- needs to work for *nix and Windows
- there may be a need to specify what section the data is in
- it may be useful to pack multiple blobs into a single .o file
- generating a large C or Assembler file to compile with the CC toolchain does not work. Large blobs can easily generate text files that hit compiler limits.

There is an interesting overview of issues and techniques here: https://www.devever.net/~hl/incbin

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.