/**
 * @file fullbrightF.glsl
 *
 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
 * $/LicenseInfo$
 */

#extension GL_ARB_texture_rectangle : enable

vec3 fullbrightAtmosTransport(vec3 light);
vec3 fullbrightScaleSoftClip(vec3 light);

void main()
{
	float shadow = 1.0;

	vec4 color = diffuseLookup(gl_TexCoord[0].xy)*gl_Color;

	color.rgb = fullbrightAtmosTransport(color.rgb);

	color.rgb = fullbrightScaleSoftClip(color.rgb);

	//gl_FragColor = color;
	gl_FragColor = vec4(1,0,1,1);
}

Fix for accidental checkin of hot pink fullbright.

/**
 * @file fullbrightF.glsl
 *
 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
 * $/LicenseInfo$
 */

#extension GL_ARB_texture_rectangle : enable

vec3 fullbrightAtmosTransport(vec3 light);
vec3 fullbrightScaleSoftClip(vec3 light);

void main()
{
	float shadow = 1.0;

	vec4 color = diffuseLookup(gl_TexCoord[0].xy)*gl_Color;

	color.rgb = fullbrightAtmosTransport(color.rgb);

	color.rgb = fullbrightScaleSoftClip(color.rgb);

	gl_FragColor = color;
}


Shader "Hidden/MRT Blit"
{
    Properties
    {
    }

    CGINCLUDE
    struct Input
    {
        float4 vertex : POSITION;
    };

    struct Varyings
    {
        float4 vertex : SV_POSITION;
        float2 uv : TEXCOORD0;
    };

    struct Output
    {
        float4 first : SV_Target0;
        float4 second : SV_Target1;
    };

    sampler2D _BlitSourceTex;

    Varyings vertex(in Input input)
    {
        Varyings output;

        output.vertex = input.vertex;
        output.uv = .5 * input.vertex.xy + .5;

        return output;
    }

    Output fragment(in Varyings input)
    {
        Output output;

        float4 color = tex2D(_BlitSourceTex, input.uv);

        output.first = color;
        output.second = color;

        return output;
    }
    ENDCG

    SubShader
    {
        Cull Off ZWrite Off ZTest Always

        Pass
        {
            CGPROGRAM
            #pragma vertex vertex
            #pragma fragment fragment
            ENDCG
        }
    }
}

Handle flipped UVs in MRT blit

Shader "Hidden/MRT Blit"
{
    Properties
    {
    }

    CGINCLUDE
    struct Input
    {
        float4 vertex : POSITION;
    };

    struct Varyings
    {
        float4 vertex : SV_POSITION;
        float2 uv : TEXCOORD0;
    };

    struct Output
    {
        float4 first : SV_Target0;
        float4 second : SV_Target1;
    };

    sampler2D _BlitSourceTex;
    float4 _BlitSourceTex_TexelSize;

    Varyings vertex(in Input input)
    {
        Varyings output;

        output.vertex = input.vertex;

        float2 uv = .5 * input.vertex.xy + .5;
        output.uv = uv;

    #if UNITY_UV_STARTS_AT_TOP
        if (_BlitSourceTex_TexelSize.y < 0.)
            output.uv.y = 1. - uv.y;
    #endif

        return output;
    }

    Output fragment(in Varyings input)
    {
        Output output;

        float4 color = tex2D(_BlitSourceTex, input.uv);

        output.first = color;
        output.second = color;

        return output;
    }
    ENDCG

    SubShader
    {
        Cull Off ZWrite Off ZTest Always

        Pass
        {
            CGPROGRAM
            #pragma vertex vertex
            #pragma fragment fragment
            ENDCG
        }
    }
}


#ifdef GL_ES
    precision mediump float;
#endif

uniform sampler2D sDiffuse;
uniform sampler2D sMask;

varying vec2 vColorTexCoord;
varying vec2 vMaskTexCoord;
varying vec4 vColor;

void main(void)
{
	vec4 diffuse = texture2D(sDiffuse, vColorTexCoord);
	vec4 mask = vec4(1.0, 1.0, 1.0, texture2D(sMask, vMaskTexCoord).r);
	gl_FragColor = diffuse * vColor * mask;
}

Fix alpha mask on android

#ifdef GL_ES
    precision mediump float;
#endif

uniform sampler2D sDiffuse;
uniform sampler2D sMask;

varying vec2 vColorTexCoord;
varying vec2 vMaskTexCoord;
varying vec4 vColor;

void main(void)
{
	vec4 diffuse = texture2D(sDiffuse, vColorTexCoord);

	#ifdef PLATFORM_ANDROID
		vec4 mask = vec4(1.0, 1.0, 1.0, texture2D(sMask, vMaskTexCoord).a);
	#else
		vec4 mask = vec4(1.0, 1.0, 1.0, texture2D(sMask, vMaskTexCoord).r);
	#endif

	gl_FragColor = diffuse * vColor * mask;
}


// Common FS routines for evaluating terrain color.

//uniform sampler2DArray t_Height;
// This texture has a layer per terrain type. First row is `lightCLR`, second in `palCLR`.
uniform sampler2DArray t_Table;
// corresponds to SDL palette
uniform sampler1D t_Palette;

const float c_HorFactor = 0.5; //H_CORRECTION

vec4 evaluate_color(uint type, vec3 tex_coord, float height_normalized, float lit_factor) {
    float terrain = float(type) + 0.5;
    float diff =
        textureOffset(t_Height, tex_coord, ivec2(1, 0)).x
        - textureOffset(t_Height, tex_coord, ivec2(-1, 0)).x;
    float light_clr =
        texture(t_Table, vec3(0.5 * diff + 0.5, 0.25, terrain)).x;
    float tmp =
        light_clr - c_HorFactor * (1.0 - height_normalized);
    float color_id =
        texture(t_Table, vec3(0.5 * lit_factor * tmp + 0.5, 0.75, terrain)).x;

    return texture(t_Palette, color_id);
}

Fix color table level selector

// Common FS routines for evaluating terrain color.

//TODO: provide only minimum information to
// reconstruct the lighting model in shader code.

//uniform sampler2DArray t_Height;
// This texture has a layer per terrain type. First row is `lightCLR`, second in `palCLR`.
uniform sampler2DArray t_Table;
// corresponds to SDL palette
uniform sampler1D t_Palette;

const float c_HorFactor = 0.5; //H_CORRECTION

vec4 evaluate_color(uint type, vec3 tex_coord, float height_normalized, float lit_factor) {
    float diff =
        textureOffset(t_Height, tex_coord, ivec2(1, 0)).x
        - textureOffset(t_Height, tex_coord, ivec2(-1, 0)).x;
    float light_clr =
        texture(t_Table, vec3(0.5 * diff + 0.5, 0.25, float(type))).x;
    float tmp =
        light_clr - c_HorFactor * (1.0 - height_normalized);
    float color_id =
        texture(t_Table, vec3(0.5 * lit_factor * tmp + 0.5, 0.75, float(type))).x;

    return texture(t_Palette, color_id);
}


/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

void main(void) {
    float a = texture(sDiffuse, vUv).a;
    oFragColor = vec4(vColor.rgb, vColor.a * a);
}

Add proper transform support for text run shader.

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

void main(void) {
    float a = texture(sDiffuse, vUv).a;
#ifdef WR_FEATURE_TRANSFORM
    float alpha = 0.0;
    init_transform_fs(vLocalPos, vLocalRect, alpha);
    a *= alpha;
#endif
    oFragColor = vec4(vColor.rgb, vColor.a * a);
}


Shader "Custom/Gradient"
{
	Properties {
        _Palette ("Texture", 2D) = "white" { }
    }

    SubShader
    {
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            sampler2D _Palette;

            struct vertInput {
        		float4 pos : POSITION;
				float4 color : COLOR0;
    		};

            struct vertOutput {
                float4 pos : SV_POSITION;
                float4 uv : TEXCOORD0;
                fixed4 color : COLOR0;
            };

            vertOutput vert (vertInput input)
            {
                vertOutput o;
                o.pos = mul(UNITY_MATRIX_MVP, input.pos);
                o.uv = mul(UNITY_MATRIX_MVP, input.pos);
                o.color = input.color;
                return o;
            }

            fixed4 frag (vertOutput output) : SV_Target
            {
                float2 paletteuv = output.color.b + 1.0/32.0;
                float2 screen = output.uv.xy / output.uv.z + float2(1.0, 1.0);
                float gradient = screen.x * output.color.r + screen.y * output.color.g;
                gradient = abs(((gradient*3.0)%2.0) - 1.0);
                return tex2D (_Palette, float2(gradient, paletteuv.y));
            }
            ENDCG
        }
    }
}

Fix gradient material projection issues

Shader "Custom/Gradient"
{
	Properties {
        _Palette ("Texture", 2D) = "white" { }
    }

    SubShader
    {
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            sampler2D _Palette;

            struct vertInput {
        		float4 pos : POSITION;
				float4 color : COLOR0;
    		};

            struct vertOutput {
                float4 pos : SV_POSITION;
                float4 uv : TEXCOORD0;
                fixed4 color : COLOR0;
            };

            vertOutput vert (vertInput input)
            {
                vertOutput o;
                o.pos = mul(UNITY_MATRIX_MVP, input.pos);
                o.uv = mul(UNITY_MATRIX_MV, input.pos);
                o.color = input.color;
                return o;
            }

            fixed4 frag (vertOutput output) : SV_Target
            {
                float2 paletteuv = output.color.b + 1.0/32.0;
                float2 screen = output.uv.xy / output.uv.z + float2(1.0, 1.0);
                float gradient = screen.x * output.color.r + screen.y * output.color.g;
                gradient = abs(((gradient*3.0)%2.0) - 1.0);
                return tex2D (_Palette, float2(gradient, paletteuv.y));
            }
            ENDCG
        }
    }
}


uniform samplerCube tCube;
uniform float tFlip;
uniform float opacity;

varying vec3 vWorldDirection;

void main() {

	gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );
	gl_FragColor.a *= opacity;

}

Support decoding, tonemapping, and output encoding

uniform samplerCube tCube;
uniform float tFlip;
uniform float opacity;

varying vec3 vWorldDirection;

void main() {

	vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );

	gl_FragColor = envMapTexelToLinear( texColor );
	gl_FragColor.a *= opacity;

	#include <tonemapping_fragment>
	#include <encodings_fragment>

}


precision mediump float;

varying vec2 coord;

uniform vec2 verts[%%MAX%%];
uniform vec3 colors[%%MAX%%];
uniform vec2 size;

void main() {
    float dist = 1e20, color = 0.0;
    vec3 color = vec3(1.0, 0.0, 0.0);
    for (int i = 0; i < %%MAX%%; i++) {
        float newdist = distance(verts[i] * size, coord * size);
        if (newdist < dist) {
            color = colors[i];
            dist = newdist;
        }
    }
    gl_FragColor = vec4(color, 1.0);
}

Reduce "infinity" size to work around Radeon bug.

precision mediump float;

varying vec2 coord;

uniform vec2 verts[%%MAX%%];
uniform vec3 colors[%%MAX%%];
uniform vec2 size;

void main() {
    float dist = 1e10;
    vec3 color = vec3(1.0, 0.0, 0.0);
    for (int i = 0; i < %%MAX%%; i++) {
        float newdist = distance(verts[i] * size, coord * size);
        if (newdist < dist) {
            color = colors[i];
            dist = newdist;
        }
    }
    gl_FragColor = vec4(color, 1.0);
}


precision highp float;
in vec2 diffuse_coord;

#ifdef VULKAN
layout (set = 0, binding = 0)
#endif
uniform sampler2D y_texture;

#ifdef VULKAN
layout (set = 0, binding = 1)
#endif
uniform sampler2D uv_texture;

out vec4 fragColor;
void main (void) {
  float r, g, b, y, u, v;
  y = texture(y_texture, v_texCoord).r;
  vec4 texColor = texture(uv_texture,v_texCoord);
  u = texColor.a - 0.5;
  v = texColor.r - 0.5;
  r = y + 1.13983*v;
  g = y - 0.39465*u - 0.58060*v;
  b = y + 2.03211*u;
  fragColor = vec4(r, g, b, 1.0);
}

Adjust bindings: start counting from 4

precision highp float;
in vec2 diffuse_coord;

#ifdef VULKAN
layout (set = 0, binding = 4)
#endif
uniform sampler2D y_texture;

#ifdef VULKAN
layout (set = 0, binding = 5)
#endif
uniform sampler2D uv_texture;

out vec4 fragColor;
void main (void) {
  float r, g, b, y, u, v;
  y = texture(y_texture, v_texCoord).r;
  vec4 texColor = texture(uv_texture,v_texCoord);
  u = texColor.a - 0.5;
  v = texColor.r - 0.5;
  r = y + 1.13983*v;
  g = y - 0.39465*u - 0.58060*v;
  b = y + 2.03211*u;
  fragColor = vec4(r, g, b, 1.0);
}


#version 330 core
layout (std140) uniform Colors {
    vec4 color[256];
};
out vec4 FragColor;

in vec2 TexCoord;

uniform usampler2D ourTexture;
uniform float opacity;

void main()
{
    uint in_label = texture(ourTexture, vec2(TexCoord.x, 1.0 - TexCoord.y)).r;
    FragColor = in_label < uint(256) && in_label > uint(0) ? color[in_label] : vec4(0.0, 0.0, 0.0, 0.0);
    if(in_label > uint(0))
    FragColor.a = opacity;
}

Fix bug segmentation pyramid renderer drawing segmentation incorrectly

#version 330 core
layout (std140) uniform Colors {
    vec4 color[256];
};
out vec4 FragColor;

in vec2 TexCoord;

uniform usampler2D ourTexture;
uniform float opacity;

void main()
{
    uint in_label = texture(ourTexture, vec2(TexCoord.x, TexCoord.y)).r;
    FragColor = in_label < uint(256) && in_label > uint(0) ? color[in_label] : vec4(0.0, 0.0, 0.0, 0.0);
    if(in_label > uint(0))
    FragColor.a = opacity;
}


precision highp float;

// a.xy = resolution
// a.z = time
// a.w = fade
uniform vec4 a;

// b.x = 1
// b.y = kick drum volume
// b.z = t>>19
uniform vec4 b;

void main() {
  // ray marcher temp result
	vec3 e = b.xxx,
  cu = -e + sin(a.z + b.z),

  // ray direction
  rd = (gl_FragCoord.xyz - a.xyz) * a.z / a.x + cu;

  // ray marcher
  for(int f=0; f<9; f++)
    // plasma + sphere
    cu += e = sin(sin(rd*cu) + length(sin(rd*cu)));

  gl_FragColor = vec4(
    // material color
    sin(sin(sin(e.z - a.xyz) * a.z + b.y) / 1e1 + e.z) * a.w,

		1e0
  );
}

Adjust alpha according to hit distance

precision highp float;

// a.xy = resolution
// a.z = time
// a.w = fade
uniform vec4 a;

// b.x = 1
// b.y = kick drum volume
// b.z = t>>19
uniform vec4 b;

void main() {
  // ray marcher temp result
	vec3 e = b.xxx,
  cu = -e + sin(a.z + b.z),

  // ray direction
  rd = (gl_FragCoord.xyz - a.xyz) * a.z / a.x + cu;

  // ray marcher
  for(int f=0; f<9; f++)
    // plasma + sphere
    cu += e = sin(sin(rd*cu) + length(sin(rd*cu)));

  gl_FragColor = vec4(
    // material color
    sin(sin(sin(e.z - a.xyz) * a.z + b.y) / 1e1 + e.z) * a.w,

		.5 / e.z
  );
}


attribute highp vec4 v;
uniform highp mat4 matrix;
uniform highp mat4 rotation;

// w -> apply 3d rotation and projection
uniform lowp vec4 tweak;

varying mediump vec2 pos;

void main()
{
    vec4 p = matrix * v;

    if (tweak.w > 0.0) {
        vec4 proj = rotation * p;
        gl_Position = vec4(proj.x, proj.y, 0, proj.z);
    } else {
        gl_Position = p;
    }

    pos = v.xy * 1.37;
}

Use the correct precision specifier in visualizer GLSL.

attribute highp vec4 v;
uniform highp mat4 matrix;
uniform highp mat4 rotation;

// w -> apply 3d rotation and projection
uniform mediump vec4 tweak;

varying mediump vec2 pos;

void main()
{
    vec4 p = matrix * v;

    if (tweak.w > 0.0) {
        vec4 proj = rotation * p;
        gl_Position = vec4(proj.x, proj.y, 0, proj.z);
    } else {
        gl_Position = p;
    }

    pos = v.xy * 1.37;
}


uniform vec4 ambient_color;
uniform float ambient_intensity;

void main(void)
{
  gl_FragColor = ambient_color * ambient_intensity/2.0;
}

Update shader for tests to make obvious when it works. It's edge-detection shader and should draw borders around edges.

#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

#define PROCESSING_TEXTURE_SHADER

uniform sampler2D texture;
uniform vec2 texOffset;

varying vec4 vertColor;
varying vec4 vertTexCoord;

const vec4 lumcoeff = vec4(0.299, 0.587, 0.114, 0);

void main() {
  vec2 tc0 = vertTexCoord.st + vec2(-texOffset.s, -texOffset.t);
  vec2 tc1 = vertTexCoord.st + vec2(         0.0, -texOffset.t);
  vec2 tc2 = vertTexCoord.st + vec2(+texOffset.s, -texOffset.t);
  vec2 tc3 = vertTexCoord.st + vec2(-texOffset.s,          0.0);
  vec2 tc4 = vertTexCoord.st + vec2(         0.0,          0.0);
  vec2 tc5 = vertTexCoord.st + vec2(+texOffset.s,          0.0);
  vec2 tc6 = vertTexCoord.st + vec2(-texOffset.s, +texOffset.t);
  vec2 tc7 = vertTexCoord.st + vec2(         0.0, +texOffset.t);
  vec2 tc8 = vertTexCoord.st + vec2(+texOffset.s, +texOffset.t);

  vec4 col0 = texture2D(texture, tc0);
  vec4 col1 = texture2D(texture, tc1);
  vec4 col2 = texture2D(texture, tc2);
  vec4 col3 = texture2D(texture, tc3);
  vec4 col4 = texture2D(texture, tc4);
  vec4 col5 = texture2D(texture, tc5);
  vec4 col6 = texture2D(texture, tc6);
  vec4 col7 = texture2D(texture, tc7);
  vec4 col8 = texture2D(texture, tc8);

  vec4 sum = 8.0 * col4 - (col0 + col1 + col2 + col3 + col5 + col6 + col7 + col8);
  gl_FragColor = vec4(sum.rgb, 1.0) * vertColor;
}


PhysicalMaterial material;

#ifdef STANDARD_SG
	material.diffuseColor = diffuseColor.rgb;
	material.specularRoughness = clamp( 1.0 - glossinessFactor, 0.04, 1.0 );
	material.specularColor = specular2Factor.rgb;
#else
	material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
	material.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );
	#ifdef STANDARD
		material.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );
	#else
		material.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );
		material.clearCoat = saturate( clearCoat ); // Burley clearcoat model
		material.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );
	#endif
#endif

Revert "Fix diffuse shader code of Specular-Glossiness"

PhysicalMaterial material;

#ifdef STANDARD_SG
	material.diffuseColor = diffuseColor.rgb * ( 1.0 - max( max( specular2Factor.r, specular2Factor.g ), specular2Factor.b ) );
	material.specularRoughness = clamp( 1.0 - glossinessFactor, 0.04, 1.0 );
	material.specularColor = specular2Factor.rgb;
#else
	material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
	material.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );
	#ifdef STANDARD
		material.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );
	#else
		material.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );
		material.clearCoat = saturate( clearCoat ); // Burley clearcoat model
		material.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );
	#endif
#endif


varying vec3 v_positionEC;
varying vec3 v_normalEC;
varying vec4 v_color;

void main()
{
    vec3 positionToEyeEC = -v_positionEC;

    vec3 normalEC = normalize(v_normalEC);
#ifdef FACE_FORWARD
    normalEC = faceforward(normalEC, vec3(0.0, 0.0, 1.0), -normalEC);
#endif

    czm_materialInput materialInput;
    materialInput.normalEC = normalEC;
    materialInput.positionToEyeEC = positionToEyeEC;
    czm_material material = czm_getDefaultMaterial(materialInput);
    material.diffuse = v_color.rgb;
    material.alpha = v_color.a;

    gl_FragColor = czm_phong(normalize(positionToEyeEC), material);
}

Fix gamma correction for PerInstanceColorAppearance.

varying vec3 v_positionEC;
varying vec3 v_normalEC;
varying vec4 v_color;

void main()
{
    vec3 positionToEyeEC = -v_positionEC;

    vec3 normalEC = normalize(v_normalEC);
#ifdef FACE_FORWARD
    normalEC = faceforward(normalEC, vec3(0.0, 0.0, 1.0), -normalEC);
#endif

    czm_materialInput materialInput;
    materialInput.normalEC = normalEC;
    materialInput.positionToEyeEC = positionToEyeEC;
    czm_material material = czm_getDefaultMaterial(materialInput);
    material.diffuse = czm_gammaCorrect(v_color.rgb);
    material.alpha = v_color.a;

    gl_FragColor = czm_phong(normalize(positionToEyeEC), material);
}


#version 440
#extension GL_NV_gpu_shader5 : enable

coherent uniform
    uint64_t *records;  // all fragment records (<depth|pointer> pairs)
coherent uniform uint32_t *counters;  // auxiliary counters

uniform uint tableElementCount;
uniform uint screenSize;

void main()
{
  // Ignore helper pixels
  if (gl_SampleMaskIn[0] == 0)
    discard;

  uvec2 ij = uvec2(gl_FragCoord.xy);

  // Hashed-lists
  // clear all records
  for (uint o = ij.x + ij.y * screenSize; o < tableElementCount;
       o += screenSize * screenSize)
  {
    records[o] = uint64_t(0);
  }

  // clear max age table (max age = 0)
  counters[ij.x + ij.y * screenSize] = 0u;

  if (ij.x == 0 && ij.y == 0)
  {
    counters[screenSize * screenSize] = uint32_t(0);
  }

  discard;
}

Remove gl_SamleMaskIn useage in clear shader.

#version 440
#extension GL_NV_gpu_shader5 : enable

coherent uniform
    uint64_t *records;  // all fragment records (<depth|pointer> pairs)
coherent uniform uint32_t *counters;  // auxiliary counters

uniform uint tableElementCount;
uniform uint screenSize;

void main()
{
  uvec2 ij = uvec2(gl_FragCoord.xy);

  // Hashed-lists
  // clear all records
  for (uint o = ij.x + ij.y * screenSize; o < tableElementCount;
       o += screenSize * screenSize)
  {
    records[o] = uint64_t(0);
  }

  // clear max age table (max age = 0)
  counters[ij.x + ij.y * screenSize] = 0u;

  if (ij.x == 0 && ij.y == 0)
  {
    counters[screenSize * screenSize] = uint32_t(0);
  }

  discard;
}


// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
// RUN: lld -flavor gnu2 %t -o %t2
// RUN: llvm-objdump -t -d %t2 | FileCheck %s
// REQUIRES: x86

.section       .text,"ax",@progbits,unique,1
.global _start
_start:
  call lulz

.section       .text,"ax",@progbits,unique,2
.zero 4
.global lulz
lulz:

.global bar
.text
bar:
  movl $bar, %edx // R_X86_64_32

// R_X86_64_32
// CHECK: bar:
// CHECK:  11000: ba 00 10 01 00 movl $69632, %edx

// CHECK: e8 04 00 00 00  callq   4

// Also check that symbols match.
// CHECK: 0000000000011000         .text           00000000 bar

Make this test a bit more robust in preparation to adding more cases.

// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
// RUN: lld -flavor gnu2 %t -o %t2
// RUN: llvm-objdump -d %t2 | FileCheck %s
// REQUIRES: x86

.section       .text,"ax",@progbits,unique,1
.global _start
_start:
  call lulz

.section       .text,"ax",@progbits,unique,2
.zero 4
.global lulz
lulz:
  nop

// CHECK: Disassembly of section .text:
// CHECK-NEXT: _start:
// CHECK-NEXT:   11000:  e8 04 00 00 00   callq 4
// CHECK-NEXT:   11005:

// CHECK:      lulz:
// CHECK-NEXT:   11009:  90  nop

.global bar
.section       .text2,"ax",@progbits
bar:
  movl $bar, %edx // R_X86_64_32

// FIXME: this would be far more self evident if llvm-objdump printed
// constants in hex.
// CHECK: Disassembly of section .text2:
// CHECK-NEXT: bar:
// CHECK-NEXT:  12000: {{.*}} movl $73728, %edx


/*
 * Allocates a C string on the stack, for
 * use within system calls, which is the only
 * place the Myrddin stack should need nul-terminated
 * strings.
 *
 * This is in assembly, because for efficiency we
 * allocate the C strings on the stack, and don't adjust
 * %rsp when returning.
 */
.globl std$cstring
.globl _std$cstring
_std$cstring:
std$cstring:
	movq (%rsp),%r15	/* ret addr */
	movq 8(%rsp),%rsi	/* src */
        movq %rsp,%rdi          /* dest */
	movq %rsp,%rax          /* ret val */
	movq 16(%rsp),%rcx	/* len */

	subq %rcx,%rsp          /* get stack */
        subq $1,%rsp            /* nul */
        andq $(~15),%rsp        /* align */

	cld
	rep movsb
        movb $0,(%rdi)          /* terminate */

	pushq %r15              /* ret addr */
	ret

Make sure we don't clobber cstring()'s ret val.

/*
 * Allocates a C string on the stack, for
 * use within system calls, which is the only
 * place the Myrddin stack should need nul-terminated
 * strings.
 *
 * This is in assembly, because for efficiency we
 * allocate the C strings on the stack, and don't adjust
 * %rsp when returning.
 */
.globl std$cstring
.globl _std$cstring
_std$cstring:
std$cstring:
	movq (%rsp),%r15	/* ret addr */
	movq 8(%rsp),%rsi	/* src */
        movq %rsp,%rdi          /* dest */
	movq %rsp,%rax          /* ret val */
	movq 16(%rsp),%rcx	/* len */

        subq $16,%rsp           /* compensate for args */
	subq %rcx,%rsp          /* get stack */
        subq $1,%rsp            /* nul */
        andq $(~15),%rsp        /* align */

	cld
	rep movsb
        movb $0,(%rdi)          /* terminate */

	pushq %r15              /* ret addr */
	ret


/*
 * Allocates a C string on the stack, for
 * use within system calls, which is the only
 * place the Myrddin stack should need nul-terminated
 * strings.
 *
 * This is in assembly, because for efficiency we
 * allocate the C strings on the stack, and don't adjust
 * %rsp when returning.
 */
.globl std$cstring
.globl _std$cstring
_std$cstring:
	movq (%rsp),%r15	/* ret addr */
	movq 8(%rsp),%rsi	/* src */
        movq %rsp,%rdi          /* dest */
	movq %rsp,%rax          /* ret val */
	movq 16(%rsp),%rcx	/* len */

	subq %rcx,%rsp          /* get stack */
        subq $1,%rsp            /* nul */
        andq $(~15),%rsp        /* align */

	cld
	rep movsb
        movb $0,(%rdi)          /* terminate */

	pushq %r15              /* ret addr */
	ret

Add in Linux-style symbol for 'std.cstring'.

/*
 * Allocates a C string on the stack, for
 * use within system calls, which is the only
 * place the Myrddin stack should need nul-terminated
 * strings.
 *
 * This is in assembly, because for efficiency we
 * allocate the C strings on the stack, and don't adjust
 * %rsp when returning.
 */
.globl std$cstring
.globl _std$cstring
_std$cstring:
std$cstring:
	movq (%rsp),%r15	/* ret addr */
	movq 8(%rsp),%rsi	/* src */
        movq %rsp,%rdi          /* dest */
	movq %rsp,%rax          /* ret val */
	movq 16(%rsp),%rcx	/* len */

	subq %rcx,%rsp          /* get stack */
        subq $1,%rsp            /* nul */
        andq $(~15),%rsp        /* align */

	cld
	rep movsb
        movb $0,(%rdi)          /* terminate */

	pushq %r15              /* ret addr */
	ret


// Make sure SystemZ defaults to using the integrated assembler

// RUN: %clang -target s390x-ibm-linux -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=DEFAULT %s
// DEFAULT: "-cc1as"{{.*}} "-target-cpu" "z10"

// RUN: %clang -target s390x-ibm-linux -integrated-as -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=IAS %s
// IAS: "-cc1as"{{.*}} "-target-cpu" "z10"

// RUN: %clang -target s390x-ibm-linux -no-integrated-as -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=NO-IAS %s
// NO-IAS: "-march=z10"

Address review comments for r219679

// Make sure SystemZ defaults to using the integrated assembler

// RUN: %clang -target s390x-ibm-linux -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=IAS %s

// RUN: %clang -target s390x-ibm-linux -integrated-as -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=IAS %s
// IAS: "-cc1as"{{.*}} "-target-cpu" "z10"

// RUN: %clang -target s390x-ibm-linux -no-integrated-as -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=NO-IAS %s
// NO-IAS-NOT: -cc1as
// NO-IAS: "-march=z10"


Add testcase that would crash before the previous revert.

// RUN: llvm-mc < %s -filetype=obj -triple powerpc64le-pc-linux | \
// RUN:   llvm-readobj -t | FileCheck %s

// This used to crash. Make sure it produce the correct symbol.

// CHECK:       Symbol {
// CHECK:         Name: _ZN4llvm11SmallVectorIcLj0EEC2Ev (12)
// CHECK-NEXT:    Value: 0x0
// CHECK-NEXT:    Size: 0
// CHECK-NEXT:    Binding: Local (0x0)
// CHECK-NEXT:    Type: None (0x0)
// CHECK-NEXT:    Other: 64
// CHECK-NEXT:    Section: .group (0x5)
// CHECK-NEXT:  }

	.section	.text._ZN4llvm11SmallVectorIcLj0EEC2Ev,"axG",@progbits,_ZN4llvm11SmallVectorIcLj0EEC2Ev,comdat
.Ltmp2:
	addis 2, 12, .TOC.-.Ltmp2@ha
.Ltmp3:
	.localentry	_ZN4llvm11SmallVectorIcLj0EEC2Ev, .Ltmp3-.Ltmp2


# REQUIRES: x86
# Tests error on archive file without a symbol table
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux -o %t.o %s
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux -o %t.archive.o %S/Inputs/archive.s
# RUN: rm -f %t.a
# RUN: llvm-ar crS %t.a %t.archive.o

# RUN: not ld.lld -o out.wasm %t.o %t.a 2>&1 | FileCheck %s

.globl _start
_start:

# CHECK: error: {{.*}}.a: archive has no index; run ranlib to add one

Use -o /dev/null in test when output is not needed.

# REQUIRES: x86
# Tests error on archive file without a symbol table
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux -o %t.o %s
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux -o /dev/null %S/Inputs/archive.s
# RUN: rm -f %t.a
# RUN: llvm-ar crS %t.a %t.archive.o

# RUN: not ld.lld -o out.wasm %t.o %t.a 2>&1 | FileCheck %s

.globl _start
_start:

# CHECK: error: {{.*}}.a: archive has no index; run ranlib to add one


# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: echo \
# RUN: "SECTIONS { . = 1000; .blah : { PROVIDE(foo = .); } }" \
# RUN:   > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t -shared
# RUN: llvm-objdump -t %t1 | FileCheck %s
# CHECK: 00000000000003e8         *ABS*           00000000 foo

# RUN: echo \
# RUN: "SECTIONS { . = 1000; .blah : { PROVIDE_HIDDEN(foo = .); } }" \
# RUN:   > %t2.script
# RUN: ld.lld -o %t2 --script %t2.script %t -shared
# RUN: llvm-objdump -t %t2 | FileCheck %s --check-prefix=HIDDEN
# HIDDEN: 00000000000003e8         *ABS*           00000000 .hidden foo

.section blah
.globl patatino
patatino:
  movl $foo, %edx

Use correct section name in a test.

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: echo \
# RUN: "SECTIONS { . = 1000; .blah : { PROVIDE(foo = .); } }" \
# RUN:   > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t -shared
# RUN: llvm-objdump -t %t1 | FileCheck %s
# CHECK: 00000000000003e8         *ABS*           00000000 foo

# RUN: echo \
# RUN: "SECTIONS { . = 1000; .blah : { PROVIDE_HIDDEN(foo = .); } }" \
# RUN:   > %t2.script
# RUN: ld.lld -o %t2 --script %t2.script %t -shared
# RUN: llvm-objdump -t %t2 | FileCheck %s --check-prefix=HIDDEN
# HIDDEN: 00000000000003e8         *ABS*           00000000 .hidden foo

.section .blah
.globl patatino
patatino:
  movl $foo, %edx


PUBLIC  main

MAIN_SEG    SEGMENT CODE
            RSEG    MAIN_SEG
main:
            RET
END

Return 0 in ASM main function for KEIL MCS51 toolchain

PUBLIC      main
MAIN_SEG    SEGMENT CODE
            RSEG    MAIN_SEG
main:
            MOV     R6, #0x0
            MOV     R7, #0x0
            RET
            END


bits 64

global _start
extern main
extern exit

section .text
_start:
	xor ebp, ebp
	call main
	mov edi, eax
	call exit

Set up argc and argv before calling main.

bits 64

global _start
extern main
extern exit

section .text
_start:
	xor ebp, ebp
	pop rdi
	mov rsi, rsp
	sub rsp, 8
	call main
	mov edi, eax
	call exit


Add test that was missing in my previous commit.

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

        call bar
bar:

// CHECK: ('sh_name', 1) # '.text'
// CHECK-NEXT: ('sh_type', 1)
// CHECK-NEXT: ('sh_flags', 6)
// CHECK-NEXT: ('sh_addr', 0)
// CHECK-NEXT: ('sh_offset', 64)
// CHECK-NEXT: ('sh_size', 5)
// CHECK-NEXT: ('sh_link', 0)
// CHECK-NEXT: ('sh_info', 0)
// CHECK-NEXT: ('sh_addralign', 4)
// CHECK-NEXT: ('sh_entsize', 0)
// CHECK-NEXT: ('_section_data', 'e8000000 00')
// CHECK-NOT: .rela.text
// CHECK: shstrtab


Use llvm-mc instead of llc in an MC testcase

# RUN: llvm-mc -arch=hexagon -mcpu=hexagonv4 --filetype=obj %s -o - | llvm-readobj -file-headers -elf-output-style=GNU | FileCheck --check-prefix=CHECK-V4 %s
# RUN: llvm-mc -arch=hexagon -mcpu=hexagonv5 --filetype=obj %s -o - | llvm-readobj -file-headers -elf-output-style=GNU | FileCheck --check-prefix=CHECK-V5 %s
# RUN: llvm-mc -arch=hexagon -mcpu=hexagonv55 --filetype=obj %s -o - | llvm-readobj -file-headers -elf-output-style=GNU | FileCheck --check-prefix=CHECK-V55 %s
# RUN: llvm-mc -arch=hexagon -mcpu=hexagonv60 --filetype=obj %s -o - | llvm-readobj -file-headers -elf-output-style=GNU | FileCheck --check-prefix=CHECK-V60 %s

# CHECK-V4: Flags: 0x3
# CHECK-V5: Flags: 0x4
# CHECK-V55: Flags: 0x5
# CHECK-V60: Flags: 0x60


# REQUIRES: x86, shell

# Test that we don't erroneously replace \ with / on UNIX, as it's
# legal for a filename to contain backslashes.
# RUN: llvm-mc %s -o %T/foo\\.o -filetype=obj -triple=x86_64-pc-linux
# RUN: ld.lld %T/foo\\.o --reproduce %T/repro.tar -o /dev/null
# RUN: tar tf %T/repro.tar | FileCheck %s

# CHECK: repro/{{.*}}/foo\\.o

Fix reproduce-blackslash.s test with NetBSD tar

# REQUIRES: x86, shell

# Test that we don't erroneously replace \ with / on UNIX, as it's
# legal for a filename to contain backslashes.
# RUN: llvm-mc %s -o %T/foo\\.o -filetype=obj -triple=x86_64-pc-linux
# RUN: ld.lld %T/foo\\.o --reproduce %T/repro.tar -o /dev/null
# RUN: tar tf %T/repro.tar | FileCheck %s

# CHECK: repro/{{.*}}/foo\{{[\]?}}.o


; RUN: llc -filetype=obj -mtriple mips-unknown-linux %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-BE %s
; RUN: llc -filetype=obj -mtriple mipsel-unknown-linux %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-LE %s

; Check that we produce the correct endian.

; CHECK-BE: ('e_indent[EI_DATA]', 0x02)
; CHECK-LE: ('e_indent[EI_DATA]', 0x01)

Use llvm-mc instead of llc. Patch by Jack Carter.

// RUN: llvm-mc -filetype=obj -triple mips-unknown-linux %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-BE %s
// RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-LE %s

// Check that we produce the correct endian.

// CHECK-BE: ('e_indent[EI_DATA]', 0x02)
// CHECK-LE: ('e_indent[EI_DATA]', 0x01)


TEXT ·Ui8toi16b(SB), 7, $0
	JMP ·ui8toi16b(SB)

TEXT ·Ui8tof32(SB), 7, $0
	JMP ·ui8tof32(SB)

TEXT ·I8tof32(SB), 7, $0
	JMP ·i8tof32(SB)

TEXT ·Ui8toc64(SB), 7, $0
	JMP ·ui8toc64(SB)

TEXT ·F32toi16(SB), 7, $0
	JMP ·f32toi16(SB)

TEXT ·F32toi16ble(SB), 7, $0
	JMP ·f32toi16ble(SB)

Add some missing assembly stubs

TEXT ·Ui8toi16(SB), 7, $0
	JMP ·ui8toi16(SB)

TEXT ·Ui8toi16b(SB), 7, $0
	JMP ·ui8toi16b(SB)

TEXT ·Ui8tof32(SB), 7, $0
	JMP ·ui8tof32(SB)

TEXT ·I8tof32(SB), 7, $0
	JMP ·i8tof32(SB)

TEXT ·Ui8toc64(SB), 7, $0
	JMP ·ui8toc64(SB)

TEXT ·F32toi16(SB), 7, $0
	JMP ·f32toi16(SB)

TEXT ·F32toi16ble(SB), 7, $0
	JMP ·f32toi16ble(SB)

TEXT ·I16bleToF64(SB), 7, $0
	JMP ·i16bleToF64(SB)

TEXT ·I16bleToF32(SB), 7, $0
	JMP ·i16bleToF32(SB)


.globl _std$syscall
_std$syscall:
	pushq %rbp
	/*
	hack: We load 6 args regardless of
	how many we actually have. This may
	load junk values, but if the syscall
	doesn't use them, it's going to be
	harmless.
	 */
	movq 16(%rsp),%rax
	movq 24(%rsp),%rdi
	movq 32(%rsp),%rsi
	movq 40(%rsp),%rdx
	movq 48(%rsp),%r10
	movq 56(%rsp),%r8
	movq 64(%rsp),%r9

	syscall

	popq %rbp
	ret

Return -ERRNO on error returns from syscalls.

.globl _std$syscall
_std$syscall:
	pushq %rbp
	/*
	hack: We load 6 args regardless of
	how many we actually have. This may
	load junk values, but if the syscall
	doesn't use them, it's going to be
	harmless.
	 */
	movq 16(%rsp),%rax
	movq 24(%rsp),%rdi
	movq 32(%rsp),%rsi
	movq 40(%rsp),%rdx
	movq 48(%rsp),%r10
	movq 56(%rsp),%r8
	movq 64(%rsp),%r9

	syscall
	jae success
	negq %rax

success:
	popq %rbp
	ret


@ RUN: llvm-mc -triple thumbv7-linux-gnueabi -o - %s | FileCheck %s

	.syntax unified

	.align 2
	.global pool
	.type pool,%function
pool:
	ldr r0, =0xba5eba11
	bx lr
	.pool

@ CHECK-LABEL: pool
@ CHECK: ldr r0, .Ltmp0
@ CHECK: .align	2
@ CHECK-LABEL: .Ltmp0:
@ CHECK: .long	3126770193

Test commit - Added a new line


// RUN: not llvm-mc -triple i686-unknown-unknown -x86-asm-syntax=att %s -o /dev/null 2>&1 | FileCheck %s

// This tests weird forms of Intel and AT&T syntax that gas accepts that we
// don't.  The [no]prefix operand of the syntax directive indicates whether
// registers need a '%' prefix.

.intel_syntax prefix
// CHECK: error: '.intel_syntax prefix' is not supported: registers must not have a '%' prefix in .intel_syntax
_test2:
	mov	DWORD PTR [%esp - 4], 257
.att_syntax noprefix
// CHECK: error: '.att_syntax noprefix' is not supported: registers must have a '%' prefix in .att_syntax
	movl	$257, -4(esp)


Add a valid test case to check the reason of the recent build-bot failure. NFC

# Check decoding beqz instruction with a negative offset

# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -mattr=micromips %s -o - \
# RUN:   | llvm-objdump -d -mattr=micromips - | FileCheck %s

# CHECK: 0:   8f 7e   beqz16  $6, -4

beqz16  $6, -4


// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o /dev/null \
// RUN: 2>&1 | FileCheck %s

// CHECK: No relocation available to represent this relative expression
// CHECK: call foo - bar

        call foo - bar
        .section .foo
foo:
        .section .bar
bar:

Make this test a bit more strict. NFC.

// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o /dev/null \
// RUN: 2>&1 | FileCheck %s

// CHECK: [[@LINE+2]]:{{[0-9]+}}: error: No relocation available to represent this relative expression
// CHECK-NEXT: call foo - bar
        call foo - bar

        .section .foo
foo:
        .section .bar
bar:


[BITS   16]
[ORG    0x7C00]

boot:
    mov ax, cs
    mov ds, ax
    mov es, ax
    mov ax, 0
    mov ss, ax
    mov sp, 0x7C00 ; stack lives at 0x7C00, grows towards 0x500
reset_drive:
    mov ax, 0
    mov dl, 0
    int 0x13
    jc reset_drive
read_drive:
    mov ax, 0x7E00
    mov es, ax
    mov bx, 0
    mov ah, 2
    mov al, 1
    mov ch, 0
    mov cl, 2
    mov dh, 0
    mov dl, 0
    int 0x13
    jc read_drive

    jmp kmain

times 510-($-$$) db 0
db 0x55
db 0xaa

%include "main.s"

Read kernel into correct segment

[BITS   16]
[ORG    0x7C00]

boot:
    mov ax, cs ; initialize segment registers
    mov ds, ax
    mov es, ax
    mov ax, 0
    mov ss, ax
    mov sp, 0x7C00 ; stack lives at 0x7C00, grows towards 0x500
reset_drive:
    mov ax, 0
    mov dl, 0 ;drive 0
    int 0x13
    jc reset_drive ;if failure, try again
read_drive:
    mov ax, 0x07E0 ; load to immediately after MBR
    mov es, ax
    mov bx, 0

    mov ah, 2 ; load to ES:BX
    mov al, 1 ; load 1 sector
    mov ch, 0 ; cylinder 0
    mov cl, 2 ; sector 2
    mov dh, 0 ; head 0
    mov dl, 0 ; drive 0
    int 0x13
    jc read_drive ; if failure, try again

    jmp kmain

times 510-($-$$) db 0
db 0x55
db 0xaa

%include "main.s"


Document a change of behavior in r315552.

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o
# RUN: ld.lld %t.o -o %t -pie
# RUN: llvm-readelf -r -s %t | FileCheck %s

# Unlike bfd and gold we accept this.

# CHECK: .foobar           PROGBITS        00001000
# CHECK: .got              PROGBITS        [[GOT:[0-9a-z]*]]
# CHECK: [[GOT]]   00000008 R_386_RELATIVE
# CHECK: 00001002  00000008 R_386_RELATIVE
foo:

.section .foobar, "awx"
.global _start
_start:
 movl foo@GOT, %ebx


Add a test that shows that we produce no fixups when computing the difference of two symbols in the same fragment.

// 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 assembler layout and relaxation steps
// CHECK-NEXT: assembler - Number of emitted assembler fragments
// CHECK-NEXT: assembler - Number of emitted object file bytes
// CHECK-NEXT: assembler - Number of fragment layouts
// CHECK-NEXT: mcexpr    - Number of MCExpr evaluations

a:
  nop
b:
  .long b - a


# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t
# RUN: lld -flavor gnu2 %t -o %t2
# RUN: llvm-objdump -d %t2 | FileCheck %s
# REQUIRES: aarch64

.globl _start
_start:
  adr x1,msg
msg:  .asciz  "Hello, world\n"
msgend:

// R_AARCH64_ADR_PREL_LO21
# CHECK: _start:
# CHECK:   11000:       21 00 00 10     adr     x1, #4

Expand test comment a little bit, use reloc name as section name.

# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t
# RUN: lld -flavor gnu2 %t -o %t2
# RUN: llvm-objdump -d %t2 | FileCheck %s
# REQUIRES: aarch64

.section .R_AARCH64_ADR_PREL_LO21,"ax",@progbits
.globl _start
_start:
  adr x1,msg
msg:  .asciz  "Hello, world\n"
msgend:

# CHECK: Disassembly of section .R_AARCH64_ADR_PREL_LO21:
# CHECK: _start:
# CHECK:        0:       21 00 00 10     adr     x1, #4
# CHECK: msg:
# CHECK:        4:
# #4 is the adr immediate value.


.text
.globl UI_Add, UI_Sub
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

UI_Sub:
movq (%rsi), %rax
subq %rax, (%rdi)
0:
leaq 8(%rdi), %rdi
leaq 8(%rsi), %rsi
movq (%rsi), %rax
sbbq %rax, (%rdi)
decq %rdx
jnz 0b
setcb %al
retq

Add asm function of x86_64 'U64_Parse'

#License: Public Domain
#Author: elf
#EMail: elf198012@gmail.com

.text
.globl U64_Parse, UI_Add, UI_Sub

U64_Parse:
movq %rdx, %r8
movq %rcx, %r9
xorq %rax, %rax
xorq %rcx, %rcx
xorb %dl, %dl
movq $10, %rbx
0:
movb (%rdi), %cl
subb $0x30, %cl
js 1f
cmpb $9, %cl
jg 1f
mulq %rbx
setcb %dl
jc 2f
addq %rcx, %rax
setcb %dl
jc 2f
incq %rdi
decq %rsi
jnz 0b
1:
movq %rax, (%r8)
2:
movb %dl, (%r9)
movq %rdi, %rax
ret

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
ret

UI_Sub:
movq (%rsi), %rax
subq %rax, (%rdi)
0:
leaq 8(%rdi), %rdi
leaq 8(%rsi), %rsi
movq (%rsi), %rax
sbbq %rax, (%rdi)
decq %rdx
jnz 0b
setcb %al
ret


/*
 * Allocates a C string on the stack, for
 * use within system calls, which is the only
 * place the Myrddin stack should need nul-terminated
 * strings.
 *
 * This is in assembly, because for efficiency we
 * allocate the C strings on the stack, and don't adjust
 * %rsp when returning.
 */
.globl std$cstring
std$cstring:
	movq (%rsp),%r15	/* ret addr */
	movq 8(%rsp),%rsi	/* src */
        movq %rsp,%rdi          /* dest */
	movq %rsp,%rax          /* ret val */
	movq 16(%rsp),%rcx	/* len */

	subq %rcx,%rsp          /* get stack */
        subq $1,%rsp            /* nul */
        andq $(~15),%rsp        /* align */

	cld
	rep movsb
        movb $0,(%rdi)          /* terminate */

	pushq %r15              /* ret addr */
	ret


// 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]

	mov r1,#1
	lsl r1,#16

turnon$:
	// Set the GPCLR{16} bit
	str r1,[r0,#40]  // #40 --> 0x28

	mov r2,#0x3F0000
wait1$:
	sub r2,#1
	cmp r2,#0
	bne wait1$

turnoff$:
	mov r1,#1
	lsl r1,#16
	// Set the GPSET{16} bit
	str r1,[r0,#28]

	mov r2,#0x3F0000
wait2$:
	sub r2,#1
	cmp r2,#0
	bne wait2$

	b turnon$

Remove duplication of the wait loop.

// 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]

	// 16th pin is our target!
	mov r1,#1
	lsl r1,#16

turnon$:
	// Set the GPCLR{16} bit
	str r1,[r0,#40]  // #40 --> 0x28
	mov r2,#0x3F0000 // initialize counter
	mov r3,#1	 // set flag to ON

wait$:
	sub r2,#1
	cmp r2,#0
	bne wait$

	cmp r3,#1
	bne turnon$

turnoff$:
	// Set the GPSET{16} bit
	str r1,[r0,#28]
	mov r2,#0x3F0000 // initialize counter
	mov r3,#0	 // set flag to off

	b wait$


.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   # 0x08 is the offset to our code segment: Far jump!
flush2:
	ret


// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: llvm-readobj --dyn-symbols %p/Inputs/version-undef-sym.so | FileCheck %s

// Show that the input .so has undefined symbols before bar. That is what would
// get our version parsing out of sync.

// CHECK: Section: Undefined
// CHECK: Section: Undefined
// CHECK: Section: Undefined
// CHECK: Section: Undefined
// CHECK: Section: Undefined
// CHECK: Name: bar

// But now we can successfully find bar.
// RUN: ld.lld %t.o %p/Inputs/version-undef-sym.so -o %t.exe

        .global _start
_start:
        call bar@plt

Document how to recreate a binary.

// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: llvm-readobj --dyn-symbols %p/Inputs/version-undef-sym.so | FileCheck %s

// Inputs/version-undef-sym.so consists of the assembly file
//
//         .global bar
// bar:
//        .weak abc1
//        .weak abc2
//        .weak abc3
//        .weak abc4
//        .weak abc5
//
// linked into a shared library with the version script
//
// VER_1 {
// global:
//   bar;
// };
//
// Assuming we can reproduce the desired property (a few undefined symbols
// before bar) we should create it with lld itself once it supports that.

// Show that the input .so has undefined symbols before bar. That is what would
// get our version parsing out of sync.

// CHECK: Section: Undefined
// CHECK: Section: Undefined
// CHECK: Section: Undefined
// CHECK: Section: Undefined
// CHECK: Section: Undefined
// CHECK: Name: bar

// But now we can successfully find bar.
// RUN: ld.lld %t.o %p/Inputs/version-undef-sym.so -o %t.exe

        .global _start
_start:
        call bar@plt


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

# RUN: echo INCLUDE %t1.script > %t1.script
# RUN: not ld.lld %t.o %t1.script 2>&1 | FileCheck %s

# RUN: echo INCLUDE %t2.script > %t1.script
# RUN: echo INCLUDE %t1.script > %t2.script
# RUN: not ld.lld %t.o %t1.script 2>&1 | FileCheck %s

# CHECK: there is a cycle in linker script INCLUDEs

.globl _start
_start:
  ret

Fix issue with test when build path contains '@'

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

# RUN: echo "INCLUDE \"%t1.script\"" > %t1.script
# RUN: not ld.lld %t.o %t1.script 2>&1 | FileCheck %s

# RUN: echo "INCLUDE \"%t2.script\"" > %t1.script
# RUN: echo "INCLUDE \"%t1.script\"" > %t2.script
# RUN: not ld.lld %t.o %t1.script 2>&1 | FileCheck %s

# CHECK: there is a cycle in linker script INCLUDEs

.globl _start
_start:
  ret


#include "linux_assym.h"			/* system definitions */
#include <machine/asmacros.h>		/* miscellaneous asm macros */

#include <i386/linux/linux_syscall.h>		/* system call numbers */

NON_GPROF_ENTRY(linux_sigcode)
	call	LINUX_SIGF_HANDLER(%esp)
	leal	LINUX_SIGF_SC(%esp),%ebx	/* linux scp */
	movl	LINUX_SC_GS(%ebx),%edx
	movl	%dx,%gs
	push	%eax				/* fake ret addr */
	movl	$LINUX_SYS_linux_sigreturn,%eax	/* linux_sigreturn() */
	int	$0x80				/* enter kernel with args on stack */
	hlt					/* never gets here */

	.align	4				/* long word align */
_linux_esigcode:

	.data
	.globl	_linux_szsigcode
_linux_szsigcode:
	.long	_linux_esigcode-_linux_sigcode

	.text

Use ALIGN_TEXT macro for alignment to avoid ambiguity.

#include "linux_assym.h"			/* system definitions */
#include <machine/asmacros.h>		/* miscellaneous asm macros */

#include <i386/linux/linux_syscall.h>		/* system call numbers */

NON_GPROF_ENTRY(linux_sigcode)
	call	LINUX_SIGF_HANDLER(%esp)
	leal	LINUX_SIGF_SC(%esp),%ebx	/* linux scp */
	movl	LINUX_SC_GS(%ebx),%edx
	movl	%dx,%gs
	push	%eax				/* fake ret addr */
	movl	$LINUX_SYS_linux_sigreturn,%eax	/* linux_sigreturn() */
	int	$0x80				/* enter kernel with args on stack */
	hlt					/* never gets here */
	ALIGN_TEXT
_linux_esigcode:

	.data
	.globl	_linux_szsigcode
_linux_szsigcode:
	.long	_linux_esigcode-_linux_sigcode

	.text


Test case for correct input section order, when sections are listed in linker script

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

# This test case should place input sections in script order:
# .foo.1 .foo.2 .bar.1 .bar.2
# RUN: echo "SECTIONS { . = 0x1000; .foo : {*(.foo.*) *(.bar.*)  } }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -section=.foo -s %t1 | FileCheck --check-prefix=SCRIPT_ORDER %s
# SCRIPT_ORDER: Contents of section .foo:
# SCRIPT_ORDER-NEXT: 1000 00000000 00000000 ffffffff eeeeeeee

# This test case should place input sections in native order:
# .bar.1 .foo.1 .bar.2 .foo.2
# RUN: echo "SECTIONS { . = 0x1000; .foo : {*(.foo.* .bar.*)} }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -section=.foo -s %t1 | FileCheck --check-prefix=FILE_ORDER %s
# FILE_ORDER: Contents of section .foo:
# FILE_ORDER-NEXT: 1000 ffffffff 00000000 eeeeeeee 00000000

.global _start
_start:
 nop

.section .bar.1,"a"
bar1:
 .long 0xFFFFFFFF

.section .foo.1,"a"
foo1:
 .long 0

.section .bar.2,"a"
bar2:
 .long 0xEEEEEEEE

.section .foo.2,"a"
foo2:
 .long 0


Add a test demonstrating DWARF parse failures are not causing lld to exit non-zero

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
# RUN: ld.lld --gdb-index %t1.o -o %t 2>&1 | FileCheck %s

# FIXME: ld.lld should return non-zero (add a "NOT" to start once this bug is fixed)

# CHECK: error: invalid contribution to string offsets table

.section .debug_abbrev,"",@progbits
  .byte  1                           # Abbreviation Code
  .byte  17                          # DW_TAG_compile_unit
  .byte  0                           # DW_CHILDREN_no
  .byte  114                         # DW_AT_str_offsets_base
  .byte  23                          # DW_FORM_sec_offset
  .byte  0                           # EOM(1)
  .byte  0                           # EOM(2)
  .byte  0                           # EOM(3)

.section .debug_info,"",@progbits
  .long  .Lunit_end0-.Lunit_begin0   # Length of Unit
.Lunit_begin0:
  .short 5                           # DWARF version number
  .byte  1                           # DWARF Unit Type
  .byte  8                           # Address Size (in bytes)
  .long  .debug_abbrev               # Offset Into Abbrev. Section

  .byte  1                           # Abbrev [1] 0xc:0x43 DW_TAG_compile_unit
  .long  0                           # DW_AT_str_offsets_base
.Lunit_end0:


// REQUIRES: x86
// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
// RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s
// CHECK: relocation-before-merge-start.s.tmp.o:(.foo): offset is outside the section

.data
.long .foo - 1
.section	.foo,"aM",@progbits,4
.quad 0


@ RUN: not llvm-mc -triple armv7a-linux-gnueabihf %s -filetype=obj -o %s.o 2>&1 | FileCheck %s

@ The relaxations should be applied using the subtarget from the fragment
@ containing the fixup and not the per module subtarget.

        .syntax unified
        .thumb
        @ Place a literal pool out of range of the 16-bit ldr but within
        @ range of the 32-bit ldr.w
        .text
        @ Relaxation to ldr.w as target triple supports Thumb2
        ldr r0,=0x12345678
        .arch armv4t
        @ No relaxation as v4t does not support Thumb
        @ expect out of range error message
        ldr r0,=0x87654321
        .space 1024

@ CHECK: error: out of range pc-relative fixup value
@ CHECK-NEXT: ldr r0,=0x87654321

Fix the test case that places intermediate in source directory.

@ RUN: not llvm-mc -triple armv7a-linux-gnueabihf %s -filetype=obj -o %t.o 2>&1 | FileCheck %s

@ The relaxations should be applied using the subtarget from the fragment
@ containing the fixup and not the per module subtarget.

        .syntax unified
        .thumb
        @ Place a literal pool out of range of the 16-bit ldr but within
        @ range of the 32-bit ldr.w
        .text
        @ Relaxation to ldr.w as target triple supports Thumb2
        ldr r0,=0x12345678
        .arch armv4t
        @ No relaxation as v4t does not support Thumb
        @ expect out of range error message
        ldr r0,=0x87654321
        .space 1024

@ CHECK: error: out of range pc-relative fixup value
@ CHECK-NEXT: ldr r0,=0x87654321


// RUN: not llvm-mc -triple i686-unknown-unknown -x86-asm-syntax=att %s -o /dev/null 2>&1 | FileCheck %s

// This tests weird forms of Intel and AT&T syntax that gas accepts that we
// don't.  The [no]prefix operand of the syntax directive indicates whether
// registers need a '%' prefix.

.intel_syntax prefix
// CHECK: error: '.intel_syntax prefix' is not supported: registers must not have a '%' prefix in .intel_syntax
_test2:
	mov	DWORD PTR [%esp - 4], 257
.att_syntax noprefix
// CHECK: error: '.att_syntax noprefix' is not supported: registers must have a '%' prefix in .att_syntax
	movl	$257, -4(esp)

.intel_syntax noprefix

.global arr
.global i
.set FOO, 2
//CHECK-STDERR: error: cannot use base register with variable reference
mov eax, DWORD PTR arr[ebp + 1 + (2 * 5) - 3 + 1<<1]
//CHECK-STDERR: error: cannot use index register with variable reference
mov eax, DWORD PTR arr[esi*4]
//CHECK-STDERR: error: cannot use more than one symbol in memory operand
mov eax, DWORD PTR arr[i]

Fix some tests that didn't assert anything

// RUN: not llvm-mc -triple i686-unknown-unknown -x86-asm-syntax=att %s -o /dev/null 2>&1 | FileCheck %s

// This tests weird forms of Intel and AT&T syntax that gas accepts that we
// don't.  The [no]prefix operand of the syntax directive indicates whether
// registers need a '%' prefix.

.intel_syntax prefix
// CHECK: error: '.intel_syntax prefix' is not supported: registers must not have a '%' prefix in .intel_syntax
_test2:
	mov	DWORD PTR [%esp - 4], 257
.att_syntax noprefix
// CHECK: error: '.att_syntax noprefix' is not supported: registers must have a '%' prefix in .att_syntax
	movl	$257, -4(esp)

.intel_syntax noprefix

.global arr
.global i
.set FOO, 2
//CHECK: error: cannot use base register with variable reference
mov eax, DWORD PTR arr[ebp + 1 + (2 * 5) - 3 + 1<<1]
//CHECK: error: cannot use index register with variable reference
mov eax, DWORD PTR arr[esi*4]
//CHECK: error: cannot use more than one symbol in memory operand
mov eax, DWORD PTR arr[i]


! RUN: llvm-mc %s -arch=sparc   -show-encoding | FileCheck %s

        ! CHECK: mov 1033, %o1  ! encoding: [0x92,0x10,0x24,0x09]
        mov      (0x400|9), %o1
        ! CHECK: mov 60, %o2    ! encoding: [0x94,0x10,0x20,0x3c]
        mov      (12+3<<2), %o2

! "." is exactly like a temporary symbol equated to the current line.
! RUN: llvm-mc %s -arch=sparc | FileCheck %s --check-prefix=DOTEXPR

        ! DOTEXPR: .Ltmp0
        ! DOTEXPR-NEXT: ba .Ltmp0+8
        b . + 8

Update test to take into account for r251271.

! RUN: llvm-mc %s -arch=sparc   -show-encoding | FileCheck %s

        ! CHECK: mov 1033, %o1  ! encoding: [0x92,0x10,0x24,0x09]
        mov      (0x400|9), %o1
        ! CHECK: mov 60, %o2    ! encoding: [0x94,0x10,0x20,0x3c]
        mov      ((12+3)<<2), %o2

! "." is exactly like a temporary symbol equated to the current line.
! RUN: llvm-mc %s -arch=sparc | FileCheck %s --check-prefix=DOTEXPR

        ! DOTEXPR: .Ltmp0
        ! DOTEXPR-NEXT: ba .Ltmp0+8
        b . + 8


#include "svr4_assym.h"			/* system definitions */
#include <machine/asmacros.h>		/* miscellaneous asm macros */

#include <svr4/svr4_syscall.h>		/* system call numbers */

/* $Id$ */

NON_GPROF_ENTRY(svr4_sigcode)
	call	SVR4_SIGF_HANDLER(%esp)
	leal	SVR4_SIGF_UC(%esp),%eax	# ucp (the call may have clobbered the
					# copy at SIGF_UCP(%esp))
#if defined(NOTYET)
#ifdef VM86
	testl	$PSL_VM,SVR4_UC_EFLAGS(%eax)
	jnz	1f
#endif
#endif
	movl	SVR4_UC_GS(%eax),%edx
	movl	%dx,%gs
1:	pushl	%eax			# fake return address
	pushl	$1			# pointer to ucontext
	movl	$_svr4_sys_context,%eax
	int	$0x80	 		# enter kernel with args on stack
	movl	$exit,%eax
	int	$0x80			# exit if sigreturn fails

	.align	2				/* long word align */
svr4_esigcode:

	.data
	.globl	_svr4_szsigcode
_svr4_szsigcode:
	.long	svr4_esigcode - _svr4_sigcode

	.text

Replace ".align 2" with "ALIGN_TEXT" as per recent discussion re: the linux emulator.

#include "svr4_assym.h"			/* system definitions */
#include <machine/asmacros.h>		/* miscellaneous asm macros */

#include <svr4/svr4_syscall.h>		/* system call numbers */

/* $Id: svr4_locore.s,v 1.6 1999/07/30 12:47:17 newton Exp $ */

NON_GPROF_ENTRY(svr4_sigcode)
	call	SVR4_SIGF_HANDLER(%esp)
	leal	SVR4_SIGF_UC(%esp),%eax	# ucp (the call may have clobbered the
					# copy at SIGF_UCP(%esp))
#if defined(NOTYET)
#ifdef VM86
	testl	$PSL_VM,SVR4_UC_EFLAGS(%eax)
	jnz	1f
#endif
#endif
	movl	SVR4_UC_GS(%eax),%edx
	movl	%dx,%gs
1:	pushl	%eax			# fake return address
	pushl	$1			# pointer to ucontext
	movl	$_svr4_sys_context,%eax
	int	$0x80	 		# enter kernel with args on stack
	movl	$exit,%eax
	int	$0x80			# exit if sigreturn fails

	ALIGN_TEXT
svr4_esigcode:

	.data
	.globl	_svr4_szsigcode
_svr4_szsigcode:
	.long	svr4_esigcode - _svr4_sigcode

	.text


// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
// RUN: echo .global __progname > %t2.s
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %t2.s -o %t2.o
// RUN: ld.lld -shared %t2.o -o %t2.so
// RUN: ld.lld -o %t %t.o %t2.so
// RUN: llvm-readobj -dyn-symbols %t | FileCheck %s

// RUN: ld.lld -o %t %t.o %p/Inputs/progname-ver.so
// RUN: llvm-readobj -dyn-symbols %t | FileCheck %s

// CHECK:      Name:     __progname@
// CHECK-NEXT: Value:    0x11000
// CHECK-NEXT: Size:     0
// CHECK-NEXT: Binding:  Global (0x1)
// CHECK-NEXT: Type:     None (0x0)
// CHECK-NEXT: Other:    0
// CHECK-NEXT: Section:  .text
// CHECK-NEXT: }

.global _start, __progname
_start:
__progname:
  nop

Document how to recreate a binary.

// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
// RUN: echo .global __progname > %t2.s
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %t2.s -o %t2.o
// RUN: ld.lld -shared %t2.o -o %t2.so
// RUN: ld.lld -o %t %t.o %t2.so
// RUN: llvm-readobj -dyn-symbols %t | FileCheck %s

// Inputs/progname-ver.so consists of the assembly file
//
// .global bar
// bar:
// .quad __progname
//
// linked into a library  with the version script
//
// VER_1 {
//  global:
//  bar;
// };
//
// We should create it with lld itself once we it supports that.

// RUN: ld.lld -o %t %t.o %p/Inputs/progname-ver.so
// RUN: llvm-readobj -dyn-symbols %t | FileCheck %s

// CHECK:      Name:     __progname@
// CHECK-NEXT: Value:    0x11000
// CHECK-NEXT: Size:     0
// CHECK-NEXT: Binding:  Global (0x1)
// CHECK-NEXT: Type:     None (0x0)
// CHECK-NEXT: Other:    0
// CHECK-NEXT: Section:  .text
// CHECK-NEXT: }

.global _start, __progname
_start:
__progname:
  nop


[BITS   16]
[ORG    0x7C00]

boot:
    mov ax, 0
    mov ds, ax
    mov es, ax
    mov ss, ax
    mov sp, 0x7C00 ; stack lives at 0x1500, grows towards 0x500
    jmp kmain

times 510-($-$$) db 0
db 0x55
db 0xaa

%include "main.s"

Add initial implementation of reading from drive

[BITS   16]
[ORG    0x7C00]

boot:
    mov ax, cs
    mov ds, ax
    mov es, ax
    mov ax, 0
    mov ss, ax
    mov sp, 0x7C00 ; stack lives at 0x7C00, grows towards 0x500
reset_drive:
    mov ax, 0
    mov dl, 0
    int 0x13
    jc reset_drive
read_drive:
    mov ax, 0x7E00
    mov es, ax
    mov bx, 0
    mov ah, 2
    mov al, 1
    mov ch, 0
    mov cl, 2
    mov dh, 0
    mov dl, 0
    int 0x13
    jc read_drive

    jmp kmain

times 510-($-$$) db 0
db 0x55
db 0xaa

%include "main.s"


// RUN: llvm-mc -triple i386-unknown-unknown %s -o -

	.text
	.align	4,0x90
	.globl	_main
_main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	call	"L1$pb"
"L1$pb":
	popl	%eax
	movl	$0, -4(%ebp)
	movl	%esp, %ecx
	leal	L_.str-"L1$pb"(%eax), %eax
	movl	%eax, (%ecx)
	call	_printf
	movl	$0, -4(%ebp)
	movl	-4(%ebp), %eax
	addl	$8, %esp
	popl	%ebp
	ret
	.subsections_via_symbols
	.cstring
L_.str:
	.asciz	"hello world!\n"

Disable this test for now, we don't check for super classes when matching yet.

// RUN: llvm-mc -triple i386-unknown-unknown %s -o -
// XFAIL: *

	.text
	.align	4,0x90
	.globl	_main
_main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	call	"L1$pb"
"L1$pb":
	popl	%eax
	movl	$0, -4(%ebp)
	movl	%esp, %ecx
	leal	L_.str-"L1$pb"(%eax), %eax
	movl	%eax, (%ecx)
	call	_printf
	movl	$0, -4(%ebp)
	movl	-4(%ebp), %eax
	addl	$8, %esp
	popl	%ebp
	ret
	.subsections_via_symbols
	.cstring
L_.str:
	.asciz	"hello world!\n"


// RUN: llvm-ar rc %t.a
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: ld.lld2 -shared %t.o %t.a -o t


Add test case to check calculation of GOT pages in case of using a linker script. NFC

# Check calculation of MIPS GOT page address entries number
# when a linker script is provided.

# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux -o %t.o %s
# RUN: echo "SECTIONS { \
# RUN:          .text : { *(.text) } \
# RUN:          .data 0x10000 : { *(.data) } }" > %t.script
# RUN: ld.lld -shared --script %t.script -o %t.so %t.o
# RUN: llvm-readobj -t -mips-plt-got %t.so | FileCheck %s

# REQUIRES: mips

# CHECK:      Name: foo1
# CHECK-NEXT: Value: 0x10000
# CHECK:      Name: foo2
# CHECK-NEXT: Value: 0x20000
# CHECK:      Name: foo3
# CHECK-NEXT: Value: 0x30000
# CHECK:      Name: foo4
# CHECK-NEXT: Value: 0x40000

# CHECK:      Local entries [
# CHECK-BEXT:    Entry {
# CHECK-BEXT:      Address:
# CHECK-BEXT:      Access:
# CHECK-BEXT:      Initial: 0x10000
# CHECK-BEXT:    }
# CHECK-BEXT:    Entry {
# CHECK-BEXT:      Address:
# CHECK-BEXT:      Access:
# CHECK-BEXT:      Initial: 0x20000
# CHECK-BEXT:    }
# CHECK-BEXT:    Entry {
# CHECK-BEXT:      Address:
# CHECK-BEXT:      Access:
# CHECK-BEXT:      Initial: 0x30000
# CHECK-BEXT:    }
# CHECK-BEXT:    Entry {
# CHECK-BEXT:      Address:
# CHECK-BEXT:      Access:
# CHECK-BEXT:      Initial: 0x40000
# CHECK-BEXT:    }
# CHECK-BEXT:    Entry {
# CHECK-BEXT:      Address:
# CHECK-BEXT:      Access:
# CHECK-BEXT:      Initial: 0x50000
# CHECK-BEXT:    }
# CHECK-BEXT:  ]

  .option pic2
  .text
  ld      $v0,%got_page(foo1)($gp)
  ld      $v0,%got_page(foo2)($gp)
  ld      $v0,%got_page(foo3)($gp)
  ld      $v0,%got_page(foo4)($gp)

  .data
foo1:
  .space 0x10000
foo2:
  .space 0x10000
foo3:
  .space 0x10000
foo4:
  .word 0


// RUN: not llvm-mc %s -o %t.o -filetype=obj 2>&1 | FileCheck %s

        .quad foo@gotpcrel
// CHECK:      32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@gotpcrel

        .quad foo@plt
// CHECK:      32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@plt

        .quad foo@tlsld
// CHECK:      32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@tlsld

        .quad foo@gottpoff
// CHECK:      32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@gottpoff

        .quad foo@tlsgd
// CHECK:      32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@tlsgd

Add a triple to the test.

// RUN: not llvm-mc -triple x86_64-pc-linux %s -o %t.o -filetype=obj 2>&1 | FileCheck %s

        .quad foo@gotpcrel
// CHECK:      32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@gotpcrel

        .quad foo@plt
// CHECK:      32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@plt

        .quad foo@tlsld
// CHECK:      32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@tlsld

        .quad foo@gottpoff
// CHECK:      32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@gottpoff

        .quad foo@tlsgd
// CHECK:      32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@tlsgd


Add OTBN app file to run RSA-3072 verification operations.

/* Copyright lowRISC contributors. */
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */
/* SPDX-License-Identifier: Apache-2.0 */

.section .text.start

/**
 * OTBN app to run RSA-3072 verification and constant precomputation.
 */
run_rsa_3072:
  la    x2, mode
  lw    x2, 0(x2)

  li    x3, 1
  beq   x2, x3, precomp

  li    x3, 2
  beq   x2, x3, verify

  /* Mode is neither 1 (= precomp) nor 2 (= verify). Fail. */
  unimp

.text

/**
 * Precomputation of Montgomery constants R^2 and m0_inv.
 *
 * Expects the modulus (in_mod) to be pre-populated. Results will be stored in
 * in_rr and in_m0_inv.
 */
precomp:
  /* TODO: not yet implemented */
  unimp

/**
 * RSA-3072 signature verification.
 *
 * Expects the RSA signature (in_buf), constants (in_rr, in_m0inv) and modulus
 * (in_mod) to be pre-populated. Recovered message will be stored in out_buf.
 */
verify:
  /* run modular exponentiation */
  jal      x1, modexp_var_3072_f4

  ecall

.data

/* Operation mode (1 = precomp; 2 = verify) */
.globl mode
.balign 4
mode:
  .zero 4


// REQUIRES: x86

// This file contains two functions. They are themselves identical,
// but because they have reloactions against different data section,
// they are not mergeable.

// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
// RUN:    %p/Inputs/icf-non-mergeable.s -o %t2

// RUN: ld.lld %t1 %t2 -o %t3 --icf=all --verbose | FileCheck %s

// CHECK-NOT: selected .text.f1
// CHECK-NOT:   removed .text.f2

.globl _start, f1, f2, d1, d2
_start:
  ret

.section .text.f1, "ax"
f1:
  movl $5, d1
  ret

.section .text.f2, "ax"
f2:
  movl $5, d2
  ret

Fix a couple of typos in a test.

// REQUIRES: x86

// This file contains two functions. They are themselves identical,
// but because they have relocations against different data sections,
// they are not mergeable.

// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
// RUN:    %p/Inputs/icf-non-mergeable.s -o %t2

// RUN: ld.lld %t1 %t2 -o %t3 --icf=all --verbose | FileCheck %s

// CHECK-NOT: selected .text.f1
// CHECK-NOT:   removed .text.f2

.globl _start, f1, f2, d1, d2
_start:
  ret

.section .text.f1, "ax"
f1:
  movl $5, d1
  ret

.section .text.f2, "ax"
f2:
  movl $5, d2
  ret


////////////////////////////////////////////////////////////////////////////////////////////////
///
/// @file
/// @author     Kuba Sejdak
/// @date       16.07.2016
///
/// @copyright  This file is a part of cosmos OS. All rights reserved.
///
////////////////////////////////////////////////////////////////////////////////////////////////

    .section    .boot, "ax"
    .global     _start
    .func       _start

_start:
    // Initialize stack pointer.
    ldr     sp, =_stackStart_pa

    // Initialize registers for clearing .bss section.
    mov     r0, #0
    ldr     r1, =_bssStart_pa
    ldr     r2, =_bssEnd_pa

bssClear:
    cmp     r1, r2
    strlo   r0, [r1], #4
    blo     bssClear

    blx     mmu_init

    ldr     lr, =main
    bx      lr

    .endfunc

Add missing symbols for newlib.

////////////////////////////////////////////////////////////////////////////////////////////////
///
/// @file
/// @author     Kuba Sejdak
/// @date       16.07.2016
///
/// @copyright  This file is a part of cosmos OS. All rights reserved.
///
////////////////////////////////////////////////////////////////////////////////////////////////

    .section    .data
    .global     __dso_handle

__dso_handle:   .word   0

    .section    .text
    .global     _fini
    .func       _fini

_fini:
    bx      lr

    .endfunc

    .section    .boot, "ax"
    .global     _start
    .func       _start

_start:
    // Initialize stack pointer.
    ldr     sp, =_stackStart_pa

    // Initialize registers for clearing .bss section.
    mov     r0, #0
    ldr     r1, =_bssStart_pa
    ldr     r2, =_bssEnd_pa

bssClear:
    cmp     r1, r2
    strlo   r0, [r1], #4
    blo     bssClear

    blx     mmu_init

    ldr     lr, =main
    bx      lr

    .endfunc


/*
 * Allocates a C string on the stack, for
 * use within system calls, which is the only
 * place the Myrddin stack should need nul-terminated
 * strings.
 *
 * This is in assembly, because for efficiency we
 * allocate the C strings on the stack, and don't adjust
 * %rsp when returning.
 */
.globl std$cstring
.globl _std$cstring
_std$cstring:
std$cstring:
	movq (%rsp),%r15	/* ret addr */
	movq 8(%rsp),%rsi	/* src */
        movq %rsp,%rdi          /* dest */
	movq %rsp,%rax          /* ret val */
	movq 16(%rsp),%rcx	/* len */

	subq %rcx,%rsp          /* get stack */
        subq $1,%rsp            /* nul */
        andq $(~15),%rsp        /* align */

	cld
	rep movsb
        movb $0,(%rdi)          /* terminate */

	pushq %r15              /* ret addr */
	ret

Fix mixed tabs and spaces.

/*
 * Allocates a C string on the stack, for
 * use within system calls, which is the only
 * place the Myrddin stack should need nul-terminated
 * strings.
 *
 * This is in assembly, because for efficiency we
 * allocate the C strings on the stack, and don't adjust
 * %rsp when returning.
 */
.globl std$cstring
.globl _std$cstring
_std$cstring:
std$cstring:
	movq (%rsp),%r15	/* ret addr */
	movq 8(%rsp),%rsi	/* src */
	movq %rsp,%rdi          /* dest */
	movq %rsp,%rax          /* ret val */
	movq 16(%rsp),%rcx	/* len */

	subq $16,%rsp		/* "unpop" the args */
	subq %rcx,%rsp          /* get stack */
	subq $1,%rsp            /* nul */
	andq $(~15),%rsp        /* align */

	cld
	rep movsb
	movb $0,(%rdi)          /* terminate */

	pushq %r15              /* ret addr */
	ret


# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -o - > %t1
# RUN: llvm-objdump -d %t1 | FileCheck %s

# CHECK: 0000000000201000 _start:
# CHECK: 201000: 90 nop

# RUN: ld.lld %t.o -o %t2
# RUN: diff %t1 %t2

.globl _start
_start:
  nop

Disable test added in r351916.

# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -o - > %t1
# RUN: llvm-objdump -d %t1 | FileCheck %s

# CHECK: 0000000000201000 _start:
# CHECK: 201000: 90 nop

# RUN: ld.lld %t.o -o %t2

# FIXME: Add "RUN:" in front of this line once the test passes on Windows
# with it.
# diff %t1 %t2

.globl _start
_start:
  nop


Test DWARFv5 with gdb-index and low_pc/high_pc on the CU (rather than ranges)

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld --gdb-index %t.o -o %t
# RUN: llvm-dwarfdump -gdb-index %t | FileCheck %s

# CHECK:       Address area offset = 0x28, has 1 entries:
# CHECK-NEXT:    Low/High address = [0x201000, 0x201001) (Size: 0x1), CU id = 0

	.text
	.globl main
main:                                   # @main
.Lfunc_begin0:
	retq
.Lfunc_end0:
	.section	.debug_abbrev,"",@progbits
	.byte	1                       # Abbreviation Code
	.byte	17                      # DW_TAG_compile_unit
	.byte	0                       # DW_CHILDREN_no
	.byte	115                     # DW_AT_addr_base
	.byte	23                      # DW_FORM_sec_offset
	.byte	17                      # DW_AT_low_pc
	.byte	27                      # DW_FORM_addrx
	.byte	18                      # DW_AT_high_pc
	.byte	6                       # DW_FORM_data4
	.byte	0                       # EOM(1)
	.byte	0                       # EOM(2)
	.byte	0                       # EOM(3)
	.section	.debug_info,"",@progbits
.Lcu_begin0:
	.long	.Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
.Ldebug_info_start0:
	.short	5                       # DWARF version number
	.byte	1                       # DWARF Unit Type
	.byte	8                       # Address Size (in bytes)
	.long	.debug_abbrev           # Offset Into Abbrev. Section
	.byte	1                       # Abbrev [1] 0xc:0x2b DW_TAG_compile_unit
	.long	.Laddr_table_base0      # DW_AT_addr_base
	.byte	0                       # DW_AT_low_pc
	.long	.Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
.Ldebug_info_end0:
	.section	.debug_macinfo,"",@progbits
	.byte	0                       # End Of Macro List Mark
	.section	.debug_addr,"",@progbits
	.long	12
	.short	5
	.byte	8
	.byte	0
.Laddr_table_base0:
	.quad	.Lfunc_begin0


# 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+}}0 10 0 0
# CHECK-NEXT: 0x{{0+}}1 20 0 1
# CHECK-NEXT: 0x{{0+}}2 20 0 1 {{.*}} end_sequence

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

Fix test, nop is not always 1 byte

# 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: ^


Add a testcase for symbol resolution with -r.

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

.weak foo
foo:
.quad foo

// CHECK:      Relocations [
// CHECK-NEXT:   Section ({{.*}}) .rela.text {
// CHECK-NEXT:     0x0 R_X86_64_64 foo 0x0
// CHECK-NEXT:     0x8 R_X86_64_64 foo 0x0
// CHECK-NEXT:   }
// CHECK-NEXT: ]


# RUN: llvm-mc -triple i386-pc-linux-gnu %s | FileCheck %s

a:
	ret
.Lt:
# CHECK: .size	a, .Lt-a
	.size	a, .Lt-a


// RUN: llvm-mc -filetype=obj -triple arm64_be %s | llvm-readobj -section-data -sections | FileCheck %s

// CHECK: 0000: 00123456 789ABCDE
foo:    .xword 0x123456789abcde


# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
# RUN: not ld.lld %t1 -o %t2
# RUN: ld.lld %t1 -o %t2 -e entry

# RUN: ld.lld %t1 -o %t2 -e 4096
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=DEC %s
# RUN: ld.lld %t1 -o %t2 -e 0xcafe
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=HEX %s
# RUN: ld.lld %t1 -o %t2 -e 0777
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=OCT %s

# DEC: Entry: 0x1000
# HEX: Entry: 0xCAFE
# OCT: Entry: 0x1FF

.globl entry
entry:

Test that -e <symbol> works

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
# RUN: not ld.lld %t1 -o %t2
# RUN: ld.lld %t1 -o %t2 -e entry
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=SYM %s
# RUN: ld.lld %t1 -o %t2 -e 4096
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=DEC %s
# RUN: ld.lld %t1 -o %t2 -e 0xcafe
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=HEX %s
# RUN: ld.lld %t1 -o %t2 -e 0777
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=OCT %s

# SYM: Entry: 0x11000
# DEC: Entry: 0x1000
# HEX: Entry: 0xCAFE
# OCT: Entry: 0x1FF

.globl entry
entry:


# MIPS BFD linker puts _gp_disp symbol into DSO files and assigns zero
# version definition index to it. This value means 'unversioned local symbol'
# while _gp_disp is a section global symbol. We have to handle this bug
# in the LLD because BFD linker is used for building MIPS toolchain
# libraries. This test checks such handling.

# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o %S/Inputs/mips-gp-dips-corrupt-ver.so

  .global __start
  .text
__start:
  lw     $t0, %got(foo)($gp)

Mark the test as required MIPS target support. NFC

# MIPS BFD linker puts _gp_disp symbol into DSO files and assigns zero
# version definition index to it. This value means 'unversioned local symbol'
# while _gp_disp is a section global symbol. We have to handle this bug
# in the LLD because BFD linker is used for building MIPS toolchain
# libraries. This test checks such handling.

# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o %S/Inputs/mips-gp-dips-corrupt-ver.so

# REQUIRES: mips

  .global __start
  .text
__start:
  lw     $t0, %got(foo)($gp)


Add RDSEED instruction resource tests for GLM

# NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py
# RUN: llvm-mca -mtriple=x86_64-unknown-unknown -mcpu=goldmont -instruction-tables < %s | FileCheck %s

rdseed   %ax
rdseed   %eax
rdseed   %rax

# 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 (U)

# CHECK:      [1]    [2]    [3]    [4]    [5]    [6]    Instructions:
# CHECK-NEXT:  1      100   1.00                  U     rdseedw	%ax
# CHECK-NEXT:  1      100   1.00                  U     rdseedl	%eax
# CHECK-NEXT:  1      100   1.00                  U     rdseedq	%rax

# CHECK:      Resources:
# CHECK-NEXT: [0]   - SLMDivider
# CHECK-NEXT: [1]   - SLMFPDivider
# CHECK-NEXT: [2]   - SLMFPMultiplier
# CHECK-NEXT: [3]   - SLM_FPC_RSV0
# CHECK-NEXT: [4]   - SLM_FPC_RSV1
# CHECK-NEXT: [5]   - SLM_IEC_RSV0
# CHECK-NEXT: [6]   - SLM_IEC_RSV1
# CHECK-NEXT: [7]   - SLM_MEC_RSV

# CHECK:      Resource pressure per iteration:
# CHECK-NEXT: [0]    [1]    [2]    [3]    [4]    [5]    [6]    [7]
# CHECK-NEXT:  -      -      -     3.00    -      -      -      -

# CHECK:      Resource pressure by instruction:
# CHECK-NEXT: [0]    [1]    [2]    [3]    [4]    [5]    [6]    [7]    Instructions:
# CHECK-NEXT:  -      -      -     1.00    -      -      -      -     rdseedw	%ax
# CHECK-NEXT:  -      -      -     1.00    -      -      -      -     rdseedl	%eax
# CHECK-NEXT:  -      -      -     1.00    -      -      -      -     rdseedq	%rax


Include test for out of range LD_PREL_LO19.

# REQUIRES: aarch64

# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-none %s -o %t.o
# RUN: not ld.lld -shared %t.o -o %t 2>&1 | FileCheck %s

# CHECK: relocation R_AARCH64_LD_PREL_LO19 out of range

  ldr x8, patatino
  .data
  .zero 2000000
patatino:


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

// Test that this produces the correct relaxed relocations.

        movl	foo@GOT, %eax
        movl	foo@GOTPCREL(%rip), %eax
        movq  foo@GOTPCREL(%rip), %rax

// CHECK:      Relocations [
// CHECK:        Section ({{[^ ]+}}) .rela.text {
// CHECK-NEXT:       0x{{[^ ]+}} R_X86_64_GOT32 foo 0x{{[^ ]+}}
// CHECK-NEXT:       0x{{[^ ]+}} R_X86_64_GOTPCRELX foo 0x{{[^ ]+}}
// CHECK-NEXT:       0x{{[^ ]+}} R_X86_64_REX_GOTPCRELX foo 0x{{[^ ]+}}
// CHECK-NEXT:   }
// CHECK-NEXT: ]

// CHECK:        Symbols [
// CHECK-NOT:          _GLOBAL_OFFSET_TABLE_

Make the relaxation test more interesting.

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

// Test that this produces the correct relaxed relocations.

        movl	foo@GOT, %eax
        movl	foo@GOTPCREL(%rip), %eax
        movq  foo@GOTPCREL(%rip), %rax
        .long zed@GOTPCREL

// CHECK:      Relocations [
// CHECK:        Section ({{[^ ]+}}) .rela.text {
// CHECK-NEXT:       0x{{[^ ]+}} R_X86_64_GOT32 foo 0x{{[^ ]+}}
// CHECK-NEXT:       0x{{[^ ]+}} R_X86_64_GOTPCRELX foo 0x{{[^ ]+}}
// CHECK-NEXT:       0x{{[^ ]+}} R_X86_64_REX_GOTPCRELX foo 0x{{[^ ]+}}
// CHECK-NEXT:       0x{{[^ ]+}} R_X86_64_GOTPCREL zed 0x{{[^ ]+}}
// CHECK-NEXT:   }
// CHECK-NEXT: ]

// CHECK:        Symbols [
// CHECK-NOT:          _GLOBAL_OFFSET_TABLE_


# RUN: llvm-mc -triple=x86_64-unknown-freebsd -code-model=small -relocation-model=pic -filetype=obj -o %T/testsmall_x86-64.o %s
# RUN: llvm-rtdyld -triple=x86_64-unknown-freebsd -verify -check=%s %/T/testsmall_x86-64.o

	.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


.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


Add a test that would have found the issue in r224935.

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

; This is a regression test making sure we don't crash.

; CHECK:      Relocations [
; CHECK-NEXT:   Section __text {
; CHECK-NEXT:     Relocation {
; CHECK-NEXT:       Offset: 0x0
; CHECK-NEXT:       PCRel: 0
; CHECK-NEXT:       Length: 2
; CHECK-NEXT:       Extern: 1
; CHECK-NEXT:       Type: ARM64_RELOC_PAGEOFF12 (4)
; CHECK-NEXT:       Symbol: ltmp1
; CHECK-NEXT:       Scattered: 0
; CHECK-NEXT:     }
; CHECK-NEXT:   }
; CHECK-NEXT: ]

        ldr     x0, [x8, L_bar@PAGEOFF]

        .section        __foo,__bar,regular,no_dead_strip
L_bar:
        .quad   0


.globl _start
.section .rodata
msg:	.ascii "ok\n"
.text
_start:
	li a0, 1
	lui a1,      %hi(msg)
	addi a1, a1, %lo(msg)
	li a2, 3
	li a7, 64
	scall			# syscall: write(a0, a1, a2)

	li a0, 0
	li a7, 93
	scall			# syscall: _exit(a0)

Use the new name for syscall opcode on riscv.

.globl _start
.section .rodata
msg:	.ascii "ok\n"
.text
_start:
	li a0, 1
	lui a1,      %hi(msg)
	addi a1, a1, %lo(msg)
	li a2, 3
	li a7, 64
	ecall			# syscall: write(a0, a1, a2)

	li a0, 0
	li a7, 93
	ecall			# syscall: _exit(a0)


# Special test to make sure we don't error on VFP co-proc access
@ RUN: llvm-mc -triple=armv5 < %s | FileCheck %s
@ RUN: llvm-mc -triple=armv6 < %s | FileCheck %s

        @ p10 and p11 are reserved for NEON, but accessible on v5/v6
        ldc  p10, cr0, [r0], {0x20}
        ldc2 p11, cr0, [r0], {0x21}
        ldcl p11, cr0, [r0], {0x20}

@ CHECK-NOT: error: invalid operand for instruction


.EMPTYFILL $FF

.CARTRIDGETYPE 3
.RAMSIZE 3
.COMPUTECHECKSUM
.COMPUTECOMPLEMENTCHECK

.DEFINE ram_access_toggle $0000
.DEFINE ram_bank_select $4000

.DEFINE vram_save $A000
.DEFINE io_save $BE00

; 160 bytes
.DEFINE oam_save $BF00

.DEFINE stack_pointer_save $BFE0
.DEFINE magic_byte_save $BFE2

; required by packbits library
.DEFINE PACKBITS_INPUT_END_ADDRESS $BFE4
.DEFINE PACKBITS_CURRENT_OUTPUT_ADDRESS $BFE6

; stack starts at the top of the save ram - only need about 10 bytes
.DEFINE working_stack_pointer_address $C000

.DEFINE magic_byte_value $69

RAM_SHARING_MAGIC_BYTES:
.DB "SRAM_CFG"

.IFDEF game_uses_save_ram
    NUMBER_OF_BANKS:
    .DB 4

    GAME_SRAM:
    .DB 0

    SAVE_STATE_RAM_BANK_SRAM:
    .DB 1

.ELSE
    NUMBER_OF_BANKS:
    .DB 2
.ENDIF

    SAVE_STATE_RAM_BANK_VRAM:
    .DB 2

    SAVE_STATE_RAM_BANK:
    .DB 3

SAVE_STATE_PATCH_MAGIC_BYTES:
.DB "SSPMB"

Add support for games using MBC5 memory mapper

.EMPTYFILL $FF

.IFNDEF uses_mbc5
    .CARTRIDGETYPE 3
.ELSE
    .CARTRIDGETYPE $1B
.ENDIF

.RAMSIZE 3
.COMPUTECHECKSUM
.COMPUTECOMPLEMENTCHECK

.DEFINE ram_access_toggle $0000
.DEFINE ram_bank_select $4000

.DEFINE vram_save $A000
.DEFINE io_save $BE00

; 160 bytes
.DEFINE oam_save $BF00

.DEFINE stack_pointer_save $BFE0
.DEFINE magic_byte_save $BFE2

; required by packbits library
.DEFINE PACKBITS_INPUT_END_ADDRESS $BFE4
.DEFINE PACKBITS_CURRENT_OUTPUT_ADDRESS $BFE6

; stack starts at the top of the save ram - only need about 10 bytes
.DEFINE working_stack_pointer_address $C000

.DEFINE magic_byte_value $69

RAM_SHARING_MAGIC_BYTES:
.DB "SRAM_CFG"

.IFDEF game_uses_save_ram
    NUMBER_OF_BANKS:
    .DB 4

    GAME_SRAM:
    .DB 0

    SAVE_STATE_RAM_BANK_SRAM:
    .DB 1

.ELSE
    NUMBER_OF_BANKS:
    .DB 2
.ENDIF

    SAVE_STATE_RAM_BANK_VRAM:
    .DB 2

    SAVE_STATE_RAM_BANK:
    .DB 3

SAVE_STATE_PATCH_MAGIC_BYTES:
.DB "SSPMB"


// REQUIRES: x86

// RUN: echo "SECTIONS { \
// RUN: .dynamic : { *(.dynamic) } \
// RUN: .non_ro : { . += 1; } \
// RUN: .jcr : { *(.jcr) } \
// RUN: } " > %t.script
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: not ld.lld --export-dynamic %t.o -o %t --script=%t.script 2>&1 | FileCheck %s

// CHECK: error: section: .jcr is not contiguous with other relro sections

.global _start
_start:

        // non-empty relro section
        .section .jcr, "aw", @progbits
        .quad 0

Add BYTE expression to test case for non-contiguous relro

// REQUIRES: x86

// RUN: echo "SECTIONS { \
// RUN: .dynamic : { *(.dynamic) } \
// RUN: .non_ro : { . += 1; } \
// RUN: .jcr : { *(.jcr) } \
// RUN: } " > %t.script
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: not ld.lld --export-dynamic %t.o -o %t --script=%t.script 2>&1 | FileCheck %s

// RUN: echo "SECTIONS { \
// RUN: .dynamic : { *(.dynamic) } \
// RUN: .non_ro : { BYTE(1); } \
// RUN: .jcr : { *(.jcr) } \
// RUN: } " > %t2.script
// RUN: not ld.lld --export-dynamic %t.o -o %t --script=%t2.script 2>&1 | FileCheck %s

// CHECK: error: section: .jcr is not contiguous with other relro sections

.global _start
_start:

        // non-empty relro section
        .section .jcr, "aw", @progbits
        .quad 0


// RUN: llvm-mc -g -fdebug-compilation-dir=/test/comp/dir %s -filetype=obj -o %t.o
// RUN: llvm-dwarfdump %t.o | FileCheck %s

// CHECK: DW_AT_comp_dir [DW_FORM_string] ("/test/comp/dir")

f:
  nop

Add a triple to this test -- it has to be an ELF platform...

// RUN: llvm-mc -triple=x86_64-linux-unknown -g -fdebug-compilation-dir=/test/comp/dir %s -filetype=obj -o %t.o
// RUN: llvm-dwarfdump %t.o | FileCheck %s

// CHECK: DW_AT_comp_dir [DW_FORM_string] ("/test/comp/dir")

f:
  nop


@ RUN: llvm-mc -triple armv7 -show-encoding < %s | FileCheck %s

@ VCVT{B,T}

  vcvtt.f64.f16 d3, s1
@ CHECK-NOT: vcvtt.f64.f16 d3, s1      @ encoding: [0xe0,0x3b,0xb2,0xee]
  vcvtt.f16.f64 s5, d12
@ CHECK-NOT: vcvtt.f16.f64 s5, d12     @ encoding: [0xcc,0x2b,0xf3,0xee]

Add 'not' in front of a command that is expected to fail.

@ RUN: not llvm-mc -triple armv7 -show-encoding < %s | FileCheck %s

@ VCVT{B,T}

  vcvtt.f64.f16 d3, s1
@ CHECK-NOT: vcvtt.f64.f16 d3, s1      @ encoding: [0xe0,0x3b,0xb2,0xee]
  vcvtt.f16.f64 s5, d12
@ CHECK-NOT: vcvtt.f16.f64 s5, d12     @ encoding: [0xcc,0x2b,0xf3,0xee]


// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
// RUN: lld -flavor gnu2 %t -shared -o %tout.so
// RUN: llvm-readobj -t -dyn-symbols %tout.so | FileCheck %s
// REQUIRES: x86

// Check that STB_GNU_UNIQUE is treated as a global and ends up in the dynamic
// symbol table as STB_GNU_UNIQUE.

.global _start
.text
_start:

.data
.type symb, @gnu_unique_object
symb:

# CHECK:        Name: symb@
# CHECK-NEXT:   Value:
# CHECK-NEXT:   Size: 0
# CHECK-NEXT:   Binding: Unique
# CHECK-NEXT:   Type: Object
# CHECK-NEXT:   Other: 0
# CHECK-NEXT:   Section: .data
# CHECK-NEXT: }

Remove unused flag in test.

// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
// RUN: lld -flavor gnu2 %t -shared -o %tout.so
// RUN: llvm-readobj -dyn-symbols %tout.so | FileCheck %s
// REQUIRES: x86

// Check that STB_GNU_UNIQUE is treated as a global and ends up in the dynamic
// symbol table as STB_GNU_UNIQUE.

.global _start
.text
_start:

.data
.type symb, @gnu_unique_object
symb:

# CHECK:        Name: symb@
# CHECK-NEXT:   Value:
# CHECK-NEXT:   Size: 0
# CHECK-NEXT:   Binding: Unique
# CHECK-NEXT:   Type: Object
# CHECK-NEXT:   Other: 0
# CHECK-NEXT:   Section: .data
# CHECK-NEXT: }


// RUN: ld.lld %p/Inputs/gotpcrelx.o -o %t.so -shared
// RUN: llvm-readobj -s -r %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: 0x2090

// CHECK:      Relocations [
// CHECK-NEXT:   Section ({{.*}}) .rela.dyn {
// CHECK-NEXT:     0x2090 R_X86_64_GLOB_DAT foo 0x0
// CHECK-NEXT:     0x2098 R_X86_64_GLOB_DAT bar 0x0
// CHECK-NEXT:   }
// CHECK-NEXT: ]

Document how a binary file was created.

// RUN: ld.lld %p/Inputs/gotpcrelx.o -o %t.so -shared
// RUN: llvm-readobj -s -r %t.so | FileCheck %s

// The gotpcrelx.o is just this file assembled with gas. We should switch to
// llvm-mc once it starts producing R_X86_64_GOTPCRELX and
// R_X86_64_REX_GOTPCRELX.
movq foo@GOTPCREL(%rip), %rax
movl bar@GOTPCREL(%rip), %eax

// CHECK:      Name: .got
// CHECK-NEXT: Type: SHT_PROGBITS
// CHECK-NEXT: Flags [
// CHECK-NEXT:   SHF_ALLOC
// CHECK-NEXT:   SHF_WRITE
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x2090

// CHECK:      Relocations [
// CHECK-NEXT:   Section ({{.*}}) .rela.dyn {
// CHECK-NEXT:     0x2090 R_X86_64_GLOB_DAT foo 0x0
// CHECK-NEXT:     0x2098 R_X86_64_GLOB_DAT bar 0x0
// CHECK-NEXT:   }
// CHECK-NEXT: ]


#include "linux_assym.h"			/* system definitions */
#include <machine/asmacros.h>		/* miscellaneous asm macros */

#include <i386/linux/linux_syscall.h>		/* system call numbers */

NON_GPROF_ENTRY(linux_sigcode)
	call	LINUX_SIGF_HANDLER(%esp)
	leal	LINUX_SIGF_SC(%esp),%ebx	/* linux scp */
	movl	LINUX_SC_GS(%ebx),%edx
	movl	%dx,%gs
	push	%eax				/* fake ret addr */
	movl	$LINUX_SYS_linux_sigreturn,%eax	/* linux_sigreturn() */
	int	$0x80				/* enter kernel with args on stack */
	hlt					/* never gets here */

	.align	2				/* long word align */
_linux_esigcode:

	.data
	.globl	_linux_szsigcode
_linux_szsigcode:
	.long	_linux_esigcode-_linux_sigcode

	.text

Fix stack misalignment for Linux binaries caused by `linux_sigcode' not being a multiple of 4 bytes in size. This solves the recent SIGBUS errors for glibc2.1 configurations.

#include "linux_assym.h"			/* system definitions */
#include <machine/asmacros.h>		/* miscellaneous asm macros */

#include <i386/linux/linux_syscall.h>		/* system call numbers */

NON_GPROF_ENTRY(linux_sigcode)
	call	LINUX_SIGF_HANDLER(%esp)
	leal	LINUX_SIGF_SC(%esp),%ebx	/* linux scp */
	movl	LINUX_SC_GS(%ebx),%edx
	movl	%dx,%gs
	push	%eax				/* fake ret addr */
	movl	$LINUX_SYS_linux_sigreturn,%eax	/* linux_sigreturn() */
	int	$0x80				/* enter kernel with args on stack */
	hlt					/* never gets here */

	.align	4				/* long word align */
_linux_esigcode:

	.data
	.globl	_linux_szsigcode
_linux_szsigcode:
	.long	_linux_esigcode-_linux_sigcode

	.text


# 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"

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-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"


; vim: ft=nasm
global outb
outb:
    mov al, [esp + 8]
    mov dx, [esp + 4]
    out dx, al
    ret

global inb
inb:
    mov dx, [esp + 4]
    in al, dx

global io_wait
io_wait:
    push eax ; prevent clobbering our regs
    push edx
    mov dx, 0x80
    mov al, 0x0
    out dx,  al
    pop edx  ; restore regs
    pop eax
    ret

Fix register clobbering in outb/inb

; vim: ft=nasm
global outb
outb:
    push eax
    push edx
    mov al, [esp + 8]
    mov dx, [esp + 4]
    out dx, al
    pop edx
    pop eax
    ret

global inb
inb:
    push edx
    mov dx, [esp + 4]
    in al, dx
    pop edx
    ret

global io_wait
io_wait:
    push eax ; prevent clobbering our regs
    push edx
    mov dx, 0x80
    mov al, 0x0
    out dx,  al
    pop edx  ; restore regs
    pop eax
    ret


GLOBAL gdt_set

gdt_set:
    MOV EAX, [ESP + 4]
    LGDT [EAX]

    MOV EAX, 0x10

    ; set up data segment selectors with kernel space data selector
    MOV DS, EAX
    MOV ES, EAX
    MOV FS, EAX
    MOV GS, EAX
    MOV SS, EAX

    JMP 0x08:flush ; perform far jump to set CS to kernel space code selector
flush:
    RET

Remove segmentation setup from gdt_set

GLOBAL gdt_set

gdt_set:
    MOV EAX, [ESP + 4]
    LGDT [EAX]
    RET


.globl start
start:
    /* turn args into a slice */
    /* TODO */
    /* enter the main program */
    call	_main
    /* exit */
    movq	%rax,%rdi
    movq	$60,%rax
    syscall


_F9read_char:
push rbp
mov rbp, rsp

;TODO

leave
ret

Implement reading char from command line

_F9read_char:
push rbp
mov rbp, rsp
sub rsp, 8

push rcx
push rdi
push rsi
push rdx
push r11

mov qword [rbp - 8], 0

mov rax, 0
mov rdi, 0
lea rsi, [rbp - 8]
mov rdx, 1
syscall

mov rax, [rbp - 8]

pop r11
pop rdx
pop rsi
pop rdi
pop rcx

add rsp, 8
leave
ret


Add RuntimeDyld tests for currently supported O32 relocations.

# RUN: llvm-mc -triple=mipsel-unknown-linux -relocation-model=pic -code-model=small -filetype=obj -o %T/test_ELF_O32.o %s
# RUN: llc -mtriple=mipsel-unknown-linux -relocation-model=pic -filetype=obj -o %T/test_ELF_ExternalFunction_O32.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mipsel-unknown-linux -verify -map-section test_ELF_O32.o,.text=0x1000 -map-section test_ELF_ExternalFunction_O32.o,.text=0x10000 -check=%s %T/test_ELF_O32.o %T/test_ELF_ExternalFunction_O32.o

        .data
# rtdyld-check: *{4}R_MIPS_32 = foo
R_MIPS_32:
        .word foo
# rtdyld-check: *{4}(R_MIPS_32+4) = foo
        .4byte foo

	.text
	.abicalls
	.nan	legacy
	.text
	.set	nomicromips
	.set	nomips16
	.set	noreorder
	.set	nomacro
	.set	noat

	.align	3
	.globl	bar
	.type	bar,@function
bar:
# rtdyld-check:  decode_operand(R_MIPS_26, 0)[27:0] = stub_addr(test_ELF_O32.o, .text, foo)[27:0]
# rtdyld-check:  decode_operand(R_MIPS_26, 0)[1:0] = 0
R_MIPS_26:
	j   foo
	nop

# rtdyld-check:  decode_operand(R_MIPS_HI16, 1)[15:0] = foo[31:16]
R_MIPS_HI16:
	lui	$1, %hi(foo)

# rtdyld-check:  decode_operand(R_MIPS_LO16, 1)[15:0] = foo[15:0]
R_MIPS_LO16:
	lui	$1, %lo(foo)

	.size	bar, .-bar


Add test case to check some microMIPS R6 relocations. NFC

# REQUIRES: mips

# Check handling of microMIPS R6 relocations.

# RUN: llvm-mc -filetype=obj -triple=mips -mcpu=mips32r6 \
# RUN:         %S/Inputs/mips-micro.s -o %t1eb.o
# RUN: llvm-mc -filetype=obj -triple=mips -mcpu=mips32r6 %s -o %t2eb.o
# RUN: ld.lld -o %teb.exe %t1eb.o %t2eb.o
# RUN: llvm-objdump -d -t -mattr=micromips %teb.exe \
# RUN:   | FileCheck --check-prefixes=EB,SYM %s

# RUN: llvm-mc -filetype=obj -triple=mipsel -mcpu=mips32r6 \
# RUN:         %S/Inputs/mips-micro.s -o %t1el.o
# RUN: llvm-mc -filetype=obj -triple=mipsel -mcpu=mips32r6 %s -o %t2el.o
# RUN: ld.lld -o %tel.exe %t1el.o %t2el.o
# RUN: llvm-objdump -d -t -mattr=micromips %tel.exe \
# RUN:   | FileCheck --check-prefixes=EL,SYM %s

# EB:      __start:
# EB-NEXT:    20010:  78 47 ff fd  lapc   $2, -12
# EB-NEXT:    20014:  80 7f ff f6  beqzc  $3, -36
# EB-NEXT:    20018:  b7 ff ff f4  balc   -24 <foo>

# EL:      __start:
# EL-NEXT:    20010:  47 78 fd ff  lapc   $2, -12
# EL-NEXT:    20014:  7f 80 f6 ff  beqzc  $3, -36
# EL-NEXT:    20018:  ff b7 f4 ff  balc   -24 <foo>

# SYM: 00020000 g F     .text           00000000 foo
# SYM: 00020010         .text           00000000 __start

  .text
  .set micromips
  .global __start
__start:
  addiupc $2, foo+4   # R_MICROMIPS_PC19_S2
  beqzc   $3, foo+4   # R_MICROMIPS_PC21_S1
  balc    foo+4       # R_MICROMIPS_PC26_S1


# XFAIL: win32
# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: not ld.lld %t %t -o %t2 2>&1 | FileCheck -check-prefix=DEMANGLE %s

# RUN: not ld.lld %t %t -o %t2 --no-demangle 2>&1 | \
# RUN:   FileCheck -check-prefix=NO_DEMANGLE %s

# DEMANGLE:    duplicate symbol: {{mul\(double, double\)|_Z3muldd}} in
# NO_DEMANGLE: duplicate symbol: _Z3muldd in

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

Remove XFAIL:win32 from a test which does not fail on win32.


Add missing darwin asm file for xattr support

// Copyright 2014 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.

// +build !gccgo

#include "textflag.h"

TEXT ·use(SB),NOSPLIT,$0
	RET


Add a test that would have found the issue with r225644.

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

; Test that we produce an external relocation. There is no apparent need for it, but
; ld64 (241.9) produces a corrupt output if we don't.

// CHECK:      Relocations [
// CHECK-NEXT:   Section __data {
// 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: Lfoo
// CHECK-NEXT:       Scattered: 0
// CHECK-NEXT:     }
// CHECK-NEXT:   }
// CHECK-NEXT: ]

        .section        __DATA,__cfstring
Lfoo:

        .section        __DATA,__data
        .quad   Lfoo


Add this test back, the check pattern was too strict.

// FIXME: Switch back to FileCheck once we print actual instructions

// RUN: llvm-mc -triple i386-unknown-unknown %s > %t

# Simple instructions
        subb %al, %al
// RUN: grep {MCInst(opcode=.*, operands=.reg:2, reg:0, reg:2.)} %t


Add a test that .align directives on capable processors use long NOPs.

# RUN: llvm-mc -filetype=obj -arch=x86 -mcpu=i686 %s | llvm-objdump -d -no-show-raw-insn - | FileCheck %s

# Ensure alignment directives also emit sequences of 15-byte NOPs on processors
# capable of using long NOPs.
inc %eax
.align 32
inc %eax
# CHECK: 0:  inc
# CHECK-NEXT: 1:  nop
# CHECK-NEXT: 10:  nop
# CHECK-NEXT: 1f:  nop
# CHECK-NEXT: 20:  inc