Skip to content

clang10 -Oz generates incorrect symbols for msvc 32bit target #42056

@wang-bin

Description

@wang-bin
mannequin
Bugzilla Link 42711
Resolution FIXED
Resolved on Feb 27, 2020 02:48
Version 10.0
OS Windows NT
Blocks #41819 #43900
CC @zmodem,@zygoloid,@sjoerdmeijer

Extended Description

Code to Reproduce(from ffmpeg):

#include <stdint.h>
#include <math.h>
#ifndef ff_ctzll
#define ff_ctzll(v) __builtin_ctzll(v)
#endif
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)

int64_t av_gcd(int64_t a, int64_t b) {
int za, zb, k;
int64_t u, v;
if (a == 0)
return b;
if (b == 0)
return a;
za = ff_ctzll(a);
zb = ff_ctzll(b);
k = FFMIN(za, zb);
u = llabs(a >> za);
v = llabs(b >> zb);
while (u != v) {
if (u > v)
FFSWAP(int64_t, v, u);
v -= u;
v >>= ff_ctzll(v);
}
return (uint64_t)u << k;
}

int main()
{
int v = av_gcd(123, 345);
}

Build Command:

gnu style: clang-9 -Oz -fuse-ld=lld-link-9 --target=i386-pc-windows-msvc -std=c11 -MD -Wl,-nodefaultlib:libcmt -Wl,-defaultlib:msvcrt clangcl32OzBug.c

vc style: clang-cl -Xclang -Oz --target=i386-pc-windows-msvc -MD clangcl32OzBug.c

Actual Results:

lld-link-9: error: undefined symbol: ___ashrdi3

referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)
referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)
referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)

lld-link-9: error: undefined symbol: ___ashldi3

referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Expected Results:
no error

Additional Information:
x64 target, clang-8, -Os -O2 no error.
__ashrdi3 exists in libgcc and compiler-rt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclangClang issues not falling into any other category

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions