pkarashchenko commented on code in PR #9395:
URL: https://github.com/apache/nuttx/pull/9395#discussion_r1206872497
##########
binfmt/elf.c:
##########
@@ -247,16 +247,40 @@ static int elf_loadbinary(FAR struct binary_s *binp,
/* Bind the program to the exported symbol table */
- ret = elf_bind(&loadinfo, exports, nexports);
- if (ret != 0)
+ if (loadinfo.ehdr.e_type == ET_REL)
+ {
+ ret = elf_bind(&loadinfo, exports, nexports);
+ if (ret != 0)
+ {
+ berr("Failed to bind symbols program binary: %d\n", ret);
+ goto errout_with_load;
+ }
+
+ binp->entrypt = (main_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry);
+ }
+ else if (loadinfo.ehdr.e_type == ET_EXEC)
+ {
+ if (nexports > 0)
+ {
+ berr("Cannot bind exported symbols to a "\
+ "fully linked executable\n");
+ ret = -ENOEXEC;
+ goto errout_with_load;
+ }
+
+ /* The entrypoint for a fully linked executable can be found directly */
+
+ binp->entrypt = (main_t)(loadinfo.ehdr.e_entry);
+ }
+
+ else
{
- berr("Failed to bind symbols program binary: %d\n", ret);
- goto errout_with_load;
+ berr("Unexpected elf type %d\n", loadinfo.ehdr.e_type);
+ ret = -ENOEXEC;
Review Comment:
This style change is wrong
##########
binfmt/libelf/libelf_verify.c:
##########
@@ -89,9 +89,10 @@ int elf_verifyheader(FAR const Elf_Ehdr *ehdr)
/* Verify that this is a relocatable file */
- if (ehdr->e_type != ET_REL)
+ if ((ehdr->e_type != ET_REL) && (ehdr->e_type != ET_EXEC))
{
- berr("Not a relocatable file: e_type=%d\n", ehdr->e_type);
+ berr("Not a relocatable or executable file: e_type=%d\n",
+ ehdr->e_type);
Review Comment:
Need to align `ehdr->e_type` with upper`("`
##########
binfmt/elf.c:
##########
@@ -247,16 +247,40 @@ static int elf_loadbinary(FAR struct binary_s *binp,
/* Bind the program to the exported symbol table */
- ret = elf_bind(&loadinfo, exports, nexports);
- if (ret != 0)
+ if (loadinfo.ehdr.e_type == ET_REL)
+ {
+ ret = elf_bind(&loadinfo, exports, nexports);
+ if (ret != 0)
+ {
+ berr("Failed to bind symbols program binary: %d\n", ret);
+ goto errout_with_load;
+ }
+
+ binp->entrypt = (main_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry);
+ }
+ else if (loadinfo.ehdr.e_type == ET_EXEC)
+ {
+ if (nexports > 0)
+ {
+ berr("Cannot bind exported symbols to a "\
+ "fully linked executable\n");
Review Comment:
```
berr("Cannot bind exported symbols to a "
"fully linked executable\n");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]