Skip to content

[x86] why llvm keep rodata.const section #133684

Open
@LukeSTM

Description

@LukeSTM

https://godbolt.org/z/r8ha9o9nf

compile option: -O2 -ffunction-sections -fdata-sections -mno-sse

#include <stdio.h>
#include <string.h>                                                                                                                                             
 
struct ss_t {
	int s_id;
	char msg[];
};

struct ss_t *mst_1;

void do_some_test(void)
{
	struct ss_t *mst_2;
	char buf[100];
	int fill_num=4;
	char tmp_str[40]="test stringssssssssss!";
	memcpy(buf,&fill_num,sizeof(int));
	memcpy(buf+sizeof(int), tmp_str, strlen(tmp_str) + 1); 
	mst_1=(struct ss_t *)buf;
 
	if (mst_1->s_id==4)
		printf("mst_1->s_id=%d,mst_1->msg=%s\n",mst_1->s_id,mst_1->msg);
}

Image

sorry, but i want know, why clang keep .rodata..L__const.do_some_test.tmp_str in sections. Constant could be expanded into movabsq instructions, and what would use .rodata..L__const.do_some_test.tmp_str? Dose it should be removed ?

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend:X86missed-optimizationquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions