[PATCH] dynamic linker: properly handle STT_NOTYPE symbols

8 views
Skip to first unread message

Waldemar Kozaczuk

unread,
Apr 27, 2021, 9:27:45 PM4/27/21
to osv...@googlegroups.com, Waldemar Kozaczuk
Some ELF files define global variables symbols with STT_NOTYPE
like in this example:

13030: 000000000243b390 0 NOTYPE GLOBAL DEFAULT 13 v8_Default_embedded_blob_size_
13136: 0000000002d09db8 0 NOTYPE GLOBAL DEFAULT 24 v8_Default_embedded_blob_

Currently OSv dynamic linker will resolve such symbols at the relative
offset as specified by st_value and cause page fault. This patch fixes
this logic by correctly adding the base of the ELF to the st_value.

This patch effectively makes it possibly to run latest Node.JS 12 and 14
on OSv.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>
---
core/elf.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/elf.cc b/core/elf.cc
index 94e14b07..7c63bbfc 100644
--- a/core/elf.cc
+++ b/core/elf.cc
@@ -91,7 +91,7 @@ void* symbol_module::relocated_addr() const
}
switch (symbol_type(*symbol)) {
case STT_NOTYPE:
- return reinterpret_cast<void*>(symbol->st_value);
+ return reinterpret_cast<void*>(base + symbol->st_value);
break;
case STT_OBJECT:
case STT_FUNC:
--
2.30.2

Nadav Har'El

unread,
Apr 29, 2021, 3:12:58 AM4/29/21
to Waldemar Kozaczuk, Osv Dev
So, is this exactly the same as STT_OBJECT and STT_FUNC below? I think the reinterpret_cast doesn't change anything.
So can you merge it with the STT_OBJECT / STT_FUNC below?

         break;
     case STT_OBJECT:
     case STT_FUNC:
--
2.30.2

--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/20210428012738.789556-1-jwkozaczuk%40gmail.com.

Waldemar Kozaczuk

unread,
Apr 29, 2021, 12:14:09 PM4/29/21
to osv...@googlegroups.com, Waldemar Kozaczuk
Some ELF files define global variables symbols with STT_NOTYPE
like in this example:

13030: 000000000243b390 0 NOTYPE GLOBAL DEFAULT 13 v8_Default_embedded_blob_size_
13136: 0000000002d09db8 0 NOTYPE GLOBAL DEFAULT 24 v8_Default_embedded_blob_

Currently OSv dynamic linker will resolve such symbols at the relative
offset as specified by st_value and cause page fault. This patch fixes
this logic by correctly adding the base of the ELF to the st_value.

This patch effectively makes it possibly to run latest Node.JS 12 and 14
on OSv.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>
---
core/elf.cc | 2 --
1 file changed, 2 deletions(-)

diff --git a/core/elf.cc b/core/elf.cc
index 94e14b07..3cf1f873 100644
--- a/core/elf.cc
+++ b/core/elf.cc
@@ -91,8 +91,6 @@ void* symbol_module::relocated_addr() const
}
switch (symbol_type(*symbol)) {
case STT_NOTYPE:
- return reinterpret_cast<void*>(symbol->st_value);
- break;
case STT_OBJECT:
case STT_FUNC:
return base + symbol->st_value;
--
2.30.2

Commit Bot

unread,
Apr 30, 2021, 11:19:55 AM4/30/21
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

dynamic linker: properly handle STT_NOTYPE symbols

Some ELF files define global variables symbols with STT_NOTYPE
like in this example:

13030: 000000000243b390 0 NOTYPE GLOBAL DEFAULT 13 v8_Default_embedded_blob_size_
13136: 0000000002d09db8 0 NOTYPE GLOBAL DEFAULT 24 v8_Default_embedded_blob_

Currently OSv dynamic linker will resolve such symbols at the relative
offset as specified by st_value and cause page fault. This patch fixes
this logic by correctly adding the base of the ELF to the st_value.

This patch effectively makes it possibly to run latest Node.JS 12 and 14
on OSv.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/core/elf.cc b/core/elf.cc
Reply all
Reply to author
Forward
0 new messages