I have some large string resources located in files that I include in my executable. I include them in the executable using the following. The *.S
allows GCC to invoke as
to produce the object file without any special processing.
;; ca_conf.S
.section .rodata
;; OpenSSL's CA configuration
.global ca_conf
.type ca_conf, @object
.align 8
ca_conf:
ca_conf_start:
.incbin "res/openssl-ca.cnf"
ca_conf_end:
.byte 0
;; The string's size (if needed)
.global ca_conf_size
.type ca_conf_size, @object
.align 4
ca_conf_size:
.int ca_conf_end - ca_conf_start
I add a .byte 0
after including the string to ensure the string is NULL
terminated. That allows me to use ca_conf
as a C const char*
, or {ca_conf,ca_conf_size}
as a C++ string.
Will the assembler or linker rearrange things such that the NULL
terminator could become separated from the string its terminating? Or will the assembler and linker always keep them together?
Because you're in assembler they will be kept together.
One other point, because of the ALIGN 4
ca_conf_size may not be the length you are expecting, it can include upto 3 padding bytes.