Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lld/test/wasm/export-all.s
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,30 @@ foo:
# CHECK-NEXT: - Name: __data_end
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: Index: 2
# CHECK-NEXT: - Name: __stack_low
# CHECK-NEXT: - Name: __rodata_start
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: Index: 3
# CHECK-NEXT: - Name: __stack_high
# CHECK-NEXT: - Name: __rodata_end
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: Index: 4
# CHECK-NEXT: - Name: __global_base
# CHECK-NEXT: - Name: __stack_low
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: Index: 5
# CHECK-NEXT: - Name: __heap_base
# CHECK-NEXT: - Name: __stack_high
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: Index: 6
# CHECK-NEXT: - Name: __heap_end
# CHECK-NEXT: - Name: __global_base
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: Index: 7
# CHECK-NEXT: - Name: __memory_base
# CHECK-NEXT: - Name: __heap_base
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: Index: 8
# CHECK-NEXT: - Name: __table_base
# CHECK-NEXT: - Name: __heap_end
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: Index: 9
# CHECK-NEXT: - Name: __memory_base
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: Index: 10
# CHECK-NEXT: - Name: __table_base
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: Index: 11
22 changes: 14 additions & 8 deletions lld/test/wasm/mutable-global-exports.s
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,36 @@ _start:
# CHECK-ALL-NEXT: - Name: __data_end
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 4
# CHECK-ALL-NEXT: - Name: __stack_low
# CHECK-ALL-NEXT: - Name: __rodata_start
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 5
# CHECK-ALL-NEXT: - Name: __stack_high
# CHECK-ALL-NEXT: - Name: __rodata_end
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 6
# CHECK-ALL-NEXT: - Name: __global_base
# CHECK-ALL-NEXT: - Name: __stack_low
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 7
# CHECK-ALL-NEXT: - Name: __heap_base
# CHECK-ALL-NEXT: - Name: __stack_high
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 8
# CHECK-ALL-NEXT: - Name: __heap_end
# CHECK-ALL-NEXT: - Name: __global_base
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 9
# CHECK-ALL-NEXT: - Name: __memory_base
# CHECK-ALL-NEXT: - Name: __heap_base
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 10
# CHECK-ALL-NEXT: - Name: __table_base
# CHECK-ALL-NEXT: - Name: __heap_end
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 11
# CHECK-ALL-NEXT: - Name: __wasm_first_page_end
# CHECK-ALL-NEXT: - Name: __memory_base
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 12
# CHECK-ALL-NEXT: - Name: __table_base
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 13
# CHECK-ALL-NEXT: - Name: __wasm_first_page_end
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 14
# CHECK-ALL-NEXT: - Type: CODE

# CHECK-ALL: Name: target_features
Expand Down
5 changes: 5 additions & 0 deletions lld/wasm/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ struct Ctx {
// Symbol whose value is the alignment of the TLS block.
GlobalSymbol *tlsAlign;

// __rodata_start/__rodata_end
// Symbols marking the start/end of readonly data
DefinedData *rodataStart;
Copy link
Member

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.

Copy link
Collaborator Author

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 :)

DefinedData *rodataEnd;

// __data_end
Copy link
Member

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?

Copy link
Collaborator Author

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.

// Symbol marking the end of the data and bss.
DefinedData *dataEnd;
Expand Down
5 changes: 4 additions & 1 deletion lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,11 @@ 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.rodataStart = symtab->addOptionalDataSymbol("__rodata_start");
ctx.sym.rodataEnd = symtab->addOptionalDataSymbol("__rodata_end");
}

if (!ctx.isPic) {
ctx.sym.stackLow = symtab->addOptionalDataSymbol("__stack_low");
Expand Down
8 changes: 8 additions & 0 deletions lld/wasm/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,15 @@ void Writer::layoutMemory() {
}
}

if (ctx.sym.rodataStart && seg->name.starts_with(".rodata") &&
!ctx.sym.rodataStart->getVA())
ctx.sym.rodataStart->setVA(memoryPtr);

memoryPtr += seg->size;

// Might get set more than once if segment merging is not enabled.
if (ctx.sym.rodataEnd && seg->name.starts_with(".rodata"))
ctx.sym.rodataEnd->setVA(memoryPtr);
}

// Make space for the memory initialization flag
Expand Down