Add another test for partial register stalls.

# RUN: llvm-mca -mtriple=x86_64-unknown-unknown -mcpu=btver2 -iterations=1 -resource-pressure=false -timeline < %s | FileCheck %s

imul   %rax, %rbx
lzcnt  %ax,  %bx
add    %ecx, %ebx

# CHECK:      Iterations:        1
# CHECK-NEXT: Instructions:      3
# CHECK-NEXT: Total Cycles:      10
# CHECK-NEXT: Dispatch Width:    2
# CHECK-NEXT: IPC:               0.30
# CHECK-NEXT: Block RThroughput: 4.0

# CHECK:      Instruction Info:
# CHECK-NEXT: [1]: #uOps
# CHECK-NEXT: [2]: Latency
# CHECK-NEXT: [3]: RThroughput
# CHECK-NEXT: [4]: MayLoad
# CHECK-NEXT: [5]: MayStore
# CHECK-NEXT: [6]: HasSideEffects

# CHECK:      [1]    [2]    [3]    [4]    [5]    [6]    Instructions:
# CHECK-NEXT:  2      6     4.00                        imulq	%rax, %rbx
# CHECK-NEXT:  1      1     0.50                        lzcntw	%ax, %bx
# CHECK-NEXT:  1      1     0.50                        addl	%ecx, %ebx

# CHECK:      Timeline view:
# CHECK-NEXT: Index     0123456789

# CHECK:      [0,0]     DeeeeeeER.   imulq	%rax, %rbx
# CHECK-NEXT: [0,1]     .DeE----R.   lzcntw	%ax, %bx
# CHECK-NEXT: [0,2]     .D=====eER   addl	%ecx, %ebx

# CHECK:      Average Wait times (based on the timeline view):
# CHECK-NEXT: [0]: Executions
# CHECK-NEXT: [1]: Average time spent waiting in a scheduler's queue
# CHECK-NEXT: [2]: Average time spent waiting in a scheduler's queue while ready
# CHECK-NEXT: [3]: Average time elapsed from WB until retire stage

# CHECK:            [0]    [1]    [2]    [3]
# CHECK-NEXT: 0.     1     1.0    1.0    0.0       imulq	%rax, %rbx
# CHECK-NEXT: 1.     1     1.0    1.0    4.0       lzcntw	%ax, %bx
# CHECK-NEXT: 2.     1     6.0    0.0    0.0       addl	%ecx, %ebx


Add a test for R_386_PC16 range checking.

// RUN: llvm-mc %s -o %t.o -triple i386-pc-linux-code16 -filetype=obj

// RUN: echo ".global foo; foo = 0x8202" > %t1.s
// RUN: llvm-mc %t1.s -o %t1.o -triple i386-pc-linux -filetype=obj
// RUN: echo ".global foo; foo = 0x8203" > %t2.s
// RUN: llvm-mc %t2.s -o %t2.o -triple i386-pc-linux -filetype=obj

// RUN: ld.lld -Ttext 0x200 %t.o %t1.o -o %t1
// RUN: llvm-objdump -d -triple=i386-pc-linux-code16 %t | FileCheck %s

// CHECK:        Disassembly of section .text:
// CHECK-NEXT: _start:
// CHECK-NEXT:      200:       e9 ff 7f        jmp     32767
//                                   0x8202 - 0x203 == 32767

// RUN: not ld.lld -Ttext 0x200 %t.o %t2.o -o %t2 2>&1 | FileCheck --check-prefix=ERR %s

// ERR: {{.*}}:(.text+0x1): relocation R_386_PC16 out of range

        .global _start
_start:
        jmp foo


# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -relocation-model=pic -filetype=obj -o %s.o %s
# RUN: llvm-rtdyld -triple=x86_64-apple-macosx10.9 -verify -check=%s %s.o
# RUN: rm %s.o

        .section	__TEXT,__text,regular,pure_instructions
	.globl	foo
	.align	4, 0x90
foo:
        retq

	.globl	main
	.align	4, 0x90
main:
# Test PC-rel branch.
# rtdyld-check: decode_operand(insn1, 0) = foo - next_pc(insn1)
insn1:
        callq	foo

# Test PC-rel signed.
# rtdyld-check: decode_operand(insn2, 4) = x - next_pc(insn2)
insn2:
	movl	x(%rip), %eax
	movl	$0, %eax
	retq

        .section	__DATA,__data
	.globl	x
	.align	2
x:
        .long   5

.subsections_via_symbols

Fix this test to not write to the source tree, and instead to write to a temporary file. This fixes the test in cases where the source tree is mounted read-only.

# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -relocation-model=pic -filetype=obj -o %t.o %s
# RUN: llvm-rtdyld -triple=x86_64-apple-macosx10.9 -verify -check=%s %t.o
# RUN: rm %t.o

        .section	__TEXT,__text,regular,pure_instructions
	.globl	foo
	.align	4, 0x90
foo:
        retq

	.globl	main
	.align	4, 0x90
main:
# Test PC-rel branch.
# rtdyld-check: decode_operand(insn1, 0) = foo - next_pc(insn1)
insn1:
        callq	foo

# Test PC-rel signed.
# rtdyld-check: decode_operand(insn2, 4) = x - next_pc(insn2)
insn2:
	movl	x(%rip), %eax
	movl	$0, %eax
	retq

        .section	__DATA,__data
	.globl	x
	.align	2
x:
        .long   5

.subsections_via_symbols


// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//
// System calls and other sys stuff for Akaros amd64
//

// set tls base to DI
TEXT runtime·settls(SB),7,$32
	SUBQ	$12, SP
	MOVL	$0, 0(SP)  // vcore 0
	MOVQ	DI, 4(SP)  // the new fs base
	CALL	runtime∕parlib·Set_tls_desc(SB)
	RET

Remove contents of amd64 settls since e never call it

// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//
// System calls and other sys stuff for Akaros amd64
//

// Do nothing for now
TEXT runtime·settls(SB), 7, $0
	RET


# Check that we do not keep STT_FILE symbols in the symbol table

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -shared -o %t.so
# RUN: llvm-readobj -symbols %t.so | FileCheck %s

# REQUIRES: x86

# CHECK-NOT: xxx

.file "xxx"
.file ""

Check test conditions more precisely. NFC

# Check that we do not keep STT_FILE symbols in the symbol table

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -shared -o %t.so
# RUN: llvm-readobj -symbols %t.so | FileCheck %s

# REQUIRES: x86

# CHECK-NOT: Name: xxx

.file "xxx"
.file ""


// REQUIRES: x86

// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t1.o
// RUN: ld.lld %t1.o -M | FileCheck -strict-whitespace %s

.global _start
_start:
 nop

// CHECK:        VMA      LMA     Size Align Out     In      Symbol
// CHECK-NEXT: 11000    11000        1     4 .text
// CHECK-NEXT: 11000    11000        1     4         {{.*}}{{/|\\}}map-file-i686.s.tmp1.o:(.text)
// CHECK-NEXT: 11000    11000        0     1                 _start
// CHECK-NEXT:     0        0        8     1 .comment
// CHECK-NEXT:     0        0        8     1         <internal>:(.comment)
// CHECK-NEXT:     0        0       20     4 .symtab
// CHECK-NEXT:     0        0       20     4         <internal>:(.symtab)
// CHECK-NEXT:     0        0       2a     1 .shstrtab
// CHECK-NEXT:     0        0       2a     1         <internal>:(.shstrtab)
// CHECK-NEXT:     0        0        8     1 .strtab
// CHECK-NEXT:     0        0        8     1         <internal>:(.strtab)

Set -o because current directory may not be writable during a test

// REQUIRES: x86

// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t1.o
// RUN: ld.lld %t1.o -o %t1 -M | FileCheck -strict-whitespace %s

.global _start
_start:
 nop

// CHECK:        VMA      LMA     Size Align Out     In      Symbol
// CHECK-NEXT: 11000    11000        1     4 .text
// CHECK-NEXT: 11000    11000        1     4         {{.*}}{{/|\\}}map-file-i686.s.tmp1.o:(.text)
// CHECK-NEXT: 11000    11000        0     1                 _start
// CHECK-NEXT:     0        0        8     1 .comment
// CHECK-NEXT:     0        0        8     1         <internal>:(.comment)
// CHECK-NEXT:     0        0       20     4 .symtab
// CHECK-NEXT:     0        0       20     4         <internal>:(.symtab)
// CHECK-NEXT:     0        0       2a     1 .shstrtab
// CHECK-NEXT:     0        0       2a     1         <internal>:(.shstrtab)
// CHECK-NEXT:     0        0        8     1 .strtab
// CHECK-NEXT:     0        0        8     1         <internal>:(.strtab)


//===-- HasAVX.s ---------------------------------------*- x86 Assembly -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#if defined (__i386__) || defined (__x86_64__)

.globl _HasAVX

_HasAVX:
#if defined (__x86_64__)
    pushq %rbp
    movq %rsp, %rbp
    pushq %rbx
#else
    pushl %ebp
    movl %esp, %ebp
    pushl %ebx
#endif
    mov $1, %eax
    cpuid                                                                       // clobbers ebx
    and $0x018000000, %ecx
    cmp $0x018000000, %ecx
    jne not_supported
    mov $0, %ecx
.byte 0x0f, 0x01, 0xd0    // xgetbv, for those assemblers that don't know it
    and $0x06, %eax
    cmp $0x06, %eax
    jne not_supported
    mov $1, %eax
    jmp done
not_supported:
    mov $0, %eax
done:
#if defined (__x86_64__)
    popq %rbx
    movq %rbp, %rsp
    popq %rbp
#else
    popl %ebx
    movl %ebp, %esp
    popl %ebp
#endif
    ret                                                                         // return

#endif

Add missing newline at EOF.


.globl _start
.data
msg:    .ascii "ok\n"
.text
_start:
	basr	%r1, 0
base:
	la	%r2, base
	sr	%r1, %r2
	lhi	%r2, 1
	la	%r3, msg(%r1)
	lhi	%r4, 3
	svc	4

	xr	%r2, %r2
	svc	1

Fix string length in 64-bit mode

.globl _start
.data
msg:    .ascii "ok\n"
.text
_start:
	basr	%r1, 0
base:
	la	%r2, base
	sr	%r1, %r2
	lhi	%r2, 1
	la	%r3, msg(%r1)
	lghi	%r4, 3
	svc	4

	xr	%r2, %r2
	svc	1


Add a test case for r156840, a fix to llvm-objdump when disassembling using -macho to disassemble the last symbol to the end of the section.

@ RUN: llvm-mc -triple=thumbv7-apple-ios -filetype=obj -o - < %s | llvm-objdump -d -macho -triple=thumbv7-apple-ios - | FileCheck %s
.thumb
.thumb_func _fib
_fib:
	push	{r7, lr}
	pop	{r7, pc}
.thumb_func _main
_main:
	push	{r7, lr}
        pop	{r7, pc}
	nop
# CHECK: _fib:
# CHECK:        0:	80 b5                                        	push	{r7, lr}
# CHECK:        2:	80 bd                                        	pop	{r7, pc}
# CHECK: _main:
# CHECK:        4:	80 b5                                        	push	{r7, lr}
# CHECK:        6:	80 bd                                        	pop	{r7, pc}
# CHECK:        8:	00 bf                                        	nop
# We are checking that second function is fully disassembled.
# rdar://11426465


# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld %t -o %t2 --gc-sections
# RUN: llvm-readobj -t %t2 | FileCheck %s

# CHECK-NOT: foo

	.section	.text,"ax",@progbits,unique,0
	.globl	foo
foo:
	.cfi_startproc
	.cfi_endproc

	.section	.text,"ax",@progbits,unique,1
	.globl	_start
_start:
	.cfi_startproc
	.cfi_endproc

Add a test showing that we can gc parts of .eh_frame.

# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t

# RUN: ld.lld %t -o %t2 --gc-sections
# RUN: llvm-readobj -t %t2 | FileCheck %s
# RUN: llvm-objdump --dwarf=frames %t2 | FileCheck --check-prefix=EH %s

# RUN: ld.lld %t -o %t3
# RUN: llvm-readobj -t %t3 | FileCheck --check-prefix=NOGC %s
# RUN: llvm-objdump --dwarf=frames %t3 | FileCheck --check-prefix=EHNOGC %s

# CHECK-NOT: foo
# NOGC:      foo

# EH:     FDE cie={{.*}} pc=
# EH-NOT: FDE

# EHNOGC: FDE cie={{.*}} pc=
# EHNOGC: FDE cie={{.*}} pc=

	.section	.text,"ax",@progbits,unique,0
	.globl	foo
foo:
	.cfi_startproc
	.cfi_endproc

	.section	.text,"ax",@progbits,unique,1
	.globl	_start
_start:
	.cfi_startproc
	.cfi_endproc


Add a test documenting how we handle addends on Elf_Rela.

// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: ld.lld %t.o -o %t.so -shared
// RUN: llvm-readobj -r -s -l -section-data %t.so | FileCheck %s

// CHECK:      Name: .got
// CHECK-NEXT: Type: SHT_PROGBITS
// CHECK-NEXT: Flags [
// CHECK-NEXT:   SHF_ALLOC
// CHECK-NEXT:   SHF_WRITE
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x[[GOT:.*]]
// CHECK-NEXT: Offset:
// CHECK-NEXT: Size:
// CHECK-NEXT: Link:
// CHECK-NEXT: Info:
// CHECK-NEXT: AddressAlignment:
// CHECK-NEXT: EntrySize:
// CHECK-NEXT: SectionData (
// CHECK-NEXT:   0000: 00000000 00000000                |
// CHECK-NEXT: )

// CHECK:      Relocations [
// CHECK-NEXT:   Section ({{.*}}) .rela.dyn {
// CHECK-NEXT:     0x[[GOT]] R_X86_64_RELATIVE - 0x[[ADDEND:.*]]
// CHECK-NEXT:   }
// CHECK-NEXT: ]

// CHECK:      Type: PT_DYNAMIC
// CHECK-NEXT: Offset: 0x[[ADDEND]]
// CHECK-NEXT: VirtualAddress: 0x[[ADDEND]]
// CHECK-NEXT: PhysicalAddress: 0x[[ADDEND]]

cmpq    $0, _DYNAMIC@GOTPCREL(%rip)


// RUN: %clang -### -c -integrated-as %s 2>&1 | FileCheck %s

// REQUIRES: clang-driver

// CHECK: cc1as
// CHECK-NOT: -relax-all

// RUN: %clang -c -integrated-as -Wa,--compress-debug-sections %s 2>&1 | FileCheck --check-prefix=INVALID %s
// INVALID: error: unsupported argument '--compress-debug-sections' to option 'Wa,'

Add not to a command that is expected to fail.

// RUN: %clang -### -c -integrated-as %s 2>&1 | FileCheck %s

// REQUIRES: clang-driver

// CHECK: cc1as
// CHECK-NOT: -relax-all

// RUN: not %clang -c -integrated-as -Wa,--compress-debug-sections %s 2>&1 | FileCheck --check-prefix=INVALID %s
// INVALID: error: unsupported argument '--compress-debug-sections' to option 'Wa,'


; md5 XXXXXXXXXXXXXXXXXXXXXX

.INCLUDE "includes/init.s"
.ROMBANKS zzzzzzzzzz
.BACKGROUND "aaaaaaaaaaaaaaaaaaa"
.INCLUDE "includes/header.s"

;**********
;* config *
;**********

.DEFINE joypad $tttt
.DEFINE joypad_2 $ssss
.DEFINE current_rom_bank $iiii

;*************************
;* relocated joypad read *
;*************************

.BANK $00 SLOT 0
.ORG $0080
.SECTION "relocated read from joypad" SIZE $70 OVERWRITE
    .INCLUDE "includes/relocated_read_from_joypad.s"
    .INCLUDE "includes/zero_ram.s"
.ENDS

;************
;* zero ram *
;************

.DEFINE ZERO_RAM_DONE $0150
.BANK $00 SLOT 0
.ORG $0101
.SECTION "zero ram jump" SIZE 3 OVERWRITE
    jp ZERO_RAM
.ENDS

;***************
;* joypad read *
;***************

.BANK $00 SLOT 0
.ORG $qqqq
.SECTION "joypad read" SIZE 4 OVERWRITE
    call relocated_read_from_joypad
    nop
.ENDS

;*******************
;* save/load state *
;*******************

.BANK $zz SLOT 1
.ORG $xxxx
.SECTION "save/load state" SIZE $yyyy OVERWRITE
    .DB "--- XXXXX Save Patch ---"
    .INCLUDE "includes/save_state_includes.s"
.ENDS

Fix reset ram include in template

; md5 XXXXXXXXXXXXXXXXXXXXXX

.INCLUDE "includes/init.s"
.ROMBANKS zzzzzzzzzz
.BACKGROUND "aaaaaaaaaaaaaaaaaaa"
.INCLUDE "includes/header.s"

;**********
;* config *
;**********

.DEFINE joypad $tttt
.DEFINE joypad_2 $ssss
.DEFINE current_rom_bank $iiii

;*************************
;* relocated joypad read *
;*************************

.BANK $00 SLOT 0
.ORG $0080
.SECTION "relocated read from joypad" SIZE $70 OVERWRITE
    .INCLUDE "includes/relocated_read_from_joypad.s"
    .INCLUDE "includes/reset_ram.s"
.ENDS

;*************
;* reset ram *
;*************

.DEFINE RESET_RAM_DONE $0150
.BANK $00 SLOT 0
.ORG $0101
.SECTION "reset ram jump" SIZE 3 OVERWRITE
    jp RESET_RAM
.ENDS

;***************
;* joypad read *
;***************

.BANK $00 SLOT 0
.ORG $qqqq
.SECTION "joypad read" SIZE 4 OVERWRITE
    call relocated_read_from_joypad
    nop
.ENDS

;*******************
;* save/load state *
;*******************

.BANK $zz SLOT 1
.ORG $xxxx
.SECTION "save/load state" SIZE $yyyy OVERWRITE
    .DB "--- XXXXX Save Patch ---"
    .INCLUDE "includes/save_state_includes.s"
.ENDS


Add an interesting case where we were already producing the correct result.

// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
// RUN: ld.lld2 %t.o -o %t.so -shared
// RUN: llvm-readobj -r -t %t.so | FileCheck  %s

        .quad __start_foo
        .section foo,"a"
// By default the symbol is visible and we need a dynamic reloc.
// CHECK:  R_X86_64_64 __start_foo 0x0

        .hidden __start_bar
        .quad __start_bar
        .section bar,"a"
// Test that we are able to hide the symbol.
// CHECK:      R_X86_64_RELATIVE - 0x[[ADDR:.*]]

// CHECK:      Name: __start_bar
// CHECK-NEXT: Value: 0x[[ADDR]]


%include "functions.s"
%include "memory.s"
%include "forth.s"

kmain:
    mov dx, hw
    push dx
    call print_line

    mov dx, logo1
    push dx
    call print_line
    mov dx, logo2
    push dx
    call print_line
    mov dx, logo3
    push dx
    call print_line
    mov dx, logo4
    push dx
    call print_line
    mov dx, logo5
    push dx
    call print_line
    mov dx, logo6
    push dx
    call print_line
    mov dx, logo7
    push dx
    call print_line

    add sp, 2

    jmp forth_main

hw: db 'Kernel loaded.',0
logo1: db '===========  =',0
logo2: db '=  =====  =  =',0
logo3: db '=  =      =  =',0
logo4: db '=  =====  ====',0
logo5: db '=      =  =  =',0
logo6: db '=  =====  =  =',0
logo7: db '===========  =',0

Update CSH logo to look better

%include "functions.s"
%include "memory.s"
;%include "forth.s"

kmain:
    mov dx, hw
    push dx
    call print_line

    mov dx, logo1
    push dx
    call print_line
    mov dx, logo2
    push dx
    call print_line
    mov dx, logo3
    push dx
    call print_line
    mov dx, logo4
    push dx
    call print_line
    mov dx, logo5
    push dx
    call print_line
    mov dx, logo6
    push dx
    call print_line
    mov dx, logo7
    push dx
    call print_line
    mov dx, logo8
    push dx
    call print_line
    mov dx, logo9
    push dx
    call print_line

    add sp, 2

    ;jmp forth_main
    jmp $

hw: db 'Kernel loaded.',0
logo1: db '=========  =',0
logo2: db '=       =  =',0
logo3: db '= =====    =',0
logo4: db '= =     =  =',0
logo5: db '= ===== ====',0
logo6: db '=     = =  =',0
logo7: db '= =====    =',0
logo8: db '=       =  =',0
logo9: db '=========  =',0


Add stub file for PC64 arithmetic routines.

// Trampolines to math/big assembly implementations.

#include "textflag.h"

// func addVV(z, x, y []Word) (c Word)
TEXT ·addVV(SB),NOSPLIT,$0
	BR	math∕big·addVV(SB)

// func subVV(z, x, y []Word) (c Word)
TEXT ·subVV(SB),NOSPLIT,$0
	BR	math∕big·subVV(SB)

// func addVW(z, x []Word, y Word) (c Word)
TEXT ·addVW(SB),NOSPLIT,$0
	BR	math∕big·addVW(SB)

// func subVW(z, x []Word, y Word) (c Word)
TEXT ·subVW(SB),NOSPLIT,$0
	BR	math∕big·subVW(SB)

// func shlVU(z, x []Word, s uint) (c Word)
TEXT ·shlVU(SB),NOSPLIT,$0
	BR	math∕big·shlVU(SB)

// func shrVU(z, x []Word, s uint) (c Word)
TEXT ·shrVU(SB),NOSPLIT,$0
	BR	math∕big·shrVU(SB)

// func mulAddVWW(z, x []Word, y, r Word) (c Word)
TEXT ·mulAddVWW(SB),NOSPLIT,$0
	BR	math∕big·mulAddVWW(SB)

// func addMulVVW(z, x []Word, y Word) (c Word)
TEXT ·addMulVVW(SB),NOSPLIT,$0
	BR	math∕big·addMulVVW(SB)


# RUN: llvm-mc -triple=mips64-unknown-freebsd %s -filetype=obj -o %t.o
# RUN: not ld.lld %t.o %S/Inputs/corrupt-version-reference.so -o %t.exe 2>&1 | FileCheck %s

# CHECK: error: corrupt input file: version definition index 9 for symbol __cxa_finalize is out of bounds
# CHECK: >>> defined in {{.+}}/corrupt-version-reference.so

.globl __start
__start:
    dla $a0, __cxa_finalize
    nop

Add missing REQUIRES: mips to the test added in r315035

# RUN: llvm-mc -triple=mips64-unknown-freebsd %s -filetype=obj -o %t.o
# RUN: not ld.lld %t.o %S/Inputs/corrupt-version-reference.so -o %t.exe 2>&1 | FileCheck %s
# REQUIRES: mips

# CHECK: error: corrupt input file: version definition index 9 for symbol __cxa_finalize is out of bounds
# CHECK: >>> defined in {{.+}}/corrupt-version-reference.so

.globl __start
__start:
    dla $a0, __cxa_finalize
    nop


Check that the thumb COFF segment flag gets set on thumb windows

@ RUN: llvm-mc -triple thumbv7-windows-itanium -filetype obj -o - %s \
@ RUN:   | llvm-readobj -s - | FileCheck %s

    .syntax unified
    .thumb

    .text

    .global function
    .thumb_func
function:
    bx lr

@ CHECK: Section
@ CHECK-DAG: IMAGE_SCN_CNT_CODE
@ CHECK-DAG: IMAGE_SCN_MEM_16BIT


// Instructions to the linker
	.section .init
	.globl _start

_start:
	ldr r0,=0x20200000

	// Make pin16 an output pin.
	// mov r1,#1
	// lsl r1,#18
	// str r1,[r0,#4]

	// Make pin16 an output pin (without the bit shifts)
	mov r1,#4
	str r1,[r0,#5]  // NOTE: big endian, makes it #5, and not #6

	// Turn off the GPIO pin to turn the LED on
	mov r1,#1
	lsl r1,#16
	str r1,[r0,#40]  // #40 --> 0x28

loop$:
	// Loop forever
	b loop$

Revert change that removes bit shifts.

// Instructions to the linker
	.section .init
	.globl _start

_start:
	ldr r0,=0x20200000

	// Make pin16 an output pin.
	mov r1,#1
	lsl r1,#18
	str r1,[r0,#4]

	// Why does this not work?!@
	// It definitely worked once! :(
	// mov r1,#4
	// str r1,[r0,#5]

	// Turn off the GPIO pin to turn the LED on
	mov r1,#1
	lsl r1,#16
	str r1,[r0,#40]  // #40 --> 0x28

loop$:
	// Loop forever
	b loop$


// RUN: llvm-mc -triple i386-apple-darwin9 %s -filetype=obj -o - | macho-dump --dump-section-data | FileCheck %s

        .file	1 "foo"
	.loc	1 64 0
        nop

// CHECK:         # Section 1
// CHECK-NEXT:   (('section_name', '__debug_line\x00\x00\x00\x00')
// CHECK-NEXT:    ('segment_name', '__DWARF\x00\x00\x00\x00\x00\x00\x00\x00\x00')
// CHECK-NEXT:    ('address', 1)
// CHECK-NEXT:    ('size', 51)
// CHECK-NEXT:    ('offset', 221)
// CHECK-NEXT:    ('alignment', 0)
// CHECK-NEXT:    ('reloc_offset', 272)
// CHECK-NEXT:    ('num_reloc', 1)
// CHECK-NEXT:    ('flags', 0x2000000)
// CHECK-NEXT:    ('reserved1', 0)
// CHECK-NEXT:    ('reserved2', 0)
// CHECK-NEXT:   ),
// CHECK-NEXT:  ('_relocations', [
// CHECK-NEXT:    # Relocation 0
// CHECK-NEXT:    (('word-0', 0x27),
// CHECK-NEXT:     ('word-1', 0x4000001)),
// CHECK-NEXT:  ])
// CHECK-NEXT:  ('_section_data', '2f000000 02001a00 00000101 fb0e0d00 01010101 00000001 00000100 666f6f00 00000000 00050200 00000003 3f010201 000101')


Add a test for the feature introduced in r295240.

// RUN: llvm-mc -filetype=obj -triple=i686-unknown-cloudabi %s -o %t.o
// RUN: ld.lld --export-dynamic %t.o -o %t
// RUN: llvm-readobj -dyn-symbols %t | FileCheck %s
// REQUIRES: x86

// Ensure that a dynamic symbol table is present when --export-dynamic
// is passed in, even when creating statically linked executables.
//
// CHECK:      DynamicSymbols [
// CHECK-NEXT:   Symbol {
// CHECK-NEXT:     Name:
// CHECK-NEXT:     Value: 0x0
// CHECK-NEXT:     Size: 0
// CHECK-NEXT:     Binding: Local
// CHECK-NEXT:     Type: None
// CHECK-NEXT:     Other: 0
// CHECK-NEXT:     Section: Undefined
// CHECK-NEXT:   }
// CHECK-NEXT:   Symbol {
// CHECK-NEXT:     Name: _start
// CHECK-NEXT:     Value: 0x11000
// CHECK-NEXT:     Size: 0
// CHECK-NEXT:     Binding: Global
// CHECK-NEXT:     Type: None
// CHECK-NEXT:     Other: 0
// CHECK-NEXT:     Section: .text
// CHECK-NEXT:   }
// CHECK-NEXT: ]

.global _start
_start:
  ret


# Assembly code defines set of externally visible labels.

# Shared library generation:
#   llvm-mc -triple=mipsel -filetype=obj -relocation-model=pic \
#           -o=%t1 %p/Inputs/ext.s
#   lld -flavor gnu -target mipsel -shared -o %t2 %t1

# Executable generation:
#   llvm-mc -triple=mipsel -filetype=obj -o=%t1 %p/Inputs/ext.s
#   lld -flavor gnu -target mipsel -e ext1 -o %t2 %t1

    .global ext1
    .type   ext1,@function
    .ent    ext1
ext1:
    nop
    .end    ext1

    .global ext2
    .type   ext2,@function
    .ent    ext2
ext2:
    nop
    .end    ext2

    .global ext3
    .type   ext3,@function
    .ent    ext3
ext3:
    nop
    .end    ext3

    .global ext4
    .type   ext4,@function
    .ent    ext4
ext4:
    nop
    .end    ext4

    .global ext5
    .type   ext5,@function
    .ent    ext5
ext5:
    nop
    .end    ext5

    .global ext6
    .type   ext6,@function
    .ent    ext6
ext6:
    nop
    .end    ext6

Add "data" symbols to the test input file. No functional changes.

# Assembly code defines set of externally visible labels.

# Shared library generation:
#   llvm-mc -triple=mipsel -filetype=obj -relocation-model=pic \
#           -o=%t1 %p/Inputs/ext.s
#   lld -flavor gnu -target mipsel -shared -o %t2 %t1

# Executable generation:
#   llvm-mc -triple=mipsel -filetype=obj -o=%t1 %p/Inputs/ext.s
#   lld -flavor gnu -target mipsel -e ext1 -o %t2 %t1

    .global ext1
    .type   ext1,@function
    .ent    ext1
ext1:
    nop
    .end    ext1

    .global ext2
    .type   ext2,@function
    .ent    ext2
ext2:
    nop
    .end    ext2

    .global ext3
    .type   ext3,@function
    .ent    ext3
ext3:
    nop
    .end    ext3

    .type   data1,@object
    .comm   data1,4,4
    .type   data2,@object
    .comm   data2,4,4
    .type   data3,@object
    .comm   data3,4,4


# REQUIRES: mips
# Check R_MIPS_GOT16 relocation against merge section.

# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -o %t.o %s
# RUN: ld.lld -shared -o %t.so %t.o
# RUN: llvm-objdump -dD %t.so | FileCheck %s

# CHECK: 000001f1 .rodata:
#                'f''o''o''\0'
# CHECK-NEXT: 1f1: 66 6f 6f 00
# CHECK: lw      $25, -32744($gp)
#                            0x1f1
# CHECK-NEXT: addiu   $4, $25, 497

  .text
  lw     $t9, %got($.str)($gp)
  addiu  $a0, $t9, %lo($.str)

  .section  .rodata.str,"aMS",@progbits,1
$.str:
  .asciz "foo"

Revert "[ELF] Update test case due to llvm r365618"

# REQUIRES: mips
# Check R_MIPS_GOT16 relocation against merge section.

# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -o %t.o %s
# RUN: ld.lld -shared -o %t.so %t.o
# RUN: llvm-readobj --symbols --mips-plt-got %t.so | FileCheck %s

# CHECK:      Symbol {
# CHECK:        Name: $.str
# CHECK-NEXT:   Value: 0x1F1
# CHECK:      }

# CHECK:      Local entries [
# CHECK-NEXT:   Entry {
# CHECK-NEXT:     Address:
# CHECK-NEXT:     Access: -32744
# CHECK-NEXT:     Initial: 0x0
# CHECK:        }
# CHECK:      ]

  .text
  lw     $t9, %got($.str)($gp)
  addiu  $a0, $t9, %lo($.str)

  .section  .rodata.str,"aMS",@progbits,1
$.str:
  .asciz "foo"


# frsqrte tests disabled because accuracy is CPU dependent.

#test_frsqrte_1:
  #_ REGISTER_IN f1 1.0
#  frsqrte f1, f1
#  blr
  #_ REGISTER_OUT f1 0.99975585937500000
  # want: 0.97

#test_frsqrte_2:
  #_ REGISTER_IN f1 64.0
#  frsqrte f1, f1
#  blr
  #_ REGISTER_OUT f1 0.12496948242187500

#test_frsqrte_3:
  #_ REGISTER_IN f1 0.5
#  frsqrte f1, f1
#  blr
  #_ REGISTER_OUT f1 1.41381835937500000
  # want: 1.375

Disable frsqrte tests in a way not breaking the rest

# frsqrte tests disabled because accuracy is CPU dependent.

test_frsqrte_1:
  # _ REGISTER_IN f1 1.0
#  frsqrte f1, f1
  blr
  # _ REGISTER_OUT f1 0.99975585937500000
  # want: 0.97

test_frsqrte_2:
  # _ REGISTER_IN f1 64.0
#  frsqrte f1, f1
  blr
  # _ REGISTER_OUT f1 0.12496948242187500

test_frsqrte_3:
  # _ REGISTER_IN f1 0.5
#  frsqrte f1, f1
  blr
  # _ REGISTER_OUT f1 1.41381835937500000
  # want: 1.375


# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: echo "SECTIONS { .text : { *(.text*) QUAD(bar) } }" > %t.script
# RUN: ld.lld --gc-sections -o %t %t.o --script %t.script | FileCheck -allow-empty %s

# CHECK-NOT: unable to evaluate expression: input section .rodata.bar has no output section assigned

.section .rodata.bar
.quad 0x1122334455667788
.global bar
bar:

.section .text
.global _start
_start:
  nop

Check the produced file instead of stderr.

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: echo "SECTIONS { .text : { *(.text*) QUAD(bar) } }" > %t.script
# RUN: ld.lld --gc-sections -o %t %t.o --script %t.script
# RUN: llvm-objdump -t %t | FileCheck %s

# CHECK: 0000000000000011         .rodata                 00000000 bar

.section .rodata.bar
.quad 0x1122334455667788
.global bar
bar:

.section .text
.global _start
_start:
  nop


Add a test for the offset of dynamic relocations.

// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: ld.lld %t.o -o %t -shared
// RUN: llvm-readobj -r  %t | FileCheck %s

        .section        .data.foo,"aw",@progbits
        .quad   foo

        .section        .data.zed,"aw",@progbits
        .quad   foo

// CHECK:      Section ({{.*}}) .rela.dyn {
// CHECK-NEXT:   0x2000 R_X86_64_64 foo 0x0
// CHECK-NEXT:   0x2008 R_X86_64_64 foo 0x0
// CHECK-NEXT: }


Add test case to cover handling of microMIPS relocations in 64-bit mode

# REQUIRES: mips

# Check handling of some microMIPS relocations in 64-bit mode.

# RUN: llvm-mc -filetype=obj -triple=mips64el-unknown-linux \
# RUN:         -mattr=micromips %s -o %t1.o
# RUN: llvm-mc -filetype=obj -triple=mips64el-unknown-linux \
# RUN:         -mattr=micromips %S/Inputs/mips-dynamic.s -o %t2.o
# RUN: ld.lld %t1.o %t2.o -o %t.exe
# RUN: llvm-objdump -d %t.exe | FileCheck %s

  .global  __start
__start:
  lui     $7,  %highest(_foo+0x300047FFF7FF8)
  lui     $7,  %higher (_foo+0x300047FFF7FF8)
  lui     $gp, %hi(%neg(%gp_rel(__start)))
  lui     $gp, %lo(%neg(%gp_rel(__start)))

# CHECK:      20000:  a7 41 03 00  lui $7, 3
# CHECK-NEXT: 20004:  a7 41 05 00  lui $7, 5
# CHECK-NEXT: 20008:  bc 41 02 00  lui $gp, 2
# CHECK-NEXT: 2000c:  bc 41 00 80  lui $gp, 32768


; Inturrupt Handlers

.include "routines/block.h"
.include "routines/screen.h"
.include "routines/random.h"

.include "fptetromones.h"
.include "ui.h"
.include "controls.h"

;; Blank Handlers
ROUTINE IrqHandler
	RTI

ROUTINE CopHandler
	RTI

ROUTINE VBlank
	; Save state
	REP #$30
	PHA
	PHB
	PHD
	PHX
	PHY

	SEP #$20
.A8
.I16

	Screen_VBlank

	JSR	Ui__VBlank

	; Must be done AFTER VRAM/OAM transfers, can go over limit.
	;
	; Had to move `Console__Update` and `Random__AddJoypadEntropy`
	; into VBlank because for some reasson setting Mode 7 matrix in
	; `Ui__VBlank` caused JOY1 to stop working in snes9x 1.51 debugger.

	JSR	Controls__Update
	JSR	Random__AddJoypadEntropy

	; Load State
	REP	#$30
	PLY
	PLX
	PLD
	PLB
	PLA

	RTI

Reset NMI Flag on VBlank.

; Inturrupt Handlers

.include "routines/block.h"
.include "routines/screen.h"
.include "routines/random.h"

.include "fptetromones.h"
.include "ui.h"
.include "controls.h"

;; Blank Handlers
ROUTINE IrqHandler
	RTI

ROUTINE CopHandler
	RTI

ROUTINE VBlank
	; Save state
	REP #$30
	PHA
	PHB
	PHD
	PHX
	PHY

	SEP #$20
.A8
.I16
	; Reset NMI Flag.
	LDA	RDNMI

	Screen_VBlank

	JSR	Ui__VBlank

	; Must be done AFTER VRAM/OAM transfers, can go over limit.
	;
	; Had to move `Console__Update` and `Random__AddJoypadEntropy`
	; into VBlank because for some reasson setting Mode 7 matrix in
	; `Ui__VBlank` caused JOY1 to stop working in snes9x 1.51 debugger.

	JSR	Controls__Update
	JSR	Random__AddJoypadEntropy

	; Load State
	REP	#$30
	PLY
	PLX
	PLD
	PLB
	PLA

	RTI


#
# Copyright (c) 1998 Robert Nordier
# All rights reserved.
#
# Redistribution and use in source and binary forms are freely
# permitted provided that the above copyright notice and this
# paragraph and the following disclaimer are duplicated in all
# such forms.
#
# This software is provided "AS IS" and without any express or
# implied warranties, including, without limitation, the implied
# warranties of merchantability and fitness for a particular
# purpose.
#

#	$Id:$

#
# BTX C startup code (ELF).
#

#
# Globals.
#
		.global _start
#
# Constants.
#
		.set ARGSIZ,0x60		# Size of arguments
#
# Client entry point.
#
_start: 	movl %eax,__base		# Set base address
		subl $ARGSIZ,%esp		# Set argument
		movl %esp,__args		#  pointer
		call main			# Invoke client main()
		call exit			# Invoke client exit()
#
# Data.
#
		.comm __base,4			# Client base address
		.comm __args,4			# Client arguments

Adjust setting of argument pointer for BTX 0.87.

#
# Copyright (c) 1998 Robert Nordier
# All rights reserved.
#
# Redistribution and use in source and binary forms are freely
# permitted provided that the above copyright notice and this
# paragraph and the following disclaimer are duplicated in all
# such forms.
#
# This software is provided "AS IS" and without any express or
# implied warranties, including, without limitation, the implied
# warranties of merchantability and fitness for a particular
# purpose.
#

#	$Id: btxcsu.s,v 1.1 1998/09/14 10:37:00 rnordier Exp $

#
# BTX C startup code (ELF).
#

#
# Globals.
#
		.global _start
#
# Constants.
#
		.set ARGADJ,0xfa0		# Argument adjustment
#
# Client entry point.
#
_start: 	movl %eax,__base		# Set base address
		movl %esp,%eax			# Set
		addl $ARGADJ,%eax		#  argument
		movl %eax,__args		#  pointer
		call main			# Invoke client main()
		call exit			# Invoke client exit()
#
# Data.
#
		.comm __base,4			# Client base address
		.comm __args,4			# Client arguments


Add fast asm code for 'Unsigned integer'

.text
.globl UI_Add
UI_Add:
movq (%rsi), %rax
addq %rax, (%rdi)
0:
leaq 8(%rdi), %rdi
leaq 8(%rsi), %rsi
movq (%rsi), %rax
adcq %rax, (%rdi)
decq %rdx
jnz 0b
setcb %al
retq


// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/abs.s -o %tabs
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
// RUN: lld -flavor gnu2 %tabs %t -o %tout
// RUN: llvm-objdump -s %tout
// REQUIRES: x86

.global _start
_start:
  movl $abs, %edx

#CHECK:      Contents of section .text:
#CHECK-NEXT:  {{[0-1a-f]+}} ba420000 00

Fix test to actually test something.

// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/abs.s -o %tabs
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
// RUN: lld -flavor gnu2 %tabs %t -o %tout
// RUN: llvm-objdump -d %tout | FileCheck %s
// REQUIRES: x86

.global _start
_start:
  movl $abs, %edx

//CHECK:      start:
//CHECK-NEXT: movl	$66, %edx


Add stub file for S/390 arithmetic routines.


# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld %t -o %t2
# RUN: llvm-readobj -program-headers %t2 | FileCheck %s
# RUN: hexdump -v -s 0x0001ff0 -x %t2 | FileCheck %s -check-prefix=FILL

# CHECK: ProgramHeader {
# CHECK:   Type: PT_LOAD
# CHECK:   Offset: 0x1000
# CHECK-NEXT:   VirtualAddress:
# CHECK-NEXT:   PhysicalAddress:
# CHECK-NEXT:   FileSize: 4096
# CHECK-NEXT:   MemSize:
# CHECK-NEXT:   Flags [
# CHECK-NEXT:     PF_R
# CHECK-NEXT:     PF_X
# CHECK-NEXT:   ]

## Check that executable page is filled with traps at it's end.
# FILL: 0001ff0 cccc cccc cccc cccc cccc cccc cccc cccc

.globl _start
_start:
  nop

Remove dependency on hexdump from lit test

# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld %t -o %t2
# RUN: llvm-readobj -program-headers %t2 | FileCheck %s
# RUN: od -Ax -x -N16 -j0x1ff0 %t2 | FileCheck %s -check-prefix=FILL

# CHECK: ProgramHeader {
# CHECK:   Type: PT_LOAD
# CHECK:   Offset: 0x1000
# CHECK-NEXT:   VirtualAddress:
# CHECK-NEXT:   PhysicalAddress:
# CHECK-NEXT:   FileSize: 4096
# CHECK-NEXT:   MemSize:
# CHECK-NEXT:   Flags [
# CHECK-NEXT:     PF_R
# CHECK-NEXT:     PF_X
# CHECK-NEXT:   ]

## Check that executable page is filled with traps at its end.
# FILL: 001ff0 cccc cccc cccc cccc cccc cccc cccc cccc

.globl _start
_start:
  nop


# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: echo "SECTIONS { \
# RUN:         used_in_reloc : { *(used_in_reloc) } \
# RUN:         used_in_script : { *(used_in_script) } \
# RUN:         .data : { *(.data) } \
# RUN:       }" > %t.script
# RUN: ld.lld -T %t.script -o %t.so %t.o -shared --gc-sections
# RUN: llvm-objdump -h %t.so | FileCheck %s

# CHECK: Idx Name          Size      Address          Type
# CHECK-NEXT:  0
# CHECK-NEXT:    used_in_reloc
# CHECK-NEXT:    .dynsym
# CHECK-NEXT:    .hash
# CHECK-NEXT:    .dynstr
# CHECK-NEXT:    .rela.dyn
# CHECK-NEXT:    .data
# CHECK-NEXT:    .dynamic
# CHECK-NEXT:    .comment
# CHECK-NEXT:    .symtab
# CHECK-NEXT:    .shstrtab
# CHECK-NEXT:    .strtab

        .data
        .global foo
foo:
        .quad __start_used_in_reloc

        .section unused,"a"
        .quad 0

        .section used_in_script,"a"
        .quad 0

        .section used_in_reloc,"a"
        .quad 0

Simplify test by producing an executable.

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: echo "SECTIONS { \
# RUN:         used_in_reloc : { *(used_in_reloc) } \
# RUN:         used_in_script : { *(used_in_script) } \
# RUN:         .text : { *(.text) } \
# RUN:       }" > %t.script
# RUN: ld.lld -T %t.script -o %t.so %t.o --gc-sections
# RUN: llvm-objdump -h %t.so | FileCheck %s

# CHECK: Idx Name          Size      Address          Type
# CHECK-NEXT:  0
# CHECK-NEXT:    used_in_reloc
# CHECK-NEXT:    .text
# CHECK-NEXT:    .comment
# CHECK-NEXT:    .symtab
# CHECK-NEXT:    .shstrtab
# CHECK-NEXT:    .strtab

        .global _start
_start:
        .quad __start_used_in_reloc

        .section unused,"a"
        .quad 0

        .section used_in_script,"a"
        .quad 0

        .section used_in_reloc,"a"
        .quad 0


/*****************************************************************************
 * Copyright (c) IBM Corp, 2016
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Jose Ricardo Ziviani - ppc64le implementation
 *     based on Claudio Fontana
 *     based on test_arm.s by Peter Maydell
 *****************************************************************************/

/* Initialise the gp regs */
li 0,0
li 1,1
li 2,2
li 3,3
li 4,4
li 5,5
li 6,6
li 7,7
li 8,8
li 9,9
li 10, 10
li 11, 11
li 12, 12
li 13, 13
li 14, 14
li 15, 15
li 16, 16
li 17, 17
li 18, 18
li 19, 19
li 20, 20
li 21, 21
li 22, 22
li 23, 23
li 24, 24
li 25, 25
li 26, 26
li 27, 27
li 28, 28
li 29, 29
li 30, 30
li 31, 31

/* do compare */
.int 0x00005af0
/* exit test */
.int 0x00005af1


public start	;Make the entry point public
	org $2000		;Place the origin at $2000

start:
	;  YOUR CODE HERE
	;Instructions must be indented by at least one space,
	;otherwise the assembler will misinterpret them as labels.

	;Then, to terminate the program, spin forever. You can set
	;a breakpoint to the next instruction to be notified of
	;the program's termination.
forever:
	bra forever

Make the comments in the template align, regardless of the tab settings.


/*
 * Offsets into into structures used from asm.  Must be kept in sync with
 * appropriate headers.
 *
 * $FreeBSD$
 */

#define	UC_SIGMASK	0x0
#define	UC_MC		0x10
#define	MC_G1		0x8
#define	MC_O0		0x40
#define	MC_O1		0x48
#define	MC_O6		0x70
#define	MC_O7		0x78
#define	MC_TNPC		0x90
#define	MC_TPC		0x88

Add jmpbuf offsets. Remove ucontext offsets.

/*
 * Offsets into into structures used from asm.  Must be kept in sync with
 * appropriate headers.
 *
 * $FreeBSD$
 */

#define	_JB_FP		0x0
#define	_JB_PC		0x8
#define	_JB_SP		0x10
#define	_JB_SIGMASK	0x18
#define	_JB_SIGFLAG	0x28

#define	SIG_BLOCK	1
#define	SIG_SETMASK	3


/*
 * Offsets into structures used from asm.  Must be kept in sync with
 * appropriate headers.
 *
 * $FreeBSD$
 */

#define	FPRS_FEF	0x4

#define	UF_G0		0x0
#define	UF_G1		0x8
#define	UF_G2		0x10
#define	UF_G3		0x18
#define	UF_G4		0x20
#define	UF_G5		0x28
#define	UF_G6		0x30
#define	UF_G7		0x38
#define	UF_O0		0x40
#define	UF_O1		0x48
#define	UF_O2		0x50
#define	UF_O3		0x58
#define	UF_O4		0x60
#define	UF_O5		0x68
#define	UF_O6		0x70
#define	UF_O7		0x78
#define	UF_PC		0x90
#define	UF_NPC		0x98
#define	UF_SFAR		0xa0
#define	UF_SFSR		0xa8
#define	UF_TAR		0xb0
#define	UF_TYPE		0xb8
#define	UF_SIZEOF	0xc0

Fix wrong offsets. Add offsets for %fsr and %tstate.

/*
 * Offsets into structures used from asm.  Must be kept in sync with
 * appropriate headers.
 *
 * $FreeBSD$
 */

#define	FPRS_FEF	0x4

#define	CCR_MASK	0xff
#define	ASI_MASK	0xff

#define	UF_G0		0x0
#define	UF_G1		0x8
#define	UF_G2		0x10
#define	UF_G3		0x18
#define	UF_G4		0x20
#define	UF_G5		0x28
#define	UF_G6		0x30
#define	UF_G7		0x38
#define	UF_O0		0x40
#define	UF_O1		0x48
#define	UF_O2		0x50
#define	UF_O3		0x58
#define	UF_O4		0x60
#define	UF_O5		0x68
#define	UF_O6		0x70
#define	UF_O7		0x78
#define	UF_PC		0x80
#define	UF_NPC		0x88
#define	UF_SFAR		0x90
#define	UF_SFSR		0x98
#define	UF_TAR		0xa0
#define	UF_TYPE		0xa8
#define	UF_STATE	0xb0
#define	UF_FSR		0xb8
#define	UF_SIZEOF	0xc0


( function _l3_Global_s_()
{

'use strict';

let _global = _global_;
let _ = _global_.wTools;
_global_.wTools.global = _global_.wTools.global || Object.create( null );

// --
// implementation
// --

function is( src )
{
  _.assert( arguments.length === 1, 'Expects single argument' );

  if( _.primitiveIs( src ) )
  return false;

  for( let namespace in _globals_ )
  {
    if( _globals_[ namespace ] === src )
    return true;
  }

  return false;
}

//

function isReal( src )
{
  _.assert( arguments.length === 1, 'Expects single argument' );

  // if( _.primitiveIs( src ) )
  // return false;

  if( src === _realGlobal_ && src.__GLOBAL_NAME__ === 'real' )
  return true;
  return false;
}

//

function isDerivative( src )
{
  _.assert( arguments.length === 1, 'Expects single argument' );

  // if( _.primitiveIs( src ) )
  // return false;

  if( _.global.is( src ) && !_.global.isReal( src ) )
  return true;
  return false;
}

// --
// extension
// --

var Extension =
{
  is,
  isReal,
  isDerivative
}

//

Object.assign( _.global, Extension );

// --
// export
// --

if( typeof module !== 'undefined' )
module[ 'exports' ] = _;

})();

Fix routine `is`, namespace `global`, check prototype of namespaces

( function _l3_Global_s_()
{

'use strict';

let _global = _global_;
let _ = _global_.wTools;
_global_.wTools.global = _global_.wTools.global || Object.create( null );

// --
// implementation
// --

function is( src )
{
  _.assert( arguments.length === 1, 'Expects single argument' );

  if( _.primitiveIs( src ) )
  return false;

  if( src === _global_ )
  return true;

  if( Object.getPrototypeOf( src ) === _global_ )
  return true;

  return false;
}

//

function isReal( src )
{
  _.assert( arguments.length === 1, 'Expects single argument' );

  // if( _.primitiveIs( src ) )
  // return false;

  if( src === _realGlobal_ && src.__GLOBAL_NAME__ === 'real' )
  return true;
  return false;
}

//

function isDerivative( src )
{
  _.assert( arguments.length === 1, 'Expects single argument' );

  // if( _.primitiveIs( src ) )
  // return false;

  if( _.global.is( src ) && !_.global.isReal( src ) )
  return true;
  return false;
}

// --
// extension
// --

var Extension =
{
  is,
  isReal,
  isDerivative
}

//

Object.assign( _.global, Extension );

// --
// export
// --

if( typeof module !== 'undefined' )
module[ 'exports' ] = _;

})();


// Make sure the arm64 default on cyclone when compiling for apple.
// RUN: %clang -target arm64-apple-ios -arch arm64 -### -c %s 2>&1 | FileCheck -check-prefix=TARGET %s
//
// TARGET: "-cc1as"
// TARGET: "-target-cpu" "cyclone"


// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t -stats 2>%t.out
// RUN: FileCheck --input-file=%t.out %s

// Test that we create no fixups for this file since "a" and "b" are in the
// same fragment.

// CHECK:      assembler - Number of emitted object file bytes
// CHECK-NEXT: assembler - Number of fragment layouts

a:
  nop
b:
  .long b - a

Rewrite a test to check actual output rather than intermediate implementation detail.

// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
// RUN: llvm-objdump -r %t | FileCheck %s

// Test that we create no fixups for this file since "a" and "b"
// are in the same fragment. If b was in a different section, a
// fixup causing a relocation would be generated in the object file.

// CHECK-NOT: RELOCATION RECORDS

a:
  nop
b:
  .long b - a


Add an XFAIL test where we aren't matching the correct instruction because we don't understand how the specific instruction is doing sign extension.

// RUN: llvm-mc -triple i386-unknown-unknown --show-encoding %s | FileCheck %s
// XFAIL: *

// CHECK: addl	$4294967295, %eax       # encoding: [0x83,0xc0,0xff]
        addl $0xFFFFFFFF, %eax

// CHECK: addl	$65535, %eax       # encoding: [0x66,0x83,0xc0,0xff]
        addw $0xFFFF, %ax


test_frsqrte_1:
  #_ REGISTER_IN f1 1.0
  frsqrte f1, f1
  blr
  #_ REGISTER_OUT f1 0.99975585937500000
  # want: 0.97

test_frsqrte_2:
  #_ REGISTER_IN f1 64.0
  frsqrte f1, f1
  blr
  #_ REGISTER_OUT f1 0.12496948242187500

test_frsqrte_3:
  #_ REGISTER_IN f1 0.5
  frsqrte f1, f1
  blr
  #_ REGISTER_OUT f1 1.4138183593750000
  # want: 1.375

Fix precision of test register in frsqrte test.

test_frsqrte_1:
  #_ REGISTER_IN f1 1.0
  frsqrte f1, f1
  blr
  #_ REGISTER_OUT f1 0.99975585937500000
  # want: 0.97

test_frsqrte_2:
  #_ REGISTER_IN f1 64.0
  frsqrte f1, f1
  blr
  #_ REGISTER_OUT f1 0.12496948242187500

test_frsqrte_3:
  #_ REGISTER_IN f1 0.5
  frsqrte f1, f1
  blr
  #_ REGISTER_OUT f1 1.41381835937500000
  # want: 1.375


// RUN: mkdir -p %t.foo
// RUN: cp %s %t.foo/src.s
// RUN: cd %t.foo

// RUN: llvm-mc -triple=x86_64-linux-unknown -g src.s -filetype=obj -o out.o
// RUN: llvm-dwarfdump -v -debug-info out.o | FileCheck --check-prefix=NO_MAP %s
// RUN: llvm-mc -triple=x86_64-linux-unknown -g src.s -filetype=obj -o out.o -fdebug-prefix-map=%t.foo=src_root
// RUN: llvm-dwarfdump -v -debug-info out.o | FileCheck --check-prefix=MAP --implicit-check-not ".foo" %s

f:
  nop

// NO_MAP: DW_AT_comp_dir [DW_FORM_string] ("{{.*}}.foo")

// MAP: DW_AT_name [DW_FORM_string] ("src.s")
// MAP: DW_AT_comp_dir [DW_FORM_string] ("src_root")
// MAP: DW_AT_decl_file [DW_FORM_data4] ("src_root/src.s")

Update test to work on Windows

// RUN: mkdir -p %t.foo
// RUN: cp %s %t.foo/src.s
// RUN: cd %t.foo

// RUN: llvm-mc -triple=x86_64-linux-unknown -g src.s -filetype=obj -o out.o
// RUN: llvm-dwarfdump -v -debug-info out.o | FileCheck --check-prefix=NO_MAP %s
// RUN: llvm-mc -triple=x86_64-linux-unknown -g src.s -filetype=obj -o out.o -fdebug-prefix-map=%t.foo=src_root
// RUN: llvm-dwarfdump -v -debug-info out.o | FileCheck --check-prefix=MAP --implicit-check-not ".foo" %s

f:
  nop

// NO_MAP: DW_AT_comp_dir [DW_FORM_string] ("{{.*}}.foo")

// MAP: DW_AT_name [DW_FORM_string] ("src.s")
// MAP: DW_AT_comp_dir [DW_FORM_string] ("src_root")
// MAP: DW_AT_decl_file [DW_FORM_data4] ("src_root{{(/|\\)}}src.s")


.global gdt_flush
.extern gdtp

gdt_flush:
	lgdt gdtp        # Load the GDT with our '_gp' which is a special pointer
	mov %ax, 0x10      # 0x10 is the offset in the GDT to our data segment
	mov %ds, %ax
	mov %es, %ax
	mov %fs, %ax
	mov %gs, %ax
	mov %ss, %ax
	jmp flush2
flush2:
	ret

Add 8 byte offset to the jump.

.global gdt_flush
.extern gdtp

gdt_flush:
	lgdt gdtp        # Load the GDT with our '_gp' which is a special pointer
	mov %ax, 0x10      # 0x10 is the offset in the GDT to our data segment
	mov %ds, %ax
	mov %es, %ax
	mov %fs, %ax
	mov %gs, %ax
	mov %ss, %ax
	#jump to an 0x08 offset from flush2.
	jmp 0x08+flush2
flush2:
	ret


// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: lld -flavor gnu2 %t.o -shared -soname=bar -o %t.so
// RUN: lld -flavor gnu2 %t.o %t.so %t.so -o %t
// RUN: llvm-readobj --dynamic-table %t | FileCheck %s

// CHECK:  0x0000000000000001 NEEDED               SharedLibrary (bar)
// CHECK-NOT: NEEDED

.global _start
_start:

Make the test a bit stronger.

// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: lld -flavor gnu2 %t.o -shared -soname=bar -o %t.so
// RUN: lld -flavor gnu2 %t.o -shared -soname=bar -o %t2.so
// RUN: lld -flavor gnu2 %t.o %t.so %t2.so -o %t
// RUN: llvm-readobj --dynamic-table %t | FileCheck %s

// CHECK:  0x0000000000000001 NEEDED               SharedLibrary (bar)
// CHECK-NOT: NEEDED

.global _start
_start:


# RUN: llvm-mc -triple=i386-pc-win32 -filetype=obj -o %t.obj %s
# RUN: lld-link /subsystem:console /debug /nodefaultlib /entry:foo /out:%t.exe /pdb:%t.pdb %t.obj
# RUN: llvm-pdbutil dump -fpo %t.pdb | FileCheck %s

# CHECK:                         Old FPO Data
# CHECK-NEXT: ============================================================
# CHECK-NEXT:   RVA    | Code | Locals | Params | Prolog | Saved Regs | Use BP | Has SEH | Frame Type
# CHECK-NEXT: 00001002 |    1 |      2 |      3 |      4 |          0 |  false |   false |       FPO

.text
_foo:
ret

.global _foo

.section .debug$F,"dr"
	.long _foo@IMGREL+2
	.long 1 #  cbProc
	.long 2 # cdwLocals;
	.short 3 # cdwParams;
	.short 4 # flags
  # cbProlog : 8;
  # cbRegs : 3;
  # fHasSEH : 1;
  # fUseBP : 1;
  # reserved : 1;
  # cbFrame : 2;

Add missing Requires x86 to fix buildbot

# REQUIRES: x86
# RUN: llvm-mc -triple=i386-pc-win32 -filetype=obj -o %t.obj %s
# RUN: lld-link /subsystem:console /debug /nodefaultlib /entry:foo /out:%t.exe /pdb:%t.pdb %t.obj
# RUN: llvm-pdbutil dump -fpo %t.pdb | FileCheck %s

# CHECK:                         Old FPO Data
# CHECK-NEXT: ============================================================
# CHECK-NEXT:   RVA    | Code | Locals | Params | Prolog | Saved Regs | Use BP | Has SEH | Frame Type
# CHECK-NEXT: 00001002 |    1 |      2 |      3 |      4 |          0 |  false |   false |       FPO

.text
_foo:
ret

.global _foo

.section .debug$F,"dr"
	.long _foo@IMGREL+2
	.long 1 #  cbProc
	.long 2 # cdwLocals;
	.short 3 # cdwParams;
	.short 4 # flags
  # cbProlog : 8;
  # cbRegs : 3;
  # fHasSEH : 1;
  # fUseBP : 1;
  # reserved : 1;
  # cbFrame : 2;


// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
// RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s

// CHECK:      Displaying notes found at file offset 0x00000040 with length 0x00000014:
// CHECK-NEXT:   Owner                 Data size       Description
// CHECK-NEXT:   GNU                   0x00000004      NT_GNU_PROPERTY_TYPE_0 (property note)
// CHECK-NEXT:     Properties:
// CHECK-NEXT:     <corrupted GNU_PROPERTY_TYPE_0>

// Section below is broken, check we report that.

.section ".note.gnu.property", "a"
.align 4
  .long 4           /* Name length is always 4 ("GNU") */
  .long end - begin /* Data length */
  .long 5           /* Type: NT_GNU_PROPERTY_TYPE_0 */
  .asciz "GNU"      /* Name */
  .p2align 3
begin:
  .long 1           /* Type: GNU_PROPERTY_STACK_SIZE */
end:

Fix build bot after r328078 "llvm-readobj] - Teach llvm-readobj to dump .note.gnu.property sections."

// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
// RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s

// CHECK:      Displaying notes found at file offset 0x00000040 with length 0x00000014:
// CHECK-NEXT:   Owner                 Data size       Description
// CHECK-NEXT:   GNU                   0x00000004      NT_GNU_PROPERTY_TYPE_0 (property note)
// CHECK-NEXT:     Properties:  <corrupted GNU_PROPERTY_TYPE_0>

// Section below is broken, check we report that.

.section ".note.gnu.property", "a"
.align 4
  .long 4           /* Name length is always 4 ("GNU") */
  .long end - begin /* Data length */
  .long 5           /* Type: NT_GNU_PROPERTY_TYPE_0 */
  .asciz "GNU"      /* Name */
  .p2align 3
begin:
  .long 1           /* Type: GNU_PROPERTY_STACK_SIZE */
end:


# REQUIRES: x86
# Verify that default output filename is a.out.

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: mkdir -p %t.dir
# RUN: cd %t.dir
# RUN: rm -f a.out
# RUN: not test -e a.out
# RUN: lld -flavor gnu2 %t
# RUN: test -e a.out

.globl _start;
_start:
  mov $60, %rax
  mov $42, %rdi
  syscall

Remove the dependency to 'test' command.

# REQUIRES: x86
# Verify that default output filename is a.out.

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: mkdir -p %t.dir
# RUN: cd %t.dir
# RUN: rm -f a.out
# RUN: not llvm-readobj a.out > /dev/null 2>&1
# RUN: lld -flavor gnu2 %t
# RUN: llvm-readobj a.out > /dev/null 2>&1

.globl _start;
_start:
  mov $60, %rax
  mov $42, %rdi
  syscall


Add a reduction of the recent bootstrap failure.

// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
// RUN: ld.lld %t.o -o %t.so -shared
// RUN: llvm-readobj -s -section-data -t %t.so | FileCheck %s

// CHECK:      Name: .rodata
// CHECK-NEXT: Type: SHT_PROGBITS
// CHECK-NEXT: Flags [
// CHECK-NEXT:   SHF_ALLOC
// CHECK-NEXT:   SHF_MERGE
// CHECK-NEXT:   SHF_STRINGS
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x1C8
// CHECK-NEXT: Offset:
// CHECK-NEXT: Size: 8
// CHECK-NEXT: Link: 0
// CHECK-NEXT: Info: 0
// CHECK-NEXT: AddressAlignment: 1
// CHECK-NEXT: EntrySize: 1
// CHECK-NEXT: SectionData (
// CHECK-NEXT:   0000: 61626300 64656600                    |abc.def.|
// CHECK-NEXT: )

// CHECK:      Symbols [
// CHECK:        Symbol {
// CHECK:          Name: bar
// CHECK-NEXT:     Value: 0x1CC
// CHECK-NEXT:     Size: 0
// CHECK-NEXT:     Binding: Local
// CHECK-NEXT:     Type: None
// CHECK-NEXT:     Other: 0
// CHECK-NEXT:     Section: .rodata

        .global foo
foo:
        leaq    .L.str(%rip), %rsi
        .section        .rodata.str1.1,"aMS",@progbits,1
.L.str:
        .asciz  "abc"
bar:
        .asciz  "def"


//
// arch/x86_64/rsp/vabs.s
//
// CEN64: Cycle-Accurate Nintendo 64 Simulator.
// Copyright (C) 2014, Tyler J. Stachecki.
//
// This file is subject to the terms and conditions defined in
// 'LICENSE', which is part of this source code package.
//

#
# xmm1 = vs
# xmm0 = vt
# xmm5 = acc_lo
#

.global RSP_VABS
.type	RSP_VABS, @function

RSP_VABS:

.ifdef __AVX__
  vpsraw $0xf, %xmm1, %xmm3
  vpxor %xmm3, %xmm0, %xmm2
  vpsubsw %xmm3, %xmm2, %xmm2
  vpsignw %xmm1, %xmm0, %xmm5
  vpblendvb %xmm3, %xmm2, %xmm5, %xmm0
  retq
.else
  movdqa %xmm1, %xmm3
  pcmpeqw %xmm2, %xmm1
  psraw $0xF, %xmm3
  pandn %xmm0, %xmm1
  pxor %xmm3, %xmm1
  movdqa %xmm1, %xmm5
  psubsw %xmm3, %xmm1
  psubw %xmm3, %xmm5
  retq
.endif

.size RSP_VABS,.-RSP_VABS

Fix register-caching version of VABS.

//
// arch/x86_64/rsp/vabs.s
//
// CEN64: Cycle-Accurate Nintendo 64 Simulator.
// Copyright (C) 2014, Tyler J. Stachecki.
//
// This file is subject to the terms and conditions defined in
// 'LICENSE', which is part of this source code package.
//

#
# xmm1 = vs
# xmm0 = vt
# xmm5 = acc_lo
#

.global RSP_VABS
.type	RSP_VABS, @function

RSP_VABS:

.ifdef __AVX__
  vpsraw $0xf, %xmm1, %xmm3
  vpxor %xmm3, %xmm0, %xmm2
  vpsubsw %xmm3, %xmm2, %xmm2
  vpsignw %xmm1, %xmm0, %xmm5
  vpblendvb %xmm3, %xmm2, %xmm5, %xmm0
  retq

.else
  pcmpeqw %xmm1, %xmm2
  psraw $0xF, %xmm1
  pandn %xmm0, %xmm2
  pxor %xmm1, %xmm2
  movdqa %xmm2, %xmm5
  psubsw %xmm1, %xmm2
  psubw %xmm1, %xmm5
  movdqa %xmm2, %xmm0
  retq
.endif

.size RSP_VABS,.-RSP_VABS


// RUN: not llvm-mc -triple i386-unknown-unknown %s 2> %t
// RUN: FileCheck -input-file %t %s

// Currently XFAIL'ed, since the front-end isn't validating this. Figure out the
// right resolution.
//
// XFAIL: *

        .text
a:
        .data
// CHECK: expected relocatable expression
        .long -(0 + a)

Test for invalid constant expr addition - bad octal constant.

// RUN: not llvm-mc -triple x86_64-apple-darwin10 %s 2> %t.err | FileCheck %s
// RUN: FileCheck --check-prefix=CHECK-ERRORS %s < %t.err
// CHECK: 	.section	__TEXT,__text,regular,pure_instructions
// CHECK-ERRORS: error: Invalid octal number
.long 80+08


// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/../Inputs/shared.s -o %t2.o
// RUN: ld.lld -shared %t2.o -o %t2.so
// RUN: echo "PHDRS { text PT_LOAD FILEHDR PHDRS; } \
// RUN:       SECTIONS { .text : { *(.text) } : text }" >> %t.script
// RUN: ld.lld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -rpath foo -rpath bar --script %t.script --export-dynamic %t.o %t2.so -o %t
// RUN: llvm-readobj -s %t | FileCheck %s

// CHECK-NOT:        Name: .interp

.global _start
_start:

Use > and not >> to create the script.

// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/../Inputs/shared.s -o %t2.o
// RUN: ld.lld -shared %t2.o -o %t2.so
// RUN: echo "PHDRS { text PT_LOAD FILEHDR PHDRS; } \
// RUN:       SECTIONS { .text : { *(.text) } : text }" > %t.script
// RUN: ld.lld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -rpath foo -rpath bar --script %t.script --export-dynamic %t.o %t2.so -o %t
// RUN: llvm-readobj -s %t | FileCheck %s

// CHECK-NOT:        Name: .interp

.global _start
_start:


# RUN: not llvm-mc %s -triple mips-unknown-unknown -mcpu=mips64r2 2>&1 | FileCheck %s
# CHECK: .text

        .set fp=xx
# CHECK     : error: 'set fp=xx'option requires O32 ABI
# CHECK     : .set fp=xx
# CHECK     :          ^

Fix FileCheck prefixes with whitespace between 'CHECK' and ':'

# RUN: not llvm-mc %s -triple mips-unknown-linux -mcpu=mips64r2 2>&1 | FileCheck %s
        .set fp=xx
# CHECK: error: '.set fp=xx' requires the O32 ABI
# CHECK: .set fp=xx
# CHECK:          ^


Add an interesting test case we already pass.

// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: ld.lld %t.o -o %t.so -shared -O3
// RUN: llvm-readobj -r -s %t.so | FileCheck %s

        .section        foo,"aMS",@progbits,1
        .asciz "bar"
        .asciz "ar"

        .text
        .quad foo + 4

// CHECK:      Name: foo
// CHECK-NEXT: Type: SHT_PROGBITS
// CHECK-NEXT: Flags [
// CHECK-NEXT:   SHF_ALLOC
// CHECK-NEXT:   SHF_MERGE
// CHECK-NEXT:   SHF_STRINGS
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x1C8

// CHECK:      Relocations [
// CHECK-NEXT:   Section ({{.*}}) .rela.dyn {
// CHECK-NEXT:     0x{{.*}} R_X86_64_RELATIVE - 0x1C9
// CHECK-NEXT:   }
// CHECK-NEXT: ]


Add test for the interaction of copy relocations and non alloc sections.

// REQUIRES: x86

// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/relocation-copy.s -o %t2.o
// RUN: ld.lld %t2.o -o %t2.so -shared
// RUN: ld.lld %t.o %t2.so -o %t.exe
// RUN: llvm-readobj -s -section-data -r %t.exe | FileCheck %s

        .global _start
_start:
        .long x

        .section foo
        .long y

// CHECK:      Name: .text
// CHECK-NEXT: Type: SHT_PROGBITS
// CHECK-NEXT: Flags [
// CHECK-NEXT:   SHF_ALLOC
// CHECK-NEXT:   SHF_EXECINSTR
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x11000
// CHECK-NEXT: Offset: 0x1000
// CHECK-NEXT: Size: 4
// CHECK-NEXT: Link: 0
// CHECK-NEXT: Info: 0
// CHECK-NEXT: AddressAlignment: 4
// CHECK-NEXT: EntrySize: 0
// CHECK-NEXT: SectionData (
// CHECK-NEXT:   0000: 00300100
// CHECK-NEXT: )

// CHECK:      Name: foo
// CHECK-NEXT: Type: SHT_PROGBITS
// CHECK-NEXT: Flags [
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset: 0x20B0
// CHECK-NEXT: Size: 4
// CHECK-NEXT: Link: 0
// CHECK-NEXT: Info: 0
// CHECK-NEXT: AddressAlignment: 1
// CHECK-NEXT: EntrySize: 0
// CHECK-NEXT: SectionData (
// CHECK-NEXT:   0000: 00000000
// CHECK-NEXT: )

// CHECK:      Relocations [
// CHECK-NEXT:   Section (4) .rela.dyn {
// CHECK-NEXT:     0x13000 R_X86_64_COPY x 0x0
// CHECK-NEXT:   }
// CHECK-NEXT: ]


# REQUIRES: x86
# Check that we fall back to search paths if a version script was not found
# This behaviour matches ld.bfd.

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: mkdir -p %T/searchpath
# RUN: echo '{};' > %T/searchpath/t.script
# RUN: ld.lld -L%T/searchpath --version-script=t.script %t.o -o /dev/null
# RUN: not ld.lld --version-script=t.script %t.o 2>&1 | FileCheck -check-prefix ERROR %s
# ERROR: error: cannot find version script

Make a test more robust.

# REQUIRES: x86
# Check that we fall back to search paths if a version script was not found
# This behaviour matches ld.bfd.

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: mkdir -p %T/searchpath
# RUN: echo '{};' > %T/searchpath/%basename_t.script
# RUN: ld.lld -L%T/searchpath --version-script=%basename_t.script %t.o -o /dev/null
# RUN: not ld.lld --version-script=%basename_t.script %t.o 2>&1 | FileCheck -check-prefix ERROR %s
# ERROR: error: cannot find version script


FEATURE_FLAGS          EQU 0x01
EXTENDED_FEATURE_FLAGS EQU 0x80000001

APIC_PRESENT     EQU 1<<9
LONGMODE_ENABLED EQU 1<<29

GLOBAL capabilities_is_64bit
GLOBAL capabilities_has_apic

; XXX verify that the CPU supports CPUID!

capabilities_is_64bit:
    PUSH EBX
    PUSH ECX
    PUSH EDX

    MOV EAX, EXTENDED_FEATURE_FLAGS
    CPUID

    MOV EAX, 0
    AND EDX, LONGMODE_ENABLED
    SETNZ AL

    POP EDX
    POP ECX
    POP EBX

    RET

capabilities_has_apic:
    PUSH EBX
    PUSH ECX
    PUSH EDX

    MOV EAX, FEATURE_FLAGS
    CPUID

    MOV EAX, 0
    AND EDX, APIC_PRESENT
    SETNZ AL

    POP EDX
    POP ECX
    POP EBX

    RET

Make capability checking functions a macro

FEATURE_FLAGS          EQU 0x01
EXTENDED_FEATURE_FLAGS EQU 0x80000001

APIC_PRESENT     EQU 1<<9
LONGMODE_ENABLED EQU 1<<29

; XXX verify that the CPU supports CPUID!

; name, EAX_VALUE, REG, BIT
%MACRO GEN_CAPS 4
GLOBAL %1
%1:
    PUSH EBX
    PUSH ECX
    PUSH EDX

    MOV EAX, %2
    CPUID

    MOV EAX, 0
    AND %3, %4
    SETNZ AL

    POP EDX
    POP ECX
    POP EBX

    RET
%ENDMACRO

GEN_CAPS capabilities_is_64bit, EXTENDED_FEATURE_FLAGS, EDX, LONGMODE_ENABLED
GEN_CAPS capabilities_has_apic, FEATURE_FLAGS, EDX, APIC_PRESENT


# REQUIRES: x86
# This test is to make sure that we can handle implicit addends properly.

# RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux %s -o %t
# RUN: ld.lld %t -o %t2 --icf=all --verbose | FileCheck %s

# CHECK:     selected .text.f1
# CHECK:       removed .text.f2
# CHECK-NOT:   removed .text.f3

.globl _start, f1, f2, f3
_start:
  ret

.section .text.f1, "ax"
f1:
  movl $42, 4(%edi)

.section .text.f2, "ax"
f2:
  movl $42, 4(%edi)

.section .text.f3, "ax"
f3:
  movl $42, 8(%edi)


; RUN: llvm-mc -triple arm64-apple-darwin -filetype=obj -o - %s | macho-dump | FileCheck %s

foo:
  .long 0
bar:
  .long 1

baz:
  .byte foo - bar
  .short foo - bar

; CHECK: # Relocation 0
; CHECK: (('word-0', 0x9),
; CHECK:  ('word-1', 0x1a000002)),
; CHECK: # Relocation 1
; CHECK: (('word-0', 0x9),
; CHECK:  ('word-1', 0xa000001)),
; CHECK: # Relocation 2
; CHECK: (('word-0', 0x8),
; CHECK:  ('word-1', 0x18000002)),
; CHECK: # Relocation 3
; CHECK: (('word-0', 0x8),
; CHECK:  ('word-1', 0x8000001)),

Use llvm-readobj instead of macho-dump.

; RUN: llvm-mc -triple arm64-apple-darwin -filetype=obj -o - %s | llvm-readobj -r | FileCheck %s

foo:
  .long 0
bar:
  .long 1

baz:
  .byte foo - bar
  .short foo - bar

; CHECK: File: <stdin>
; CHECK: Format: Mach-O arm64
; CHECK: Arch: aarch64
; CHECK: AddressSize: 64bit
; CHECK: Relocations [
; CHECK:  Section __text {
; CHECK:    0x9 0 1 1 ARM64_RELOC_SUBTRACTOR 0 bar
; CHECK:    0x9 0 1 1 ARM64_RELOC_UNSIGNED 0 foo
; CHECK:    0x8 0 0 1 ARM64_RELOC_SUBTRACTOR 0 bar
; CHECK:    0x8 0 0 1 ARM64_RELOC_UNSIGNED 0 foo
; CHECK:  }
; CHECK: ]


// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump  | FileCheck %s

// Test that this produces an undefined reference to .Lfoo

        je	.Lfoo

// CHECK: ('_symbols', [
// CHECK:      (('st_name', 1) # '.Lfoo'
// CHECK-NEXT:  ('st_bind', 1)
// CHECK: (('sh_name', 36) # '.strtab'


# REQUIRES: x86

### Make sure that we do not merge data.
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld %t -o %t2 --icf=all --verbose | FileCheck %s

# CHECK-NOT: selected .data.d1
# CHECK-NOT: selected .data.d2

.globl _start, d1, d2
_start:
  ret

.section .data.f1, "a"
d1:
  .byte 1

.section .data.f2, "a"
d2:
  .byte 1

Fix test to test what it intended to test.

# REQUIRES: x86

### Make sure that we do not merge data.
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld %t -o %t2 --icf=all --verbose | FileCheck %s
# RUN: llvm-readelf -S -W %t2 | FileCheck --check-prefix=SEC %s

# SEC:  .rodata      PROGBITS  0000000000200120 000120 000002 00 A 0 0 1

# CHECK-NOT: selected .rodata.d1
# CHECK-NOT: selected .rodata.d2

.globl _start, d1, d2
_start:
  ret

.section .rodata.f1, "a"
d1:
  .byte 1

.section .rodata.f2, "a"
d2:
  .byte 1


Add empty .s file to allow `//go:linkname`

// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Empty assembly file so empty func definitions work.


.globl sys$syscall
sys$syscall:
	/*
        Ugly: Kernel is caller-save, Myrddin
        is callee-save. We need to preserve
        registers before entering the kernel.

        However, we also need SP to point to the
        start of the arguments.

	Luckily, the kernel doesn't touch our stack,
	and we have 256 bytes of gap if we get a note.
        */
        MOVQ BX,-16(SP)
        MOVQ CX,-24(SP)
        MOVQ DX,-32(SP)
        MOVQ SI,-40(SP)
        MOVQ DI,-48(SP)
        MOVQ BP,-56(SP)
        MOVQ R8,-64(SP)
        MOVQ R9,-72(SP)
        MOVQ R10,-80(SP)
        MOVQ R11,-88(SP)
        MOVQ R12,-104(SP)
        MOVQ R13,-112(SP)
        MOVQ R14,-120(SP)
        MOVQ R15,-128(SP)
        ADDQ $8,SP

	SYSCALL

	SUBQ $8,SP
        MOVQ -16(SP),BX
        MOVQ -24(SP),CX
        MOVQ -32(SP),DX
        MOVQ -40(SP),SI
        MOVQ -48(SP),DI
        MOVQ -56(SP),BP
        MOVQ -64(SP),R8
        MOVQ -72(SP),R9
        MOVQ -80(SP),R10
        MOVQ -88(SP),R11
        MOVQ -104(SP),R12
        MOVQ -112(SP),R13
        MOVQ -120(SP),R14
        MOVQ -128(SP),R15
	RET


; vim: ft=nasm

section .multiboot
align 4
mboot:
    MBALIGN             equ 1<<0
    MEMINFO             equ 1<<1
    FLAGS               equ (MBALIGN | MEMINFO)
    MAGIC_NUMBER        equ 0x1BADB002
    CHECKSUM            equ -(MAGIC_NUMBER+FLAGS)

    dd MAGIC_NUMBER
    dd FLAGS
    dd CHECKSUM

section .bss,nobits
align 4
stack_bottom:
times 16384 db 0
stack_top:

section .text
global loader
loader:
    mov esp, stack_top

    extern kmain
    call kmain
    cli
.loop:
    hlt
    jmp .loop

Change kernel stack size to hex

; vim: ft=nasm

section .multiboot
align 4
mboot:
    MBALIGN             equ 1<<0
    MEMINFO             equ 1<<1
    FLAGS               equ (MBALIGN | MEMINFO)
    MAGIC_NUMBER        equ 0x1BADB002
    CHECKSUM            equ -(MAGIC_NUMBER+FLAGS)

    dd MAGIC_NUMBER
    dd FLAGS
    dd CHECKSUM

section .bss,nobits
align 4
stack_bottom:
times 0x4000 db 0
stack_top:

section .text
global loader
loader:
    mov esp, stack_top

    extern kmain
    call kmain
    cli
.loop:
    hlt
    jmp .loop


# RUN: llvm-mc -dwarf-version 5 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s
# RUN: not llvm-mc -dwarf-version 4 %s -filetype=asm -o - 2>&1 | FileCheck %s -check-prefix=ERR
# REQUIRES: default_triple
# Darwin line table is stuck on DWARF v2.
# XFAIL: darwin
# Show that ".loc 0" works in DWARF v5, gets an error for earlier versions.
        .file 0 "root.cpp"
        .file 1 "header.h"
	.loc  0 10 0
        nop
        .loc  1 20 0
        nop

# CHECK:      file_names[ 0]:
# CHECK-NEXT: name: "root.cpp"
# CHECK:      file_names[ 1]:
# CHECK-NEXT: name: "header.h"
# CHECK:      Address Line Column File
# CHECK-NEXT: -------
# CHECK-NEXT: 0x{{[0-9a-f]+}} 10 0 0
# CHECK-NEXT: 0x{{[0-9a-f]+}} 20 0 1
# CHECK-NEXT: 0x{{[0-9a-f]+}} 20 0 1 {{.*}} end_sequence

# ERR:      file number less than one in '.loc' directive
# ERR-NEXT: .loc 0 10 0
# ERR-NEXT: ^

Fix test again, try to keep all targets happy

# RUN: llvm-mc -dwarf-version 5 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s
# RUN: not llvm-mc -dwarf-version 4 %s -filetype=asm -o - 2>&1 | FileCheck %s -check-prefix=ERR
# REQUIRES: default_triple
# Darwin line table is stuck on DWARF v2.
# XFAIL: darwin
# Show that ".loc 0" works in DWARF v5, gets an error for earlier versions.
        .file 0 "root.cpp"
        .file 1 "header.h"
	.loc  0 10 0
        .byte 0
        .loc  1 20 0
        .byte 0

# CHECK:      file_names[ 0]:
# CHECK-NEXT: name: "root.cpp"
# CHECK:      file_names[ 1]:
# CHECK-NEXT: name: "header.h"
# CHECK:      Address Line Column File
# CHECK-NEXT: -------
# CHECK-NEXT: 0x{{[0-9a-f]+}} 10 0 0
# CHECK-NEXT: 0x{{[0-9a-f]+}} 20 0 1
# CHECK-NEXT: 0x{{[0-9a-f]+}} 20 0 1 {{.*}} end_sequence

# ERR:      file number less than one in '.loc' directive
# ERR-NEXT: .loc 0 10 0
# ERR-NEXT: ^


# REQUIRES: x86, cpio

# RUN: rm -rf %t.dir
# RUN: mkdir -p %t.dir
# RUN: cd %t.dir

# RUN: not ld.lld --reproduce repro abc -o t 2>&1 | FileCheck %s
# CHECK: cannot open abc: {{N|n}}o such file or directory

# RUN: grep TRAILER repro.cpio
# RUN: cpio -id < repro.cpio
# RUN: FileCheck %s --check-prefix=RSP < repro/response.txt
# RSP: abc
# RSP: -o t

Disable cpio test on Windows again.

# Extracting the cpio archive can get over the path limit on windows.
# REQUIRES: shell

# RUN: rm -rf %t.dir
# RUN: mkdir -p %t.dir
# RUN: cd %t.dir

# RUN: not ld.lld --reproduce repro abc -o t 2>&1 | FileCheck %s
# CHECK: cannot open abc: {{N|n}}o such file or directory

# RUN: grep TRAILER repro.cpio
# RUN: cpio -id < repro.cpio
# RUN: FileCheck --check-prefix=RSP %s < repro/response.txt
# RSP: abc
# RSP: -o t


/* $FreeBSD$ */

#include <machine/asm.h>
#include <alpha/linux/linux_syscall.h>

/*
 * Signal "trampoline" code. Invoked from RTE setup by sendsig().
 *
 * On entry, stack & registers look like:
 *
 *      a0	signal number
 *      a1	pointer to siginfo_t
 *      a2	pointer to signal context frame (scp)
 *      a3	address of handler
 *      sp+0	saved hardware state
 *                      .
 *                      .
 *      scp+0	beginning of signal context frame
 */

/*
 * System call glue.
 */
#define LINUX_SYSCALLNUM(name)                                   \
        ___CONCAT(LINUX_SYS_,name)

#define LINUX_CALLSYS_NOERROR(name)                              \
        ldiq    v0, LINUX_SYSCALLNUM(name);                      \
        call_pal PAL_OSF1_callsys

NESTED(linux_sigcode,0,0,ra,0,0)
	lda	sp, -16(sp)		/* save the sigcontext pointer */
	stq	a2, 0(sp)
	jsr	ra, (t12)		/* call the signal handler (t12==pv) */
	ldq	a0, 0(sp)		/* get the sigcontext pointer */
	lda	sp, 16(sp)
					/* and call sigreturn() with it. */
	LINUX_CALLSYS_NOERROR(osf1_sigreturn)
	mov	v0, a0			/* if that failed, get error code */
	LINUX_CALLSYS_NOERROR(exit)	/* and call exit() with it. */
XNESTED(linux_esigcode,0)
	END(linux_sigcode)

	.data
	EXPORT(linux_szsigcode)
	.quad	linux_esigcode-linux_sigcode
	.text


# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld -hash-style=gnu %t.o -o %t.so -shared
# RUN: llvm-readelf --gnu-hash-table %t.so | FileCheck %s

# CHECK: Num Buckets: 4

.global sym1
sym1:

.global sym2
sym2:

.global sym3
sym3:

.global sym4
sym4:

.global sym5
sym5:

.global sym6
sym6:

.global sym7
sym7:

.global sym8
sym8:

.global sym9
sym9:

.global sym10
sym10:

.global sym11
sym11:

.global sym12
sym12:

.global sym13
sym13:

.global sym14
sym14:

.global sym15
sym15:

.global sym16
sym16:


Add a testcase that would have found the problem in r225048.

; RUN: llvm-mc -triple arm64-apple-darwin10 %s -filetype=obj -o - | llvm-readobj -r --expand-relocs | FileCheck %s

; Test tha we produce an external relocation. There is no apparent need for it, but
; ld64 (241.9) crashes if we don't.

; CHECK:      Relocations [
; CHECK-NEXT:   Section __bar {
; CHECK-NEXT:     Relocation {
; CHECK-NEXT:       Offset: 0x0
; CHECK-NEXT:       PCRel: 0
; CHECK-NEXT:       Length: 3
; CHECK-NEXT:       Extern: 1
; CHECK-NEXT:       Type: ARM64_RELOC_UNSIGNED (0)
; CHECK-NEXT:       Symbol: Lbar
; CHECK-NEXT:       Scattered: 0
; CHECK-NEXT:     }
; CHECK-NEXT:   }
; CHECK-NEXT: ]

        .section        __TEXT,__cstring
Lfoo:
        .asciz  "Hello World!"
Lbar:
        .asciz  "cString"

        .section        __foo,__bar,literal_pointers
        .quad   Lbar


// RUN: not llvm-mc -arch arm -mattr=+v5te \
// RUN: < %s >/dev/null 2> %t
// RUN: grep "error: Rt must be even-numbered" %t | count 7
// RUN: grep "error: Rt can't be R14" %t | count 7
// rdar://14479793

ldrd r1, r2, [pc, #0]
ldrd lr, pc, [pc, #0]
ldrd r1, r2, [r3, #4]
ldrd lr, pc, [r3, #4]
ldrd r1, r2, [r3], #4
ldrd lr, pc, [r3], #4
ldrd r1, r2, [r3, #4]!
ldrd lr, pc, [r3, #4]!
ldrd r1, r2, [r3, -r4]!
ldrd lr, pc, [r3, -r4]!
ldrd r1, r2, [r3, r4]
ldrd lr, pc, [r3, r4]
ldrd r1, r2, [r3], r4
ldrd lr, pc, [r3], r4

Add more negative tests for ARM LDRD.

// RUN: not llvm-mc -arch arm -mattr=+v5te \
// RUN: < %s >/dev/null 2> %t
// RUN: grep "error: Rt must be even-numbered" %t | count 7
// RUN: grep "error: Rt can't be R14" %t | count 7
// RUN: grep "error: destination operands must be sequential" %t | count 7
// rdar://14479793

ldrd r1, r2, [pc, #0]
ldrd lr, pc, [pc, #0]
ldrd r0, r3, [pc, #0]
ldrd r1, r2, [r3, #4]
ldrd lr, pc, [r3, #4]
ldrd r0, r3, [r4, #4]
ldrd r1, r2, [r3], #4
ldrd lr, pc, [r3], #4
ldrd r0, r3, [r4], #4
ldrd r1, r2, [r3, #4]!
ldrd lr, pc, [r3, #4]!
ldrd r0, r3, [r4, #4]!
ldrd r1, r2, [r3, -r4]!
ldrd lr, pc, [r3, -r4]!
ldrd r0, r3, [r4, -r5]!
ldrd r1, r2, [r3, r4]
ldrd lr, pc, [r3, r4]
ldrd r0, r3, [r4, r5]
ldrd r1, r2, [r3], r4
ldrd lr, pc, [r3], r4
ldrd r0, r3, [r4], r5


Add an extra test for archive symbol tables.

# RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
# RUN: rm -f %t
# RUN: llvm-ar rcs %t %t.o
# RUN: llvm-nm -M %t | FileCheck %s

# Test that weak undefined symbols don't show up in the archive symbol
# table.

.global foo
foo:
.weak bar
.quad bar

# CHECK: Archive map
# CHECK-NEXT: foo in archive-symbol-table.s.tmp.o
# CHECK-NOT: in
# CHECK: archive-symbol-table.s.tmp.o
# CHECK-NEXT: w bar
# CHECK-NEXT: T foo


// func haveSSSE3() bool
TEXT ·SSSE3(SB),NOSPLIT,$0
        MOVQ	$1, AX
        CPUID
        SHRQ	$9, CX
        ANDQ	$1, CX
        MOVB	CX, ret+0(FP)
        RET

TEXT ·CpuId(SB),$0-12
        MOVL ax+8(FP), AX
        CPUID
        MOVQ info+0(FP), DI
        MOVL AX, 0(DI)
        MOVL BX, 4(DI)
        MOVL CX, 8(DI)
        MOVL DX, 12(DI)
        RET

Add attribution for Cpuid and SSSE3

// (copied from Nigel Tao's shiny library, https://github.com/golang/exp/blob/master/shiny/driver/internal/swizzle/swizzle_amd64.s)
// func haveSSSE3() bool
TEXT ·SSSE3(SB),NOSPLIT,$0
        MOVQ	$1, AX
        CPUID
        SHRQ	$9, CX
        ANDQ	$1, CX
        MOVB	CX, ret+0(FP)
        RET

// (copied from the Go dist tool, https://github.com/golang/go/blob/master/src/cmd/dist/cpuid_amd64.s)
TEXT ·CpuId(SB),$0-12
        MOVL ax+8(FP), AX
        CPUID
        MOVQ info+0(FP), DI
        MOVL AX, 0(DI)
        MOVL BX, 4(DI)
        MOVL CX, 8(DI)
        MOVL DX, 12(DI)
        RET


.data
.global foo
.type foo, @object
.size foo, 4
foo:
.long 0

.text
.global bar
.type bar, @function
bar:

Make this test a bit less confusing.

.data
.global foo
.type foo, @object
.size foo, 4
foo:
.long 0

.text
.global bar
.type bar, @function
bar:
retq


; Inturrupt Handlers for Elevator Madness DX
.include "game.h"
.include "routines/block.h"
.include "routines/screen.h"

;; Blank Handlers
ROUTINE IrqHandler
	RTI

ROUTINE CopHandler
	RTI

ROUTINE VBlank
	; Save state
	REP #$30
	PHA
	PHB
	PHD
	PHX
	PHY

	SEP #$20
.A8
.I16

	Screen_VBlank
	MetaSprite_VBlank

	LDA	updateBgBufferOnZero
	IF_ZERO
		TransferToVramLocation interactiveBgBuffer, GAME_BG2_MAP, 32*32*2

		; A not Zero
		STA updateBgBufferOnZero
	ENDIF

	; Load State
	REP	#$30
	PLY
	PLX
	PLD
	PLB
	PLA

	RTI

Reset NMI flag on VBlank.

; Inturrupt Handlers for Elevator Madness DX
.include "game.h"
.include "routines/block.h"
.include "routines/screen.h"

;; Blank Handlers
ROUTINE IrqHandler
	RTI

ROUTINE CopHandler
	RTI

ROUTINE VBlank
	; Save state
	REP #$30
	PHA
	PHB
	PHD
	PHX
	PHY

	SEP #$20
.A8
.I16
	; Reset NMI Flag.
	LDA	RDNMI

	Screen_VBlank
	MetaSprite_VBlank

	LDA	updateBgBufferOnZero
	IF_ZERO
		TransferToVramLocation interactiveBgBuffer, GAME_BG2_MAP, 32*32*2

		; A not Zero
		STA updateBgBufferOnZero
	ENDIF

	; Load State
	REP	#$30
	PLY
	PLX
	PLD
	PLB
	PLA

	RTI


# REQUIRES: x86, zlib
# RUN: llvm-mc -filetype=obj -triple i686-linux-gnu -compress-debug-sections=zlib %s -o %t.o
# RUN: llvm-readobj -sections %t.o | FileCheck -check-prefix=OBJ %s
# RUN: not ld.lld %t.o %t.o -o %tout 2>&1 | FileCheck -check-prefix=ERROR %s

# OBJ:      Sections [
# OBJ:        Section {
# OBJ:          Index: 3
# OBJ-NEXT:     Name: .debug_line (16)
# OBJ-NEXT:     Type: SHT_PROGBITS (0x1)
# OBJ-NEXT:     Flags [ (0x800)
# OBJ-NEXT:       SHF_COMPRESSED (0x800)
# OBJ-NEXT:     ]

# ERROR:      error: duplicate symbol: main
# ERROR-NEXT: >>> defined at reduced.c:2 (/tmp/reduced.c:2)
# ERROR-NEXT: >>>
# ERROR-NEXT: >>> defined at reduced.c:2 (/tmp/reduced.c:2)
# ERROR-NEXT: >>>

	.text
	.file	"reduced.c"
	.globl	main
main:
	.file	1 "/tmp" "reduced.c"
	.loc	1 2 0
	xorl	%eax, %eax
	retl
	.file	2 "/tmp/repeat/repeat/repeat/repeat" "repeat.h"

Make test a bit less strict. NFC.

# REQUIRES: x86, zlib
# RUN: llvm-mc -filetype=obj -triple i686-linux-gnu -compress-debug-sections=zlib %s -o %t.o
# RUN: llvm-readobj -sections %t.o | FileCheck -check-prefix=OBJ %s
# RUN: not ld.lld %t.o %t.o -o %tout 2>&1 | FileCheck -check-prefix=ERROR %s

# OBJ:      Sections [
# OBJ:        Section {
# OBJ:          Index:
# OBJ:          Name: .debug_line
# OBJ-NEXT:     Type: SHT_PROGBITS
# OBJ-NEXT:     Flags [
# OBJ-NEXT:       SHF_COMPRESSED
# OBJ-NEXT:     ]

# ERROR:      error: duplicate symbol: main
# ERROR-NEXT: >>> defined at reduced.c:2 (/tmp/reduced.c:2)
# ERROR-NEXT: >>>
# ERROR-NEXT: >>> defined at reduced.c:2 (/tmp/reduced.c:2)
# ERROR-NEXT: >>>

	.text
	.file	"reduced.c"
	.globl	main
main:
	.file	1 "/tmp" "reduced.c"
	.loc	1 2 0
	xorl	%eax, %eax
	retl
	.file	2 "/tmp/repeat/repeat/repeat/repeat" "repeat.h"


Implement register-caching version of VMRG.

//
// arch/x86_64/rsp/vmrg.s
//
// CEN64: Cycle-Accurate Nintendo 64 Simulator.
// Copyright (C) 2014, Tyler J. Stachecki.
//
// This file is subject to the terms and conditions defined in
// 'LICENSE', which is part of this source code package.
//

#
# xmm0 = vs
# xmm1 = vt
# xmm5 = acc_lo
# xmm11 = vcc_lo
# xmm13 = vco_lo
# xmm14 = vco_hi
#

.global RSP_VMRG
.type	RSP_VMRG, @function

RSP_VMRG:

.ifdef __AVX__
  vpblendvb %xmm11, %xmm0, %xmm1, %xmm0
  vpxor %xmm13, %xmm13, %xmm13
  movdqa %xmm0, %xmm5
  vpxor %xmm14, %xmm14, %xmm14
  retq
.else
  movdqa %xmm11, %xmm2
  pand %xmm11, %xmm0
  pandn %xmm1, %xmm2
  pxor %xmm13, %xmm13
  por %xmm2, %xmm0
  pxor %xmm14, %xmm14
  movdqa %xmm0, %xmm5
  retq
.endif

.size RSP_VMRG,.-RSP_VMRG


/// @file
///   CpuPause() function for Itanium-based architecture.
///
/// Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
/// This program and the accompanying materials
/// are licensed and made available under the terms and conditions of the BSD License
/// which accompanies this distribution.  The full text of the license may be found at
/// http://opensource.org/licenses/bsd-license.php
///
/// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
/// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
///
/// Module Name:  CpuPause.s
///
///

.auto
.text

.proc   CpuPause
.type   CpuPause, @function
CpuPause::
        hint                @pause
        br.ret.sptk.many    b0
.endp

Fix ICC 11.1 build break

/// @file
///   CpuPause() function for Itanium-based architecture.
///
/// Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
/// This program and the accompanying materials
/// are licensed and made available under the terms and conditions of the BSD License
/// which accompanies this distribution.  The full text of the license may be found at
/// http://opensource.org/licenses/bsd-license.php
///
/// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
/// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
///
/// Module Name:  CpuPause.s
///
///

.auto
.text

.proc   CpuPause
.type   CpuPause, @function
CpuPause::
        hint.i              @pause
        br.ret.sptk.many    b0
.endp


; MIT License

; Copyright (c) 2017 Blockchain-VCS

; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions:

; The above copyright notice and this permission notice shall be included in all
; copies or substantial portions of the Software.

; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; SOFTWARE.

.data

.code

_DllMainCRTStartup proc
	nop
	ret
_DllMainCRTStartup endp

end


# REQUIRES: x86

# Test that we don't error on undefined versions when static linking.
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -o %t

.global _start
.global bar
.symver _start, bar@@UNDEFINED
_start:

Make the test more strict.

# REQUIRES: x86

# Test that we don't error on undefined versions when static linking.
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -o %t
# RUN: echo "DEFINED { global: *; };" > %t.map
# RUN: ld.lld %t.o --version-script %t.map -o %t

.global _start
.global bar
.symver _start, bar@@UNDEFINED
_start:


# REQUIRES: x86

# Test that we don't error on undefined versions when static linking.
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -o %t

.global _start
.global bar
.symver _start, bar@@UNDEFINED
_start:


# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: echo "SECTIONS { foo = ADDR(.text) - ABSOLUTE(ADDR(.text)); };" > %t.script
# RUN: ld.lld -o %t.so --script %t.script %t.o -shared
# RUN: llvm-readobj --symbols %t.so | FileCheck %s

# Test that the script creates a non absolute symbol with value
# 0 I.E., a symbol that refers to the load address.

# CHECK:      Symbol {
# CHECK:        Name: foo
# CHECK-NEXT:   Value: 0x0
# CHECK-NEXT:   Size: 0
# CHECK-NEXT:   Binding: Global
# CHECK-NEXT:   Type: None
# CHECK-NEXT:   Other: 0
# CHECK-NEXT:   Section: .text
# CHECK-NEXT: }


//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

.section .rodata

.global deserialize_schema_start
.global deserialize_schema_end

deserialize_schema_start:
.incbin ARMNN_SERIALIZER_SCHEMA_PATH
deserialize_schema_end:

Fix build breaks for armnnDeserializer test

//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#if !defined(__MACH__)
.section .rodata
#define EXTERN_ASM
#else
.const_data
#define EXTERN_ASM _
#endif

#define GLUE(a, b) a ## b
#define JOIN(a, b) GLUE(a, b)
#define X(s) JOIN(EXTERN_ASM, s)

.global X(deserialize_schema_start)
.global X(deserialize_schema_end)

X(deserialize_schema_start):
.incbin ARMNN_SERIALIZER_SCHEMA_PATH
X(deserialize_schema_end):


# REQUIRES: x86

# RUN: echo "FBSD_1.2 {};" > %t.ver
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld -shared %t.o -o %t.so --version-script=%t.ver
# RUN: llvm-nm --dynamic %t.so | FileCheck %s

        .weak	openat
openat:
openat@@FBSD_1.2 = openat

# CHECK: 0000000000001000 W openat
# CHECK-NEXT: 0000000000001000 W openat

Make the test more precise.

# REQUIRES: x86

# RUN: echo "FBSD_1.1 {}; FBSD_1.2 {};" > %t.ver
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld -shared %t.o -o %t.so --version-script=%t.ver
# RUN: llvm-readobj --dyn-symbols --elf-output-style=GNU %t.so | FileCheck %s

        .weak	openat
openat:
openat@FBSD_1.1 = openat
openat@@FBSD_1.2 = openat

# CHECK-DAG: openat@FBSD_1.1
# CHECK-DAG: openat@@FBSD_1.2


# REQUIRES: x86
#
# RUN: llvm-dlltool -k -m i386 --input-def %p/Inputs/ordinal-only-implib.def --output-lib %t-implib.a
# RUN: llvm-mc -triple=i386-pc-win32 %s -filetype=obj -o %t.obj
# RUN: lld-link -out:%t.exe -entry:main -subsystem:console -safeseh:no -debug %t.obj %t-implib.a
# RUN: llvm-objdump -private-headers %t.exe | FileCheck --match-full-lines %s

.text
.global _main
_main:
call _ByOrdinalFunction
ret

# CHECK: The Import Tables:
# CHECK:     DLL Name: test.dll
# CHECK-NEXT:     Hint/Ord  Name
# CHECK-NEXT:            1
# CHECK-EMPTY:

Use lld-link instead of llvm-dlltool to create an implib

# REQUIRES: x86
#
# RUN: lld-link -machine:x86 -def:%p/Inputs/ordinal-only-implib.def -implib:%t-implib.a
# RUN: llvm-mc -triple=i386-pc-win32 %s -filetype=obj -o %t.obj
# RUN: lld-link -out:%t.exe -entry:main -subsystem:console -safeseh:no -debug %t.obj %t-implib.a
# RUN: llvm-objdump -private-headers %t.exe | FileCheck --match-full-lines %s

.text
.global _main
_main:
call _ByOrdinalFunction
ret

# CHECK: The Import Tables:
# CHECK:     DLL Name: test.dll
# CHECK-NEXT:     Hint/Ord  Name
# CHECK-NEXT:            1
# CHECK-EMPTY:


// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
// RUN: ld.lld %t -o %t2
// RUN: llvm-readobj -sections %t2 | FileCheck %s
// REQUIRES: x86

// Test that bss takes no space on disk.

// CHECK:        Name: .bss
// CHECK-NEXT:   Type: SHT_NOBITS
// CHECK-NEXT:   Flags [
// CHECK-NEXT:     SHF_ALLOC
// CHECK-NEXT:     SHF_WRITE
// CHECK-NEXT:   ]
// CHECK-NEXT:   Address: 0x201000
// CHECK-NEXT:   Offset: 0x1000
// CHECK-NEXT:   Size: 4
// CHECK-NEXT:   Link: 0
// CHECK-NEXT:   Info: 0
// CHECK-NEXT:   AddressAlignment:
// CHECK-NEXT:   EntrySize: 0
// CHECK-NEXT: }

        .global _start
_start:

        .bss
        .zero 4

Make test test what it should be testing.

// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
// RUN: ld.lld %t -o %t2
// RUN: llvm-readobj -sections %t2 | FileCheck %s
// REQUIRES: x86

// Test that bss takes no space on disk.

// CHECK:        Name: .bss
// CHECK-NEXT:   Type: SHT_NOBITS
// CHECK-NEXT:   Flags [
// CHECK-NEXT:     SHF_ALLOC
// CHECK-NEXT:     SHF_WRITE
// CHECK-NEXT:   ]
// CHECK-NEXT:   Address:
// CHECK-NEXT:   Offset: 0x[[OFFSET:.*]]
// CHECK-NEXT:   Size: 4
// CHECK-NEXT:   Link: 0
// CHECK-NEXT:   Info: 0
// CHECK-NEXT:   AddressAlignment:
// CHECK-NEXT:   EntrySize: 0
// CHECK-NEXT: }
// CHECK-NEXT: Section {
// CHECK-NEXT:   Index:
// CHECK-NEXT:   Name:
// CHECK-NEXT:   Type:
// CHECK-NEXT:   Flags [
// CHECK-NEXT:     SHF_MERGE
// CHECK-NEXT:     SHF_STRINGS
// CHECK-NEXT:   ]
// CHECK-NEXT: Address:
// CHECK-NEXT: Offset: 0x[[OFFSET]]

        .global _start
_start:

        .bss
        .zero 4


Add a test for Win64 EH unwind information emission.

// This test checks that the SEH directives emit the correct unwind data.
// RUN: llvm-mc -triple x86_64-pc-win32 -filetype=obj %s | coff-dump.py | FileCheck %s

// CHECK:      Name                 = .xdata
// CHECK-NEXT: VirtualSize
// CHECK-NEXT: VirtualAddress
// CHECK-NEXT: SizeOfRawData        = 44
// CHECK-NEXT: PointerToRawData
// CHECK-NEXT: PointerToRelocations
// CHECK-NEXT: PointerToLineNumbers
// CHECK-NEXT: NumberOfRelocations  = 4
// CHECK-NEXT: NumberOfLineNumbers  = 0
// CHECK-NEXT: Charateristics
// CHECK-NEXT:   IMAGE_SCN_CNT_INITIALIZED_DATA
// CHECK-NEXT:   IMAGE_SCN_ALIGN_4BYTES
// CHECK-NEXT:   IMAGE_SCN_MEM_READ
// CHECK-NEXT:   IMAGE_SCN_MEM_WRITE
// CHECK-NEXT: SectionData
// CHECK-NEXT:   21 12 08 30 00 30 0F 03 - 0E 88 00 00 09 46 02 00
// CHECK-NEXT:   04 22 00 A1 00 00 00 00 - 00 00 00 00 24 00 00 00
// CHECK-NEXT:   00 00 00 00 1B 00 00 00 - 00 00 00 00

    .text
    .globl func
    .def func; .scl 2; .type 32; .endef
    .seh_proc func
func:
    .seh_pushframe @code
    subq $24, %rsp
    .seh_stackalloc 24
    movq %rsi, 16(%rsp)
    .seh_savereg %rsi, 16
    movups %xmm8, (%rsp)
    .seh_savexmm %xmm8, 0
    pushq %rbx
    .seh_pushreg 3
    mov %rsp, %rbx
    .seh_setframe 3, 0
    .seh_endprologue
    .seh_handler __C_specific_handler, @except
    .seh_handlerdata
    .long 0
    .text
    .seh_startchained
    .seh_endprologue
    .seh_endchained
    lea (%rbx), %rsp
    pop %rbx
    addq $24, %rsp
    ret
    .seh_endproc


#
# Copyright 2011-2015 Jeff Bush
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

					.text
					.globl _start
					.align 4
					.type _start,@function
_start:				getcr s0, 0
					btrue s0, launchOtherThreads

					# Set up stack
					load_32 sp, stack_base
					call main

launchOtherThreads: move s0, 0
					move pc, s0

stack_base:			.long 0x100000

Move stack to 4M so there is more space to load programs.

#
# Copyright 2011-2015 Jeff Bush
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Execution starts here. Set up the stack and call into the serial bootloader.
# When other threads are started (which will be done by the program that was
# loaded, they will start here, but skip execution of the serial bootloader and
# jump directly to address 0, where the new program will dispatch them
# appropriately.

					.text
					.globl _start
					.align 4
					.type _start,@function
_start:				getcr s0, 0
					btrue s0, jump_to_zero

					# Set up stack
					load_32 sp, temp_stack
					call main

jump_to_zero: 		move s0, 0
					move pc, s0

temp_stack:			.long 0x400000


# RUN: llvm-mc -filetype=obj %s -o %t
# RUN: ld.lld -z keep-text-section-prefix %t -o %t2
# RUN: llvm-readelf -l %t2 | FileCheck %s
# RUN: ld.lld %t -o %t3
# RUN: llvm-readelf -l %t3 | FileCheck --check-prefix=CHECKNO %s
# RUN: ld.lld -z nokeep-text-section-prefix %t -o %t4
# RUN: llvm-readelf -l %t4 | FileCheck --check-prefix=CHECKNO %s

# CHECK: .text
# CHECK: .text.hot
# CHECK: .text.startup
# CHECK: .text.exit
# CHECK: .text.unlikely
# CHECKNO: .text
# CHECKNO-NOT: .text.hot

_start:
  ret

.section .text.f,"ax"
f:
  nop

.section .text.hot.f_hot,"ax"
f_hot:
  nop

.section .text.startup.f_startup,"ax"
f_startup:
  nop

.section .text.exit.f_exit,"ax"
f_exit:
  nop

.section .text.unlikely.f_unlikely,"ax"
f_unlikely:
  nop

Fix test by adding -triple=x86_64-unknown-linux

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld -z keep-text-section-prefix %t -o %t2
# RUN: llvm-readelf -l %t2 | FileCheck %s
# RUN: ld.lld %t -o %t3
# RUN: llvm-readelf -l %t3 | FileCheck --check-prefix=CHECKNO %s
# RUN: ld.lld -z nokeep-text-section-prefix %t -o %t4
# RUN: llvm-readelf -l %t4 | FileCheck --check-prefix=CHECKNO %s

# CHECK: .text
# CHECK: .text.hot
# CHECK: .text.startup
# CHECK: .text.exit
# CHECK: .text.unlikely
# CHECKNO: .text
# CHECKNO-NOT: .text.hot

_start:
  ret

.section .text.f,"ax"
f:
  nop

.section .text.hot.f_hot,"ax"
f_hot:
  nop

.section .text.startup.f_startup,"ax"
f_startup:
  nop

.section .text.exit.f_exit,"ax"
f_exit:
  nop

.section .text.unlikely.f_unlikely,"ax"
f_unlikely:
  nop


Add empty .s file to allow `//go:linkname`

// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Empty assembly file so empty func definitions work.


# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t

# RUN: ld.lld -o %t.out %t --oformat binary
# RUN: hexdump -C %t.out | FileCheck %s
# CHECK: 00000000 90 11 22 00 00 00 00 00
# CHECK-NOT: 00000010

## Check case when linkerscript is used.
# RUN: echo "SECTIONS { . = 0x1000; }" > %t.script
# RUN: ld.lld -o %t2.out --script %t.script %t --oformat binary
# RUN: hexdump -C %t2.out | FileCheck %s

# RUN: not ld.lld -o %t3.out %t --oformat foo 2>&1 \
# RUN:   | FileCheck %s --check-prefix ERR
# ERR: unknown --oformat value: foo

.text
.align 4
.globl _start
_start:
 nop

.section        .mysec.1,"ax"
.byte   0x11

.section        .mysec.2,"ax"
.byte   0x22

Use od instead of hexdump.

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t

# RUN: ld.lld -o %t.out %t --oformat binary
# RUN: od -t x1 -v %t.out | FileCheck %s
# CHECK: 000000 90 11 22 00 00 00 00 00
# CHECK-NOT: 00000010

## Check case when linkerscript is used.
# RUN: echo "SECTIONS { . = 0x1000; }" > %t.script
# RUN: ld.lld -o %t2.out --script %t.script %t --oformat binary
# RUN: od -t x1 -v %t2.out | FileCheck %s

# RUN: not ld.lld -o %t3.out %t --oformat foo 2>&1 \
# RUN:   | FileCheck %s --check-prefix ERR
# ERR: unknown --oformat value: foo

.text
.align 4
.globl _start
_start:
 nop

.section        .mysec.1,"ax"
.byte   0x11

.section        .mysec.2,"ax"
.byte   0x22


.text
.type x,@object
.bss
.globl x
.align 4
x:
.long 0
.size x, 4
.type y,@object
.globl y
.align 4
y:
.long 0
.size y, 4

Make this input a bit more readable.

.bss

.type x,@object
.globl x
.align 4
x:
.long 0
.size x, 4

.type y,@object
.globl y
.align 4
y:
.long 0
.size y, 4


.ascii "APS2"
.sleb128 6    // Number of relocations
.sleb128 4096 // Initial offset

.sleb128 2 // Number of relocations in group
.sleb128 8 // RELOCATION_GROUP_HAS_ADDEND_FLAG

.sleb128 256 // Reloc 1: r_offset delta
.sleb128 8   // Reloc 1: r_info R_X86_RELATIVE
.sleb128 0   // Reloc 1: r_addend delta
.sleb128 128 // Reloc 2: r_offset delta
.sleb128 8   // Reloc 2: r_info R_X86_RELATIVE
.sleb128 8   // Reloc 2: r_addend delta

.sleb128 2 // Number of relocations in group
.sleb128 0 // No RELOCATION_GROUP_HAS_ADDEND_FLAG

.sleb128 128           // reloc 1: r_offset delta
.sleb128 (1 << 32) | 1 // r_x86_64_64 (sym index 1)
.sleb128 8             // reloc 2: r_offset delta
.sleb128 (2 << 32) | 1 // r_x86_64_64 (sym index 2)

.sleb128 2 // Number of relocations in group
.sleb128 8 // RELOCATION_GROUP_HAS_ADDEND_FLAG

.sleb128 8             // reloc 1: r_offset delta
.sleb128 (1 << 32) | 1 // r_x86_64_64 (sym index 1)
.sleb128 0             // reloc 1: r_addend delta
.sleb128 8             // reloc 2: r_offset delta
.sleb128 (2 << 32) | 1 // r_x86_64_64 (sym index 2)
.sleb128 8             // reloc 2: r_addend delta


// FIXME: Actually test that we get the expected results.

// RUN: llvm-mc %s > %t

# Immediates
        push $1
        push $(1+2)
        push $a
        push $1 + 2

# Disambiguation
        push 4+4
        push (4+4)
        push (4+4)(%eax)
        push 8(%eax)
        push (%eax)
        push (4+4)(,%eax)

# Indirect Memory Operands
        push 1(%eax)
        push 1(%eax,%ebx)
        push 1(%eax,%ebx,)
        push 1(%eax,%ebx,4)
        push 1(,%ebx)
        push 1(,%ebx,)
        push 1(,%ebx,4)
        push 1(,%ebx,(2+2))

# '*'
        call a
        call *a
        call *%eax
        call 4(%eax) # FIXME: Warn or reject.
        call *4(%eax)


.text
        .globl  bar
bar:
        .cfi_startproc
        leal    (%edi, %edi), %eax
        ret
        .cfi_endproc

        .globl  asm_main
asm_main:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset %rbp, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register %rbp
        movl    $47, %edi

        # install tramp as return address
        # (similar to signal return trampolines on some platforms)
        leaq    tramp, %rax
        pushq   %rax
        jmp     bar # call, with return address pointing to tramp

        popq    %rbp
        .cfi_def_cfa %rsp, 8
        ret
        .cfi_endproc

        .globl  tramp
tramp:
        .cfi_startproc
        .cfi_signal_frame
        # Emit cfi to line up with the frame created by asm_main
        .cfi_def_cfa_offset 16
        .cfi_offset %rbp, -16
        .cfi_def_cfa_register %rbp
        # copy asm_main's epilog to clean up the frame
        popq    %rbp
        .cfi_def_cfa %rsp, 8
        ret
        .cfi_endproc

Use rip-relative addressing in asm test

.text
        .globl  bar
bar:
        .cfi_startproc
        leal    (%edi, %edi), %eax
        ret
        .cfi_endproc

        .globl  asm_main
asm_main:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset %rbp, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register %rbp
        movl    $47, %edi

        # install tramp as return address
        # (similar to signal return trampolines on some platforms)
        leaq    tramp(%rip), %rax
        pushq   %rax
        jmp     bar # call, with return address pointing to tramp

        popq    %rbp
        .cfi_def_cfa %rsp, 8
        ret
        .cfi_endproc

        .globl  tramp
tramp:
        .cfi_startproc
        .cfi_signal_frame
        # Emit cfi to line up with the frame created by asm_main
        .cfi_def_cfa_offset 16
        .cfi_offset %rbp, -16
        .cfi_def_cfa_register %rbp
        # copy asm_main's epilog to clean up the frame
        popq    %rbp
        .cfi_def_cfa %rsp, 8
        ret
        .cfi_endproc


Add test case to check number of redundant entries in the local part of MIPS GOT. NFC.

# Check number of redundant entries in the local part of MIPS GOT.

# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -shared -o %t.so
# RUN: llvm-readobj -mips-plt-got %t.so | FileCheck %s

# REQUIRES: mips

# CHECK:      Local entries [
# CHECK-NEXT:   Entry {
# CHECK-NEXT:     Address: 0x20008
# CHECK-NEXT:     Access: -32744
# CHECK-NEXT:     Initial: 0x30000
#                          ^-- loc1
# CHECK-NEXT:   }
# CHECK-NEXT:   Entry {
# CHECK-NEXT:     Address: 0x2000C
# CHECK-NEXT:     Access: -32740
# CHECK-NEXT:     Initial: 0x40000
#                          ^-- loc2, loc3, loc4
# CHECK-NEXT:   }
# CHECK-NEXT:   Entry {
# CHECK-NEXT:     Address: 0x20010
# CHECK-NEXT:     Access: -32736
# CHECK-NEXT:     Initial: 0x0
# CHECK-NEXT:   }
# CHECK-NEXT:   Entry {
# CHECK-NEXT:     Address: 0x20014
# CHECK-NEXT:     Access: -32732
# CHECK-NEXT:     Initial: 0x0
# CHECK-NEXT:   }
# CHECK-NEXT: ]

  .text
  .globl  foo
foo:
  lw      $t0, %got(loc1)($gp)
  addi    $t0, $t0, %lo(loc1)
  lw      $t0, %got(loc2)($gp)
  addi    $t0, $t0, %lo(loc2)
  lw      $t0, %got(loc3)($gp)
  addi    $t0, $t0, %lo(loc3)
  lw      $t0, %got(loc4)($gp)
  addi    $t0, $t0, %lo(loc4)

  .section .data.1,"aw",%progbits
loc1:
  .space 0x10000
loc2:
  .word 0
loc3:
  .word 0

  .section .data.2,"aw",%progbits
loc4:
  .word 0