Make TCC write ".imp.@." section at the end of the file.

Now it's possible to write import table at the end of file without need to put linking of autoimporting libraries at the very end of command line.

git-svn-id: svn://kolibrios.org@8604 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Magomed Kostoev (mkostoevr) 2021-02-23 16:37:49 +00:00
parent ccc434de43
commit 521bee47b1

View File

@ -41,6 +41,7 @@ typedef struct {
meos_section_info* code_sections;
meos_section_info* data_sections;
meos_section_info* bss_sections;
meos_section_info* imp_sections; // Pointers to imported libraries and functions
} me_info;
int tcc_output_dbgme(const char *filename, me_info* me);
@ -64,6 +65,11 @@ meos_section_info* findsection(me_info* me,int num)
if (si->sec_num==num)
return si;
}
for (si=me->imp_sections;si;si=si->next)
{
if (si->sec_num==num)
return si;
}
return (meos_section_info*)0;
}
@ -162,6 +168,16 @@ void assign_addresses(me_info* me)
me->bss_sections=si;
continue;
}
if (strcmp(".imp.@.",s->name)==0)
{
si=tcc_malloc(sizeof(meos_section_info));
si->data=s->data;
si->data_size=s->data_offset;
si->next=me->imp_sections;
si->sec_num=i;
me->imp_sections=si;
continue;
}
}
int addr;
addr=sizeof(IMAGE_MEOS_FILE_HEADER);
@ -175,6 +191,11 @@ void assign_addresses(me_info* me)
si->sh_addr=addr;
addr+=si->data_size;
}
for (si=me->imp_sections;si;si=si->next)
{
si->sh_addr=addr;
addr+=si->data_size;
}
me->header.image_size=addr;
for (si=me->bss_sections;si;si=si->next)
{
@ -269,6 +290,13 @@ int tcc_output_me(TCCState* s1,const char *filename)
fwrite(si->data,1,si->data_size,f);
for (si=me.data_sections;si;si=si->next)
fwrite(si->data,1,si->data_size,f);
// IMPORTANT: Write ".imp.@." sections at the very end!
// BSS sections don't count, they should not be in the file at all
// Cause MENUET header filled assuming that file size does not include BSS
// We just emit it for smaller entrophia, sometimes
// it makes the kex file being packed better
for (si=me.imp_sections;si;si=si->next)
fwrite(si->data,1,si->data_size,f);
if (!s1->nobss)
{
for (si=me.bss_sections;si;si=si->next)