Opened 11 years ago

Closed 11 years ago

Last modified 3 years ago

#39052 closed defect (wontfix)

clang-3.2: can't compile a program that writes to stderr on PPC

Reported by: tenomoto (Takeshi Enomoto) Owned by: jeremyhu (Jeremy Huddleston Sequoia)
Priority: Normal Milestone:
Component: ports Version: 2.1.3
Keywords: Cc: cooljeanius (Eric Gallager), fang@…, devernay (Frédéric Devernay), mojca (Mojca Miklavec)
Port: clang-3.2

Description

I can't compile a simple program that writes to stderr on a PowerPC Mac running Leopard. I attach a log.

$ cat foo.c
#include <stdio.h>
int main(void)
{
  fprintf(stderr,"hello\n");
}
$ clang-mp-3.2 foo.c
ld: absolute address to symbol ___stderrp in a different linkage unit not supported in _main from /tmp/foo-WnmpXC.o
collect2: ld returned 1 exit status
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

Attachments (1)

foo.log (2.9 KB) - added by tenomoto (Takeshi Enomoto) 11 years ago.

Download all attachments as: .zip

Change History (12)

Changed 11 years ago by tenomoto (Takeshi Enomoto)

Attachment: foo.log added

comment:1 Changed 11 years ago by larryv (Lawrence Velázquez)

Cc: jeremyhu@… removed
Owner: changed from macports-tickets@… to jeremyhu@…

comment:2 Changed 11 years ago by cooljeanius (Eric Gallager)

Is this just an issue with the MacPorts clang-3.2, or is it also present in other compiles of clang-3.2 for PPC?

comment:3 Changed 11 years ago by jeremyhu (Jeremy Huddleston Sequoia)

Resolution: wontfix
Status: newclosed

clang's ppc support is extremely limited. If you want to use clang on ppc, I suggest you use trunk, follow upstream development closely, and contribute code changes.

comment:4 Changed 11 years ago by cooljeanius (Eric Gallager)

Cc: egall@… added

Cc Me!

comment:6 Changed 11 years ago by fang@…

Cc: fang@… added

Cc Me!

comment:7 Changed 11 years ago by devernay (Frédéric Devernay)

Cc: frederic.devernay@… added

Cc Me!

comment:8 Changed 11 years ago by devernay (Frédéric Devernay)

This also affects clang-3.3, and thus prevents building boost 1.54.0 on PPC #39809. Shouldn't it be reopened? fang@… seems to have working clang-3.2 and clang-3.3 builds (at least on Tiger) http://vlsi.cornell.edu/~fang/sw/llvm/

The PPC output has changed a lot between clang-3.1 and clang-3.2. Here's a simple program:

#include <stdio.h>

int main(int argc, char **argv)
{
  fprintf(stdout,"hello!\n");
  return 0;
}

Here's the PPC assembly output of clang-3.1/OSX 10.5:

	.machine ppc970
	.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, -4(r1)
	stw r0, 8(r1)
	stwu r1, -64(r1)
	bl L0$pb
L0$pb:
	mr r31, r1
	mflr r4
	addis r3, r4, ha16(L___stdoutp$non_lazy_ptr-L0$pb)
	addis r4, r4, ha16(L_.str-L0$pb)
	lwz r3, lo16(L___stdoutp$non_lazy_ptr-L0$pb)(r3)
	la r4, lo16(L_.str-L0$pb)(r4)
	lwz r3, 0(r3)
	bl _fprintf$LDBL128
	li r3, 0
	addi r1, r1, 64
	lwz r0, 8(r1)
	lwz r31, -4(r1)
	mtlr r0
	blr 

	.section	__DATA,__nl_symbol_ptr,non_lazy_symbol_pointers
	.align	2
L___stdoutp$non_lazy_ptr:
	.indirect_symbol	___stdoutp
	.long	0

.subsections_via_symbols
	.section	__TEXT,__cstring,cstring_literals
L_.str:
	.asciz	 "hello!\n"

And here's the output on clang-3.2:

	.machine ppc970
	.section	__TEXT,__textcoal_nt,coalesced,pure_instructions
	.section	__TEXT,__text,regular,pure_instructions
	.globl	_main
	.align	4
_main:
	mflr r0
	stw r31, -4(r1)
	stw r0, 8(r1)
	stwu r1, -64(r1)
	lis r3, ha16(___stdoutp)
	lis r4, ha16(L_.str)
	mr r31, r1
	lwz r3, lo16(___stdoutp)(r3)
	la r4, lo16(L_.str)(r4)
	bl _fprintf$LDBL128
	li r3, 0
	addi r1, r1, 64
	lwz r0, 8(r1)
	lwz r31, -4(r1)
	mtlr r0
	blr 

.subsections_via_symbols
	.section	__TEXT,__cstring,cstring_literals
L_.str:
	.asciz	 "hello!\n"

comment:9 Changed 11 years ago by jeremyhu (Jeremy Huddleston Sequoia)

Even with David's patches for darwin/ppc support in llvm, that support is still experimental (it is still being discussed on the llvm mailing list and hasn't been merged yet) and should not be used.

I think you should focus on finding a stable compiler that does work for boost.

comment:10 Changed 9 years ago by mojca (Mojca Miklavec)

Cc: mojca@… added

Cc Me!

comment:11 Changed 3 years ago by kencu (Ken)

Some progress over the years -- this is on Tiger PPC:

$ port -v installed clang-3.4
The following ports are currently installed:
  clang-3.4 @3.4.2_14+analyzer (active) platform='darwin 8' archs='ppc' date='2020-11-22T06:21:40-0800'

$ port -v installed cctools
The following ports are currently installed:
  cctools @949.0.1_0 (active) platform='darwin 8' archs='ppc' date='2021-01-30T12:15:33-0800'

$ port -v installed | grep ld64
  ld64 @3_3+ld64_97 (active) platform='darwin 8' archs='ppc' date='2020-05-01T20:27:38-0700'
  ld64-97 @97.17_11 (active) platform='darwin 8' archs='ppc' date='2019-09-11T19:25:08-0700'
$ cat hello.c
#include <stdio.h>

int main()
{
	printf("hello, world!\n");
	return 0;
}

$ clang-mp-3.4 -o hello hello.c
/usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: /var/tmp/hello-5a28d3.o has external relocation entries in non-writable section (__TEXT,__text) for symbols:
_printf$LDBL128
collect2: ld returned 1 exit status
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

but if we do this:

sudo port select gcc apple-gcc42

now the linker works:

$ clang-mp-3.4 -o hello hello.c

$ ./hello
hello, world!

and for this example:

$ cat hello2.c
#include <stdio.h>

int main()
{
	fprintf(stderr, "hello, world!\n");
	return 0;
}

we try:

$ clang-mp-3.4 -o hello2 hello2.c
ld: absolute address to symbol ___sF in a different linkage unit not supported in _main from /var/tmp/hello2-d3a630.o
collect2: ld returned 1 exit status
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

but if we add -fpic then we get success:

$ clang-mp-3.4 -fpic -o hello2 hello2.c
$ ./hello2
hello, world!
Note: See TracTickets for help on using tickets.