-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[lld][WebAssembly] Add new __rodata_start/__rodata_end symbols #172102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-lld @llvm/pr-subscribers-lld-wasm Author: Sam Clegg (sbc100) ChangesThis is similar to etext/_etext in the ELF linker. Its useful in emscripten to know where the RO data data ends and the data begins (even though the Wasm format itself has no concept of RO data). See emscripten-core/emscripten#25939 (reply in thread) Full diff: https://github.com/llvm/llvm-project/pull/172102.diff 3 Files Affected:
diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index 9d903e0c799db..2c73dabb8c3a0 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -173,6 +173,10 @@ struct Ctx {
// Symbol whose value is the alignment of the TLS block.
GlobalSymbol *tlsAlign;
+ // __rodata_end
+ // Symbol marking the end of readonly data (similar to _etext under ELF)
+ DefinedData *rodataEnd;
+
// __data_end
// Symbol marking the end of the data and bss.
DefinedData *dataEnd;
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 97e50783985a8..293ebe63fc5e0 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -988,8 +988,10 @@ static void createOptionalSymbols() {
ctx.sym.dsoHandle = symtab->addOptionalDataSymbol("__dso_handle");
- if (!ctx.arg.shared)
+ if (!ctx.arg.shared) {
ctx.sym.dataEnd = symtab->addOptionalDataSymbol("__data_end");
+ ctx.sym.rodataEnd = symtab->addOptionalDataSymbol("__rodata_end");
+ }
if (!ctx.isPic) {
ctx.sym.stackLow = symtab->addOptionalDataSymbol("__stack_low");
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 9a5b56fc52e2f..9c8b484033834 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -400,8 +400,10 @@ void Writer::layoutMemory() {
setGlobalPtr(tlsBase, memoryPtr);
}
}
-
memoryPtr += seg->size;
+ // Might get set more than once if segment merging is not enabled.
+ if (ctx.sym.rodataEnd)
+ ctx.sym.rodataEnd->setVA(memoryPtr);
}
// Make space for the memory initialization flag
|
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
9dbf57a to
c5fa5e4
Compare
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
This is similar to etext/_etext in the ELF linker. Its useful in emscripten to know where the RO data data ends and the data begins (even though the Wasm format itself has no concept of RO data). See emscripten-core/emscripten#25939 (reply in thread)
| DefinedData *rodataStart; | ||
| DefinedData *rodataEnd; | ||
|
|
||
| // __data_end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason why __data_start doesn't exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just historical need I believe.
|
|
||
| // __rodata_start/__rodata_end | ||
| // Symbols marking the start/end of readonly data | ||
| DefinedData *rodataStart; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of unfortunate that we have __stack_low, __heap_base, and __rodata_start. But I guess it's too late to fix the inconsistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.. that is kind of sad/absurd I agree :)
This is similar to etext/_etext in the ELF linker. Its useful in emscripten to know where the RO data data ends and the data begins (even though the Wasm format itself has no concept of RO data).
See emscripten-core/emscripten#25939 (reply in thread)