LLVM Clang 19 Lands Support For C23's #embed

Written by Michael Larabel in LLVM on 12 June 2024 at 06:27 AM EDT. 6 Comments
LLVM
Merged today to LLVM Clang 19 Git is support for the #embed resource inclusion mechanism that is an approved C23 feature. This also makes Clang the first for supporting this pre-processor embed feature.

C23's #embed pre-processor directive makes it easy to include binary data within an executable. With C23 #embed the developer can include the contents of an external binary file at compile-time without relying on any external approaches or resorting to loading the external binary file(s) at run-time.

More details on the C23 #embed feature can be found via the open-std.org whitepaper on the feature. The abstract is as follows:
"Pulling binary data into a program often involves external tools and build system coordination. Many programs need binary data such as images, encoded text, icons and other data in a specific format. Current state of the art for working with such static data in C includes creating files which contain solely string literals, directly invoking the linker to create data blobs to access through carefully named extern variables, or generating large brace-delimited lists of integers to place into arrays. As binary data has grown larger, these approaches have begun to have drawbacks and issues scaling. From parsing 5 megabytes worth of integer literal expressions into AST nodes to arbitrary string literal length limits in compilers, portably putting binary data in a C program has become an arduous task that taxes build infrastructure and compilation memory and time. This proposal provides a flexible preprocessor directive for making this data available to the user in a straightforward manner."

Since last year has been this pull request making all the necessary changes to support the #embed pre-processor for both C and C++. After months of work, that code was merged this morning and now makes LLVM Clang the first of the major open-source compilers supporting this directive.

C23 embed code snippet


The current C23 language status with the Clang compiler can be found via this status page.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week