[cfe-dev] Getting started with clang
Mike Stump
mrs at apple.com
Mon Aug 17 09:04:25 PDT 2009
On Aug 17, 2009, at 8:46 AM, Robert Wuest wrote:
> I'm just getting started with clang and having some problems. I'm
> trying to build a compiler to run on x8_64 and gen code for the
> powerpc.
The normal clang can do that just fine.
> This definitely produces a working native compiler as seen here:
>
> $ clang hello.c
> $ ./a.out
> Hello, world
>
> However, when I try the '-arch ppc' option, it still only produces
> x86_64 code:
You sure? See below... Try the -S option, seeing is believing.
> $ rm a.out
> $ clang -arch ppc hello.c
> clang: warning: argument unused during compilation: '-arch ppc'
> $ ./a.out
> Hello, world
> Have I missed something?
$ cat >t.c
int main() {
printf("Hello World!\n");
}
mrs $ clang t.c -w
mrs $ a.out
Hello World!
$ file a.out
a.out: Mach-O 64-bit executable x86_64
mrs $ clang -arch ppc t.c -w
mrs $ a.out
Hello World!
mrs $ file a.out
a.out: Mach-O executable ppc
mrs $ clang -arch ppc t.c -w -o - -S
.machine ppc
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
.section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4
_main:
mflr r0
stw r31, 20(r1)
stw r0, 8(r1)
stwu r1, -64(r1)
mr r31, r1
bl "L1$pb"
"L1$pb":
mflr r2
li r3, 0
addis r2, r2, ha16(L_.str-"L1$pb")
stw r3, 60(r31)
la r2, lo16(L_.str-"L1$pb")(r2)
mr r3, r2
bl L_printf$stub
mr r2, r3
lwz r2, 60(r31)
mr r3, r2
addi r1, r1, 64
lwz r0, 8(r1)
lwz r31, 20(r1)
mtlr r0
blr
.section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
.align 4
L_printf$stub:
.indirect_symbol _printf
mflr r0
bcl 20,31,L_printf$stub$tmp
L_printf$stub$tmp:
mflr r11
addis r11,r11,ha16(L_printf$lazy_ptr-L_printf$stub$tmp)
mtlr r0
lwzu r12,lo16(L_printf$lazy_ptr-L_printf$stub$tmp)(r11)
mtctr r12
bctr
.section __DATA,__la_symbol_ptr,lazy_symbol_pointers
L_printf$lazy_ptr:
.indirect_symbol _printf
.long dyld_stub_binding_helper
.subsections_via_symbols
.section __TEXT,__cstring,cstring_literals
L_.str:
.asciz "Hello World!\n"
More information about the cfe-dev
mailing list