Bug 205904 - textproc/expat2: unresolvable R_ARM_MOVW_ABS_NC relocation against symbol `malloc@@FBSD_1.0'
Summary: textproc/expat2: unresolvable R_ARM_MOVW_ABS_NC relocation against symbol `ma...
Status: Closed Not A Bug
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: arm Any
: --- Affects Only Me
Assignee: freebsd-arm (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-04 22:02 UTC by Mark Millard
Modified: 2016-01-11 13:01 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Millard 2016-01-04 22:02:42 UTC
I updated to (via a cross build from amd64 that was based on -march=armv7-a -mcpu=cortex-a7):

# freebsd-version -ku; uname -aKU
11.0-CURRENT
11.0-CURRENT
FreeBSD rpi2 11.0-CURRENT FreeBSD 11.0-CURRENT #8 r293129M: Sun Jan  3 20:37:26 PST 2016     root@FreeBSDx64:/usr/obj/clang/arm.armv6/usr/src/sys/RPI2-NODBG  arm 1100093 1100093

on an rpi2b in order to pick up and try out:

BEGIN -r292964 description
Author: ian
Date: Wed Dec 30 23:04:08 2015
New Revision: 292964
URL: https://svnweb.freebsd.org/changeset/base/292964

Log:
  Add the MOVT/MOVW types to the list of relocs which do not generate .plt
  entries.  This fixes the segfaults in arm userland code compiled with
  -march= or -mcpu= values that allow the compiler to generate movw/movt
  sequences to load 32-bit constants.

Modified:
  head/contrib/binutils/bfd/elf32-arm.c
END -r292964 description

instead of using /usr/local/arm-gnueabi-freebsd/bin/* binutils as I have been experimenting with.

I tried something simple and C-based on the rpi2:

portmaster -DK textproc/expat2

based on:

# more /etc/make.conf 
DEFAULT_VERSIONS+=perl5=5.22
WRKDIRPREFIX=/usr/obj/portswork
WITH_DEBUG=
WITH_DEBUG_FILES=
MALLOC_PRODUCTION=
TO_TYPE=armv6
TOOLS_TO_TYPE=arm-gnueabi
VERSION_CONTEXT=11.0
.if ${.MAKE.LEVEL} == 0
CC=/usr/bin/clang -v -target ${TO_TYPE}--freebsd${VERSION_CONTEXT}-gnueabi -march=armv7-a -mcpu=cortex-a7 -mfloat-abi=softfp -mno-unaligned-access
CXX=/usr/bin/clang++ -v -target ${TO_TYPE}--freebsd${VERSION_CONTEXT}-gnueabi -march=armv7-a -mcpu=cortex-a7 -mfloat-abi=softfp -mno-unaligned-access
CPP=/usr/bin/clang-cpp -v -target ${TO_TYPE}--freebsd${VERSION_CONTEXT}-gnueabi -march=armv7-a -mcpu=cortex-a7 -mfloat-abi=softfp -mno-unaligned-access
.export CC
.export CXX
.export CPP
.endif

(Note the -v's that show extra context during the command executions.)

The failing result involving movw was "unresolvable R_ARM_MOVW_ABS_NC relocation against symbol `malloc@@FBSD_1.0'":

/bin/sh ./libtool --silent --mode=link /usr/bin/clang -v -target armv6--freebsd11.0-gnueabi -march=armv7-a -mcpu=cortex-a7 -mfloat-abi=softfp -mno-unaligned-access -I./lib -I. -pipe -mfloat-abi=softfp  -g -fno-strict-aliasing -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions  -DHAVE_EXPAT_CONFIG_H -no-undefined -version-info 7:0:6 -rpath /usr/local/lib  -o libexpat.la lib/xmlparse.lo lib/xmltok.lo lib/xmlrole.lo
FreeBSD clang version 3.7.1 (tags/RELEASE_371/final 255217) 20151225
Target: armv6--freebsd11.0-gnueabi
Thread model: posix
 "/usr/bin/ld" --eh-frame-hdr -Bshareable --hash-style=both --enable-new-dtags -o .libs/libexpat.so.1.6.0 /usr/lib/crti.o /usr/lib/crtbeginS.o -L/usr/lib lib/.libs/xmlparse.o lib/.libs/xmltok.o lib/.libs/xmlrole.o -soname libexpat.so.1 -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtendS.o /usr/lib/crtn.o
/usr/bin/ld: lib/.libs/xmlparse.o(.text+0x198): unresolvable R_ARM_MOVW_ABS_NC relocation against symbol `malloc@@FBSD_1.0'
/usr/bin/ld: final link failed: Nonrepresentable section on output
clang: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
make[1]: stopped in /usr/obj/portswork/usr/ports/textproc/expat2/work/expat-2.1.0
*** Error code 1



For reference: here is one of the prior C compiles (xmlparse.c -> xmlparse.o as referenced in the failure):

/bin/sh ./libtool --silent --mode=compile /usr/bin/clang -v -target armv6--freebsd11.0-gnueabi -march=armv7-a -mcpu=cortex-a7 -mfloat-abi=softfp -mno-unaligned-access -I./lib -I. -pipe -mfloat-abi=softfp  -g -fno-strict-aliasing -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions  -DHAVE_EXPAT_CONFIG_H -o lib/xmlparse.lo -c lib/xmlparse.c
FreeBSD clang version 3.7.1 (tags/RELEASE_371/final 255217) 20151225
Target: armv6--freebsd11.0-gnueabi
Thread model: posix
 "/usr/bin/clang" -cc1 -triple armv7--freebsd11.0-gnueabi -emit-obj -mrelax-all -disable-free -main-file-name xmlparse.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -relaxed-aliasing -masm-verbose -mconstructor-aliases -target-cpu cortex-a7 -target-feature +soft-float-abi -target-abi aapcs-linux -mfloat-abi soft -backend-option -arm-strict-align -v -gdwarf-2 -dwarf-column-info -coverage-file /usr/obj/portswork/usr/ports/textproc/expat2/work/expat-2.1.0/xmlparse.c -resource-dir /usr/bin/../lib/clang/3.7.1 -D HAVE_EXPAT_CONFIG_H -I ./lib -I . -Wall -Wmissing-prototypes -Wstrict-prototypes -fdebug-compilation-dir /usr/obj/portswork/usr/ports/textproc/expat2/work/expat-2.1.0 -ferror-limit 19 -fmessage-length 200 -mstackrealign -fno-signed-char -fobjc-runtime=gnustep -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o xmlparse.o -x c lib/xmlparse.c
clang -cc1 version 3.7.1 based upon LLVM 3.7.1 default target armv6--freebsd11.0-gnueabi
#include "..." search starts here:
#include <...> search starts here:
 ./lib
 .
 /usr/bin/../lib/clang/3.7.1/include
 /usr/include
End of search list.
Comment 1 Mark Millard 2016-01-05 04:04:07 UTC
Investigating the issue I had the portmaster activity use the /usr/local/arm-gnueabi-freebsd/bin/ tools instead (via /etc/make.conf changes) and in that context the message is different but it was still an error:

relocation R_ARM_MOVW_ABS_NC against `malloc' can not be used when making a shared object; recompile with -fPIC


Trying again with -fPIC does let the portmaster command complete in this /usr/local/arm-gnueabi-freebsd/bin/ based tool context.


Going back and trying -fPIC in the /usr/bin/ based tools context also lets the portmaster command complete. (That context without -fPIC did not directly indicate to try -fPIC in its messages.)


So maybe part of the issue is having compiler arguments like -fPIC show up in commands for contexts like -march=armv7-a -mcpu=cortex-a7 without manual intervention in each case. For ports: some parts of a more complicated port might needed such and other parts might not.


FYI: The detailed /usr/local/arm-gnueabi-freebsd/bin/ld invocation that reported that other error mentioning -fPIC was:

/bin/sh ./libtool --silent --mode=link /usr/bin/clang -v -target armv6--freebsd11.0-gnueabi -march=armv7-a -mcpu=cortex-a7 -mfloat-abi=softfp -mno-unaligned-access -B/usr/local/arm-gnueabi-freebsd/bin -I./lib -I. -pipe -mfloat-abi=softfp  -g -fno-strict-aliasing -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions  -DHAVE_EXPAT_CONFIG_H -no-undefined -version-info 7:0:6 -rpath /usr/local/lib  -o libexpat.la lib/xmlparse.lo lib/xmltok.lo lib/xmlrole.lo
FreeBSD clang version 3.7.1 (tags/RELEASE_371/final 255217) 20151225
Target: armv6--freebsd11.0-gnueabi
Thread model: posix
 "/usr/local/arm-gnueabi-freebsd/bin/ld" --eh-frame-hdr -Bshareable --hash-style=both --enable-new-dtags -o .libs/libexpat.so.1.6.0 /usr/lib/crti.o /usr/lib/crtbeginS.o -L/usr/lib lib/.libs/xmlparse.o lib/.libs/xmltok.o lib/.libs/xmlrole.o -soname libexpat.so.1 -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtendS.o /usr/lib/crtn.o
/usr/local/arm-gnueabi-freebsd/bin/ld: lib/.libs/xmlparse.o: relocation R_ARM_MOVW_ABS_NC against `malloc' can not be used when making a shared object; recompile with -fPIC
lib/.libs/xmlparse.o: error adding symbols: Bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1
Comment 2 Mark Millard 2016-01-05 19:19:11 UTC
Ian Lapore reports the correct interpretation of what I saw is that textproc/expat2 needs to be fixed for how it is built:

All of this is a complex way of saying "there is a bug in the expat2
port" (that being that it tries to build a shared library from object
files that were compiled without -fpic).

Adding -fpic via make.conf is absolutely not a fix or even a marginally
viable workaround.

-- Ian
Comment 3 Mark Millard 2016-01-11 13:01:19 UTC
Looks like using -v on clang/clang++ command lines messes up autoconf/libtool figuring things out: I had -v in the $(CC) and $(CXX) text.

The overall result was that -fpic/-fPIC and the like were not being used because of teh options being classified as not-available.