Giter Site home page Giter Site logo

Comments (3)

mathieuchopstm avatar mathieuchopstm commented on September 26, 2024 2

Taking the Linux kernel's linker as a reference point - relevant parts being:

The main difference with Zephyr, as far as I can tell - and ignoring unrelated details - seems to be that Linux completely ignores the ELF_ST_TYPE of symbols; on the other hand, Zephyr only relocates symbols if they have specific values for it, as seen here:

zephyr/subsys/llext/llext.c

Lines 840 to 852 in 8c8e2f6

} else if (ELF_ST_TYPE(sym.st_info) == STT_SECTION ||
ELF_ST_TYPE(sym.st_info) == STT_FUNC ||
ELF_ST_TYPE(sym.st_info) == STT_OBJECT) {
/* Link address is relative to the start of the section */
link_addr = (uintptr_t)ext->mem[ldr->sect_map[sym.st_shndx]]
+ sym.st_value;
LOG_INF("found section symbol %s addr 0x%lx", name, link_addr);
} else {
/* Nothing to relocate here */
LOG_DBG("not relocated");
continue;
}

@edersondisouza could you try if the following patch fixes the issue on your side?

diff --git a/subsys/llext/llext.c b/subsys/llext/llext.c
index c92f49abd60..16748d941b4 100644
--- a/subsys/llext/llext.c
+++ b/subsys/llext/llext.c
@@ -835,18 +835,15 @@ static int llext_link(struct llext_loader *ldr, struct llext *ext, bool do_local
                                } else {
                                        LOG_INF("found symbol %s at 0x%lx", name, link_addr);
                                }
-                       } else if (ELF_ST_TYPE(sym.st_info) == STT_SECTION ||
-                                  ELF_ST_TYPE(sym.st_info) == STT_FUNC ||
-                                  ELF_ST_TYPE(sym.st_info) == STT_OBJECT) {
+                       } else if (IN_RANGE(sym.st_shndx, 0xFF00, 0xFFFF)) {
+                               //0xFF00 => SHN_LORESERVE, 0xFFFF => SHN_HIRESERVE
+                               LOG_DBG("section index in RESERVED range - not relocating");
+                               continue;
+                       } else {
                                /* Link address is relative to the start of the section */
                                link_addr = (uintptr_t)ext->mem[ldr->sect_map[sym.st_shndx]]
                                        + sym.st_value;
 
                                LOG_INF("found section symbol %s addr 0x%lx", name, link_addr);
-                       } else {
-                               /* Nothing to relocate here */
-                               LOG_DBG("not relocated");
-                               continue;
                        }
 
                        LOG_INF("writing relocation symbol %s type %zd sym %zd at addr 0x%lx "

Edit: re-reading the comment thread in EDK PR, I have seen the issue appeared on qemu_cortex_r5, so I tested on my side. Using ./scripts/twister -p qemu_cortex_r5 --testsuite-root tests/subsys/llext -K (-K required because qemu_cortex_r5 is excluded from LLEXT tests):

  • Without patch, 8 tests are performed: one is skipped, one passes and the other six fail
  • With the patch, one is still skipped but all other tests pass 😄

from zephyr.

edersondisouza avatar edersondisouza commented on September 26, 2024

@mathieuchopstm I've tested it here with the sample and can confirm that your patch does work!!! Will you submit a PR, please?

from zephyr.

mathieuchopstm avatar mathieuchopstm commented on September 26, 2024

@edersondisouza PR with fix submitted

from zephyr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.