tpoechtrager / cctools-port

Apple cctools port for Linux and *BSD

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cctools 949 i386 assembler broken

kencu opened this issue · comments

commented

Hi,

I'm trying to upgrade cctools to 949 in the MacPorts project, and I'm finding the i386 assembler is broken compared to cctools-927.

$ clang-mp-3.4 -arch i386 -no-integrated-as -o hello hello.c
ld: in /var/folders/JS/JSmhNUB9HNSSCVaN+wE+XU+++TI/-Tmp-/hello-eaff28.o, in section __TEXT,__text reloc 2: r_length=0 and r_pcrel=0 not supported for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

the x86_64 assembler is OK:

$ clang-mp-3.4 -arch x86_64 -no-integrated-as -o hello hello.c
$ ./hello
Hello, World

The i386 assembler in cctools-927 worked OK

I was wondering you had any ideas about this, or perhaps already might have tweaked your project here to fix this? If so, I can't spot the fix looking around here...

Afaik Apple does not support i386 upstream anymore, so this is kinda expected.

commented

it's just accidentally been broken, I think.

The i386.c files are updated, and the ppc assembler still works great.

I will see if I can spot where they are building the errant relic sections.

commented

reloc sections ... ipads ;)

commented

I found it. This little tweak here that was added in cctools 949 chopped off some code that was used in i386 (and maybe in x86_64 as well):

diff --git a/cctools/as/write_object.c b/cctools/as/write_object.c
index 66f85f3..29f056c 100644
--- a/cctools/as/write_object.c
+++ b/cctools/as/write_object.c
@@ -1253,6 +1259,8 @@ uint32_t debug_section)
 		riP->r_type = X86_64_RELOC_UNSIGNED;
 		return(2 * sizeof(struct relocation_info));
 #endif
+/* the #if that follows is to silence a noisy "unreachable code" warning */
+#if defined(ARM) || defined(SPARC) || defined(HPPA) || defined (PPC)
 #ifdef PPC
 		if(fixP->fx_r_type == PPC_RELOC_HI16)
 		    sectdiff = PPC_RELOC_HI16_SECTDIFF;
@@ -1379,6 +1387,7 @@ uint32_t debug_section)
 #endif
 		*riP = *((struct relocation_info *)&sri);
 		return(2 * sizeof(struct relocation_info));
+#endif /* unreachable code */
 	    }
 	    /*
 	     * Determine if this is left as a local relocation entry or must be

So once that was removed, the assembler works properly again.

$ port -v installed cctools
The following ports are currently installed:
  cctools @927.0.2_7 platform='darwin 8' archs='i386' date='2021-01-21T22:10:33-0800'
  cctools @949.0.1_0 (active) platform='darwin 8' archs='i386' date='2021-01-27T11:14:57-0800'
$ clang-mp-3.4 -arch i386 -v -Wl,-v -Wa,-v -no-integrated-as -o hello hello.c
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
Target: i386-apple-darwin8.11.1
Thread model: posix
 "/opt/local/libexec/llvm-3.4/bin/clang" -cc1 -triple i386-apple-macosx10.4.0 -S -disable-free -disable-llvm-verifier -main-file-name hello.c -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -target-cpu yonah -target-linker-version 97.17 -v -resource-dir /opt/local/libexec/llvm-3.4/bin/../lib/clang/3.4.2 -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm -fno-autolink -fdebug-compilation-dir /Users/cunningh/Desktop -ferror-limit 19 -fmessage-length 110 -mstackrealign -fobjc-runtime=macosx-fragile-10.4.0 -fencode-extended-block-signature -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/tmp/hello-82a2a4.s -x c hello.c
clang -cc1 version 3.4.2 based upon LLVM 3.4.2 default target i386-apple-darwin8.11.1
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/local/libexec/llvm-3.4/bin/../lib/clang/3.4.2/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/opt/local/bin/as" -arch i386 -force_cpusubtype_ALL -v -o /var/tmp/hello-e3887b.o /var/tmp/hello-82a2a4.s
Apple Inc version cctools-localbuild, GNU assembler version 1.38
 "/opt/local/libexec/llvm-3.4/bin/ld" -dynamic -arch i386 -macosx_version_min 10.4.0 -o hello -lcrt1.o -v /var/tmp/hello-e3887b.o -lSystem -lgcc_s.10.4 /opt/local/libexec/llvm-3.4/bin/../lib/clang/3.4.2/lib/darwin/libclang_rt.10.4.a
@(#)PROGRAM:ld  PROJECT:ld64-97.17
configured to support archs: i386 x86_64 ppc ppc64 armv6 armv7
Library search paths:
	/usr/lib
	/usr/local/lib
Framework search paths:
	/Library/Frameworks/
	/System/Library/Frameworks/
$ ./hello
Hello, World

Thanks for pointing this out!