Skip to content

Commit 879dab0

Browse files
xiaoxiang781216pkarashchenko
authored andcommitted
binfmt: Move elf_allocbuffer to elf_sectname and elf_symname
it's better to allocate the buffer just before really use it. Signed-off-by: Xiang Xiao <[email protected]>
1 parent 6a1abbc commit 879dab0

File tree

5 files changed

+22
-33
lines changed

5 files changed

+22
-33
lines changed

binfmt/libelf/libelf_bind.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -572,17 +572,6 @@ int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
572572
return ret;
573573
}
574574

575-
/* Allocate an I/O buffer. This buffer is used by elf_symname() to
576-
* accumulate the variable length symbol name.
577-
*/
578-
579-
ret = elf_allocbuffer(loadinfo);
580-
if (ret < 0)
581-
{
582-
berr("elf_allocbuffer failed: %d\n", ret);
583-
return ret;
584-
}
585-
586575
#ifdef CONFIG_ARCH_ADDRENV
587576
/* If CONFIG_ARCH_ADDRENV=y, then the loaded ELF lies in a virtual address
588577
* space that may not be in place now. elf_addrenv_select() will

binfmt/libelf/libelf_ctors.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,6 @@ int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo)
8282

8383
DEBUGASSERT(loadinfo->ctors == NULL);
8484

85-
/* Allocate an I/O buffer if necessary. This buffer is used by
86-
* elf_sectname() to accumulate the variable length symbol name.
87-
*/
88-
89-
ret = elf_allocbuffer(loadinfo);
90-
if (ret < 0)
91-
{
92-
berr("elf_allocbuffer failed: %d\n", ret);
93-
return -ENOMEM;
94-
}
95-
9685
/* Find the index to the section named ".ctors." NOTE: On old ABI system,
9786
* .ctors is the name of the section containing the list of constructors;
9887
* On newer systems, the similar section is called .init_array. It is

binfmt/libelf/libelf_dtors.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,6 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo)
8383

8484
DEBUGASSERT(loadinfo->dtors == NULL);
8585

86-
/* Allocate an I/O buffer if necessary. This buffer is used by
87-
* elf_sectname() to accumulate the variable length symbol name.
88-
*/
89-
90-
ret = elf_allocbuffer(loadinfo);
91-
if (ret < 0)
92-
{
93-
berr("elf_allocbuffer failed: %d\n", ret);
94-
return -ENOMEM;
95-
}
96-
9786
/* Find the index to the section named ".dtors." NOTE: On old ABI system,
9887
* .dtors is the name of the section containing the list of destructors;
9988
* On newer systems, the similar section is called .fini_array. It is

binfmt/libelf/libelf_sections.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ static inline int elf_sectname(FAR struct elf_loadinfo_s *loadinfo,
8282
return -EINVAL;
8383
}
8484

85+
/* Allocate an I/O buffer if necessary. This buffer is used by
86+
* elf_sectname() to accumulate the variable length symbol name.
87+
*/
88+
89+
ret = elf_allocbuffer(loadinfo);
90+
if (ret < 0)
91+
{
92+
berr("elf_allocbuffer failed: %d\n", ret);
93+
return ret;
94+
}
95+
8596
/* Get the section name string table section header */
8697

8798
shstr = &loadinfo->shdr[shstrndx];

binfmt/libelf/libelf_symbols.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ static int elf_symname(FAR struct elf_loadinfo_s *loadinfo,
8282
return -ESRCH;
8383
}
8484

85+
/* Allocate an I/O buffer. This buffer is used by elf_symname() to
86+
* accumulate the variable length symbol name.
87+
*/
88+
89+
ret = elf_allocbuffer(loadinfo);
90+
if (ret < 0)
91+
{
92+
berr("elf_allocbuffer failed: %d\n", ret);
93+
return ret;
94+
}
95+
8596
offset = loadinfo->shdr[loadinfo->strtabidx].sh_offset + sym->st_name;
8697

8798
/* Loop until we get the entire symbol name into memory */

0 commit comments

Comments
 (0)