Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 018769c9e26017cfc29741ccb9ff252f5451c4e2
      
https://github.com/WebKit/WebKit/commit/018769c9e26017cfc29741ccb9ff252f5451c4e2
  Author: Vassili Bykov <[email protected]>
  Date:   2026-01-16 (Fri, 16 Jan 2026)

  Changed paths:
    M Source/JavaScriptCore/offlineasm/asm.rb
    M Source/JavaScriptCore/offlineasm/backends.rb
    M Source/WTF/wtf/InlineASM.h

  Log Message:
  -----------
  offlineasm incorrectly lowers references to global labels
https://bugs.webkit.org/show_bug.cgi?id=305489
rdar://168153042

Reviewed by Yusuke Suzuki.

Feeding this snippet into offlineasm:

global _foo
_foo:
    leap _foo, r0
    ret

produces the following in LLIntAssembly.h:

".loc 5 1541\n"   OFFLINE_ASM_GLOBAL_LABEL(foo)
".loc 5 1543\n"   "movq " LOCAL_LABEL_STRING(foo) "@GOTPCREL(%rip), %rax \n"
".loc 5 1544\n"   "ret \n"

The label is incorrectly referenced using LOCAL_LABEL_STRING, as if it were 
declared using
OFFLINE_ASM_LOCAL_LABEL(). On x86, LOCAL_LABEL_STRING(foo) is rendered as 
"Lfoo" and
compilation fails because "Lfoo" is undefined.

The incorrect reference is emitted because LabelReference.asmLabel (in 
backend.rb) calls
Assembler.labelReference. That appears reasonable and parallels 
LocalLabelReference
calling Assembler.localLabelReference. However, the implementations of 
.labelReference and
.localLabelReference are identical and both produce LOCAL_LABEL_STRING.

Git archaeology shows that originally Assembler.labelReference and 
.localLabelReference
emitted different code. That changed with 
https://bugs.webkit.org/show_bug.cgi?id=131205,
as part of a sweeping change to make opcode labels local. After the change, the 
asmLabel
of a LabelReference is the local string, unless the label is 'extern'. A label 
is extern
if it's referenced but never defined in the assembly source, for example 
'_g_config', so
instructions like 'leap _g_config, ws0' are translated correctly.

This breaks when a label is defined as a global, in which case its 'extern' 
attribute is
set to false, but using LOCAL_LABEL_STRING to reference it is incorrect.

The picture is further obscured by the naming of the methods and macros 
involved.
.labelReference suggests it's different, but is actually identical to
.localLabelReference, and .externLabelReference (by definition never local) 
expands into
the macro LOCAL_REFERENCE (!), which then usually expands into GLOBAL_REFERENCE.

The patch changes LabelReference.asmLabel to respect the 'global' attribute, 
removes
Assembler.labelReference, and renames other methods and macros involved to 
better reflect
what's going on.

Testing: offlineasm has no dedicated test suite, but the upcoming JSPI PR
https://github.com/WebKit/WebKit/pull/54712 has code that relies on the 
corrected
behavior.

Canonical link: https://commits.webkit.org/305717@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to