Re: [PATCH v2] objtool: Support multiple rodata sections.
From: Josh Poimboeuf
Date: Tue Aug 28 2018 - 12:58:33 EST
On Fri, Aug 03, 2018 at 07:40:40PM +0100, Allan Xavier wrote:
> +static void mark_rodata(struct objtool_file *file)
> +{
> + struct section *sec;
> + bool found = false;
> + static const char *str1 = ".str1.";
> + const int str1len = strlen(str1) + 1;
> +
A comment here would help, explaining that this looks for both .rodata
and .rodata.func_name sections (when using -fdata-sections).
> + for_each_sec(file, sec) {
> + if (strstr(sec->name, ".rodata") == sec->name) {
> + char *str1pos = sec->name + strlen(sec->name) - str1len;
> +
> + /* Skips over .rodata.str1.1 and .rodata.str.1.8 */
> + if (strstr(sec->name, str1) != str1pos) {
> + sec->rodata = true;
> + found = true;
> + }
> + }
> + }
This could be simplified and made more readable with something like:
for_each_sec(file, sec) {
if (!strncmp(sec->name, ".rodata", 7) &&
!strstr(sec->name, ".str1.") {
sec->rodata = true;
found = true;
}
}
--
Josh