Skip to content
Merged
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
38 changes: 38 additions & 0 deletions lld/test/wasm/dylink-non-pie.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.lib.o %p/Inputs/ret32.s
# RUN: wasm-ld -m wasm32 --experimental-pic -shared --no-entry %t.lib.o -o %t.lib.so
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
# RUN: wasm-ld -m wasm32 -Bdynamic %t.o %t.lib.so -o %t.wasm
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, this effectively generates a non-PIC output? And ctx.isPic not set?

I wonder if we can confirm this this test somehow? Perhaps its enough that we successfully use i32.const f_p (which would not work if the output was PIC, right?) instead of i32.const f_p@MBREL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx.isPic is not set as neither of pie or shared is set.

the following is the generated output. it looks reasonable to me.

(module $dylink-non-pie.s.tmp.wasm
  (type (;0;) (func (param f32) (result i32)))
  (type (;1;) (func))
  (import "env" "ret32" (func $ret32 (type 0)))
  (import "GOT.func" "ret32" (global $ret32 (mut i32)))
  (func $__wasm_apply_data_relocs (type 1)
    i32.const 1024
    global.get $ret32
    i32.store)
  (func $_start (type 1)
    i32.const 1024
    drop)
  (table (;0;) 1 1 funcref)
  (memory (;0;) 2)
  (global $__stack_pointer (mut i32) (i32.const 66576))
  (export "memory" (memory 0))
  (export "_start" (func $_start))
  (export "__wasm_apply_data_relocs" (func $__wasm_apply_data_relocs))
  (data $.data (i32.const 1024) "\00\00\00\00"))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can confirm this this test somehow? Perhaps its enough that we successfully use i32.const f_p (which would not work if the output was PIC, right?) instead of i32.const f_p@MBREL

maybe we can confirm it doesn't have __memory_base/__table_base imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

# RUN: obj2yaml %t.wasm | FileCheck %s
# RUN: llvm-objdump -d --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DIS

.functype ret32 (f32) -> (i32)
.globl _start
_start:
.functype _start () -> ()
i32.const f_p
drop
end_function

.section .data.f_p,"",@
f_p:
.int32 ret32
.size f_p, 4

# CHECK: Sections:
# CHECK-NEXT: - Type: CUSTOM
# CHECK-NEXT: Name: dylink.0

# non-pie executable doesn't import __memory_base
# CHECK: - Type: IMPORT
# CHECK-NOT: Field: __memory_base

# CHECK: - Type: EXPORT
# CHECK: - Name: __wasm_apply_data_relocs
# CHECK-NEXT: Kind: FUNCTION
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be checking for some more things here?

Perhaps we can check that GOT.ret32 is imported? Perhaps we can decompile __wasm_apply_data_relocs and verify that is using GOT.ret32 as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know any existing tests doing similar things which i can use as an example?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are a few tests that disassembly stuff. Looks for DIS-NEXT in lld/test/wasm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. i will take a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


# DIS: <__wasm_apply_data_relocs>:
# DIS-EMPTY:
# DIS-NEXT: i32.const 1024
# DIS-NEXT: global.get 0
# DIS-NEXT: i32.store 0
# DIS-NEXT: end
2 changes: 1 addition & 1 deletion lld/wasm/Relocations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void scanRelocations(InputChunk *chunk) {
break;
}

if (ctx.isPic ||
if (ctx.isPic || sym->isShared() ||
(sym->isUndefined() &&
config->unresolvedSymbols == UnresolvedPolicy::ImportDynamic)) {
switch (reloc.Type) {
Expand Down
Loading