How to write an array var into .s file without null-terminator

Dmitry Mikushin
Wed Dec 12 01:28:00 GMT 2012

Dear All,

We are trying to embed a raw vector of chars into .s file using the 
following code:

         tree index_type = build_index_type(size_int(moduleBitcode.size()));
         tree const_char_type = build_qualified_type(
             unsigned_char_type_node, TYPE_QUAL_CONST);
         tree string_type = build_array_type(const_char_type, index_type);
         string_type = build_variant_type_copy(string_type);
         tree string_val = build_string(moduleBitcode.size(),;
         TREE_TYPE(string_val) = string_type;

         tree var = create_tmp_var_raw(string_type, NULL);
         char* tmpname = tmpnam(NULL) + strlen(P_tmpdir);
         if (*tmpname == '/') tmpname++;
         DECL_NAME (var) = get_identifier (tmpname);
         DECL_SECTION_NAME (var) = build_string (11, ".kernelgen");
         TREE_PUBLIC (var) = 1;
         TREE_STATIC (var) = 1;
         TREE_READONLY (var) = 1;
         DECL_INITIAL (var) = string_val;
         varpool_finalize_decl (var);

The problem is that build_string always null-terminates our data array, 
which is unexpected. I tried to clone build_string and modify it in such 
way that it does not add '\0' in the end. But even in this case the 
output object size is moduleBitcode.size() + 1. Why? How to change this 
code to write the data exactly as it is - without null-terminator?

Many thanks,
- Dima.

More information about the Gcc mailing list