[MacPorts] #58493: cctools: using clang < 5.0 as default assembler generates assembly errors in some cases

MacPorts noreply at macports.org
Sat May 18 21:54:33 UTC 2019


#58493: cctools: using clang < 5.0 as default assembler generates assembly errors
in some cases
----------------------+----------------------
  Reporter:  kencu    |      Owner:  jeremyhu
      Type:  defect   |     Status:  assigned
  Priority:  Normal   |  Milestone:
 Component:  ports    |    Version:
Resolution:           |   Keywords:
      Port:  cctools  |
----------------------+----------------------
Description changed by kencu:

Old description:

> To fix errors in newer ports that require gcc (fortran) to assemble newer
> assembly, the `as` in `cctools` was modified to send the assembly to a
> specific version of `clang` for processing, if present. For SnowLeopard,
> that default `clang` version is `clang-3.4`.
>
> It turns out there is (at least one) bug in the `clang` i386 assembler
> that was not fixed until after `clang-3.7`. It is fixed in `clang-5.0`.
> This error shows up during the build or bootstrapping of `gcc / libgcc`,
> and perhaps will turn up elsewhere:
> {{{
> pt/local/i386-apple-darwin10/bin/ -nostdinc++
> -B/opt/local/var/macports/build/_opt_macports-
> ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
> darwin10/libstdc++-v3/src/.libs -B/opt/local/var/macports/build
> /_opt_macports-ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
> darwin10/libstdc++-v3/libsupc++/.libs  -isystem
> /opt/local/var/macports/build/_opt_macports-
> ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
> darwin10/libstdc++-v3/include/i386-apple-darwin10  -isystem
> /opt/local/var/macports/build/_opt_macports-
> ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
> darwin10/libstdc++-v3/include  -isystem /opt/local/var/macports/build
> /_opt_macports-
> ports_lang_gcc9/libgcc9/work/gcc-9.1.0/libstdc++-v3/libsupc++
> -L/opt/local/var/macports/build/_opt_macports-
> ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
> darwin10/libstdc++-v3/src/.libs -L/opt/local/var/macports/build
> /_opt_macports-ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
> darwin10/libstdc++-v3/libsupc++/.libs    -g -O2  -fno-checking -mdynamic-
> no-pic -gtoggle -DIN_GCC     -fno-exceptions -fno-rtti -fasynchronous-
> unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual
> -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long
> -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -static-
> libstdc++ -static-libgcc  -o cc1 c/c-lang.o c-family/stub-objc.o
> attribs.o c/c-errors.o c/c-decl.o c/c-typeck.o c/c-convert.o c/c-aux-
> info.o c/c-objc-common.o c/c-parser.o c/c-fold.o c/gimple-parser.o
> c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o
> c-family/c-format.o c-family/c-gimplify.o c-family/c-indentation.o
> c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o
> c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o
> c-family/c-semantics.o c-family/c-ada-spec.o c-family/c-ubsan.o c-family
> /known-headers.o c-family/c-attribs.o c-family/c-warn.o
> c-family/c-spellcheck.o i386-c.o darwin-c.o \
>           cc1-checksum.o libbackend.a main.o libcommon-target.a
> libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a libcommon.a
> ../libcpp/libcpp.a  -liconv ../libbacktrace/.libs/libbacktrace.a
> ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a  -L/opt/local/lib
> -lisl -L/opt/local/lib -L/opt/local/lib -L/opt/local/lib -lmpc -lmpfr
> -lgmp   -lz
> ld: in libbackend.a(i386.o), in section __TEXT,__text reloc 5479:
> unsupported r_length=0 for scattered vanilla reloc for architecture i386
> }}}
>
> This is a known clang assembler error
> <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63773>.
>
> There is a reduced test case for it:
> {{{
>         .text
>         .align 4,0x90
>         .globl _choose_tmpdir
> _choose_tmpdir:
>         sbbl    $3+_vartmp, %esi
>         ret
>         .space 254
>
>         .const
>         .align 2
> _vartmp:
>         .byte   47
> }}}
> and I confirm that `clang-3.4` and `clang-3.7` error out on this
> assembly, but `clang-5.0` can compile it successfully:
> {{{
> $ clang-mp-3.4 -arch i386  testi386asm.S
> ld: in /var/folders/If/IfyiELboGT08qyd+9nD3DU+++TI/-Tmp-/testi386asm-
> fc6237.o, in section __TEXT,__text reloc 0: unsupported r_length=0 for
> scattered vanilla reloc for architecture i386
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
>
> $ clang-mp-3.7 -arch i386  testi386asm.S
> ld: in /var/folders/If/IfyiELboGT08qyd+9nD3DU+++TI/-Tmp-/testi386asm-
> c2fa0b.o, in section __TEXT,__text reloc 0: unsupported r_length=0 for
> scattered vanilla reloc for architecture i386
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
>
> $ clang-mp-5.0 -arch i386  testi386asm.S
> Undefined symbols for architecture i386:
>   "_main", referenced from:
>       start in crt1.10.6.o
> ld: symbol(s) not found for architecture i386
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
> }}}
>
> Likewise, the same assembly generates errors when compiling in `x86_64`
> mode.
> {{{
> $ clang-mp-3.4 -arch x86_64  testi386asm.S
> ld: in /var/folders/If/IfyiELboGT08qyd+9nD3DU+++TI/-Tmp-/testi386asm-
> 07fc5b.o, in section __TEXT,__text reloc 0: length < 2 and
> X86_64_RELOC_UNSIGNED not supported for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
>
> $ clang-mp-3.7 -arch x86_64  testi386asm.S
> ld: in /var/folders/If/IfyiELboGT08qyd+9nD3DU+++TI/-Tmp-/testi386asm-
> 52d45e.o, in section __TEXT,__text reloc 0: length < 2 and
> X86_64_RELOC_UNSIGNED not supported for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
>
> $ clang-mp-5.0 -arch x86_64  testi386asm.S
> Undefined symbols for architecture x86_64:
>   "_main", referenced from:
>       start in crt1.10.6.o
> ld: symbol(s) not found for architecture x86_64
> }}}
>
> So - it appears that `clang` should not be used as the default assembler
> unless it is `clang-5.0` or greater, and for the system `clang` should
> not be used (according to the gcc bug report) unless the Xcode version is
> at least `7.3.1`.
>
> This probably requires only a rather minor adjustment to the `cctools`
> port.

New description:

 To fix errors in newer ports that require gcc (fortran) to assemble newer
 assembly, the `as` in `cctools` was modified to send the assembly to a
 specific version of `clang` for processing, if present. For SnowLeopard,
 that default `clang` version is `clang-3.4`.

 It turns out there is (at least one) bug in the `clang` i386 assembler
 that was not fixed until after `clang-3.7`. It is fixed in `clang-5.0`.
 This error shows up during the build or bootstrapping of `gcc / libgcc`,
 and perhaps will turn up elsewhere:
 {{{
 /opt/local/i386-apple-darwin10/bin/ -nostdinc++
 -B/opt/local/var/macports/build/_opt_macports-
 ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
 darwin10/libstdc++-v3/src/.libs -B/opt/local/var/macports/build
 /_opt_macports-ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
 darwin10/libstdc++-v3/libsupc++/.libs  -isystem
 /opt/local/var/macports/build/_opt_macports-
 ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
 darwin10/libstdc++-v3/include/i386-apple-darwin10  -isystem
 /opt/local/var/macports/build/_opt_macports-
 ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
 darwin10/libstdc++-v3/include  -isystem /opt/local/var/macports/build
 /_opt_macports-
 ports_lang_gcc9/libgcc9/work/gcc-9.1.0/libstdc++-v3/libsupc++
 -L/opt/local/var/macports/build/_opt_macports-
 ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
 darwin10/libstdc++-v3/src/.libs -L/opt/local/var/macports/build
 /_opt_macports-ports_lang_gcc9/libgcc9/work/build/prev-i386-apple-
 darwin10/libstdc++-v3/libsupc++/.libs    -g -O2  -fno-checking -mdynamic-
 no-pic -gtoggle -DIN_GCC     -fno-exceptions -fno-rtti -fasynchronous-
 unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual
 -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long
 -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -static-
 libstdc++ -static-libgcc  -o cc1 c/c-lang.o c-family/stub-objc.o attribs.o
 c/c-errors.o c/c-decl.o c/c-typeck.o c/c-convert.o c/c-aux-info.o c/c
 -objc-common.o c/c-parser.o c/c-fold.o c/gimple-parser.o
 c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o
 c-family/c-format.o c-family/c-gimplify.o c-family/c-indentation.o
 c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o
 c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o
 c-family/c-semantics.o c-family/c-ada-spec.o c-family/c-ubsan.o c-family
 /known-headers.o c-family/c-attribs.o c-family/c-warn.o
 c-family/c-spellcheck.o i386-c.o darwin-c.o \
           cc1-checksum.o libbackend.a main.o libcommon-target.a
 libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a libcommon.a
 ../libcpp/libcpp.a  -liconv ../libbacktrace/.libs/libbacktrace.a
 ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a  -L/opt/local/lib
 -lisl -L/opt/local/lib -L/opt/local/lib -L/opt/local/lib -lmpc -lmpfr
 -lgmp   -lz
 ld: in libbackend.a(i386.o), in section __TEXT,__text reloc 5479:
 unsupported r_length=0 for scattered vanilla reloc for architecture i386
 }}}

 This is a known clang assembler error
 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63773>.

 There is a reduced test case for it:
 {{{
         .text
         .align 4,0x90
         .globl _choose_tmpdir
 _choose_tmpdir:
         sbbl    $3+_vartmp, %esi
         ret
         .space 254

         .const
         .align 2
 _vartmp:
         .byte   47
 }}}
 and I confirm that `clang-3.4` and `clang-3.7` error out on this assembly,
 but `clang-5.0` can compile it successfully:
 {{{
 $ clang-mp-3.4 -arch i386  testi386asm.S
 ld: in /var/folders/If/IfyiELboGT08qyd+9nD3DU+++TI/-Tmp-/testi386asm-
 fc6237.o, in section __TEXT,__text reloc 0: unsupported r_length=0 for
 scattered vanilla reloc for architecture i386
 clang: error: linker command failed with exit code 1 (use -v to see
 invocation)

 $ clang-mp-3.7 -arch i386  testi386asm.S
 ld: in /var/folders/If/IfyiELboGT08qyd+9nD3DU+++TI/-Tmp-/testi386asm-
 c2fa0b.o, in section __TEXT,__text reloc 0: unsupported r_length=0 for
 scattered vanilla reloc for architecture i386
 clang: error: linker command failed with exit code 1 (use -v to see
 invocation)

 $ clang-mp-5.0 -arch i386  testi386asm.S
 Undefined symbols for architecture i386:
   "_main", referenced from:
       start in crt1.10.6.o
 ld: symbol(s) not found for architecture i386
 clang: error: linker command failed with exit code 1 (use -v to see
 invocation)
 }}}

 Likewise, the same assembly generates errors when compiling in `x86_64`
 mode.
 {{{
 $ clang-mp-3.4 -arch x86_64  testi386asm.S
 ld: in /var/folders/If/IfyiELboGT08qyd+9nD3DU+++TI/-Tmp-/testi386asm-
 07fc5b.o, in section __TEXT,__text reloc 0: length < 2 and
 X86_64_RELOC_UNSIGNED not supported for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to see
 invocation)

 $ clang-mp-3.7 -arch x86_64  testi386asm.S
 ld: in /var/folders/If/IfyiELboGT08qyd+9nD3DU+++TI/-Tmp-/testi386asm-
 52d45e.o, in section __TEXT,__text reloc 0: length < 2 and
 X86_64_RELOC_UNSIGNED not supported for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to see
 invocation)

 $ clang-mp-5.0 -arch x86_64  testi386asm.S
 Undefined symbols for architecture x86_64:
   "_main", referenced from:
       start in crt1.10.6.o
 ld: symbol(s) not found for architecture x86_64
 }}}

 So - it appears that `clang` should not be used as the default assembler
 unless it is `clang-5.0` or greater, and for the system `clang` should not
 be used (according to the gcc bug report) unless the Xcode version is at
 least `7.3.1`.

 This probably requires only a rather minor adjustment to the `cctools`
 port.

--

-- 
Ticket URL: <https://trac.macports.org/ticket/58493#comment:1>
MacPorts <https://www.macports.org/>
Ports system for macOS


More information about the macports-tickets mailing list