This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Fix __start/__stop symbols when combining input segments
ClosedPublic

Authored by sbc100 on Jul 3 2019, 10:38 AM.

Details

Summary

We should be generating one __start/__stop pair per output segment
not per input segment. The test wasn't catching this because it was
only linking a single object file.

Fixes PR41565

Diff Detail

Repository
rL LLVM

Event Timeline

sbc100 created this revision.Jul 3 2019, 10:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2019, 10:38 AM
sbc100 edited the summary of this revision. (Show Details)Jul 3 2019, 10:39 AM
sbc100 added a reviewer: ruiu.
sbc100 added a reviewer: carlokok.
sbc100 edited the summary of this revision. (Show Details)

With this patch, the symbols still seem to end up as 0:

target triple = "wasm32"

@__start_ELRTMLRR = external global i32
@__stop_ELRTMLRR = external global i32
@"ms_t7__1sTypee_GetMethodStart$MD" = constant { [16 x i8], i32* ()* } { [16 x i8] c"\CA\F0\D0\A07\CEi\B1\0F\BEkAqI\ED\BA", i32* ()* @ms_t7__1sTypee_GetMethodStart }, section "ELRTMLRR"
@"ms_t7__1sTyped_GetMethodsEnd$MD" = constant { [16 x i8], i32* ()* } { [16 x i8] c"\0E\BFR\1EJ+G\D7\F8B\96\9B3\E1\8D%", i32* ()* @ms_t7__1sTyped_GetMethodsEnd }, section "ELRTMLRR"
@"both" = constant { { [16 x i8], i32* ()* }*,  { [16 x i8], i32* ()* }* } {{ [16 x i8], i32* ()* }*@"ms_t7__1sTypee_GetMethodStart$MD", { [16 x i8], i32* ()* }*@"ms_t7__1sTyped_GetMethodsEnd$MD"}

define nonnull i32* @ms_t7__1sTypee_GetMethodStart() {
BasicBlock229:
  ret i32* @__start_ELRTMLRR
}

define nonnull i32* @ms_t7__1sTyped_GetMethodsEnd()  {
BasicBlock232:
  ret i32* @__stop_ELRTMLRR
}


define nonnull i32* @test() {
    %abba = load { { [16 x i8], i32* ()* }*,  { [16 x i8], i32* ()* }* }, { { [16 x i8], i32* ()* }*,  { [16 x i8], i32* ()* }* }* @"both"
    ret i32* null
}

llc -filetype=obj lltset.ll
lld -flavor wasm lltset.o -o lltest.wasm -no-entry --export-dynamic --undefined=test

C:\p\llvm\llvm-bin64\Debug\bin>llvm-objdump.exe lltest.wasm --disassemble

lltest.wasm: file format WASM

Disassembly of section CODE:

00000000 CODE:
        # 3 functions in section.
       1: 08 00                         throw           0
       3: 41 80 80 80 80 00             i32.const       0
       9: 0b                            end
       a: 08 00                         throw           0
       c: 41 80 80 80 80 00             i32.const       0
      12: 0b                            end
      13: 04 00                         if      invalid_type
      15: 41 00                         i32.const       0
      17: 0b                            end

Despite it being present at offset 1024:

- Type:            DATA
  Segments:
    - SectionOffset:   7
      InitFlags:       0
      Offset:
        Opcode:          I32_CONST
        Value:           1024
      Content:         CAF0D0A037CE69B10FBE6B417149EDBA010000000000000000000000000000000EBF521E4A2B47D7F842969B33E18D2502000000
    - SectionOffset:   65
      InitFlags:       0
      Offset:
        Opcode:          I32_CONST
        Value:           1080
      Content:         '0004000020040000'

Update: it works if using --no-gc-sections (though obviously that's not a solution)

sbc100 updated this revision to Diff 208265.Jul 6 2019, 2:44 AM

Address feedback

ruiu accepted this revision.Jul 8 2019, 12:54 AM

LGTM

This revision is now accepted and ready to land.Jul 8 2019, 12:54 AM
This revision was automatically updated to reflect the committed changes.