Bug 219524

Summary: devel/libunwind: ld: cannot preempt symbol '_Ux86_64_init_local' (WITH_LLD_IS_LD)
Product: Ports & Packages Reporter: O. Hartmann <ohartmann>
Component: Individual Port(s)Assignee: Po-Chuan Hsieh <sunpoet>
Status: Closed FIXED    
Severity: Affects Many People CC: ale, bagas1983, bretislav.kubesa, bugzilla.freebsd, citrin+pr, danilo, emaste, freebsd, iron.udjin, sunpoet, w.schwarzenfeld
Priority: --- Keywords: patch
Version: LatestFlags: bugzilla: maintainer-feedback? (sunpoet)
Hardware: Any   
OS: Any   
See Also: https://bugs.llvm.org/show_bug.cgi?id=31476
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=214864
Bug Depends on: 246390    
Bug Blocks:    
Attachments:
Description Flags
devel/libunwind: set LLD_UNSAFE
none
svn-diff-libunwind_1.3.1
none
svn-diff-libunwind_1.3.1_v2
none
svn-diff-libunwind_1.3.1_v3
none
svn-diff-libunwind_1.3.1_v4
none
svn-diff-libunwind_v5 none

Description O. Hartmann 2017-05-25 10:58:12 UTC
On recent CURRENT (12.0-CURRENT #0 r318861: Thu May 25 10:54:04 CEST 2017 amd64, with setting WITH_LLD_IS_LD=YES), the port bails out and fails to compile, see below. After ino64 has been introduced, I'd like to recompile everything necessary for xorg (portmaster -f), but the port fails to build.


libtool: link: cc -O2 -pipe -O3 -fstack-protector -fno-strict-aliasing -fexceptions -Wall -Wsign-compare -fstack-protector -o .libs/Gperf-simple Gperf-simple.o  ../src/.libs/libunwind-x86_64.so /usr/ports/devel/libunwind/work/libunwind-1.2/src/.libs/libunwind.so ../src/.libs/libunwind.so -lgcc_s -llzma -Wl,-rpath -Wl,/usr/local/lib
--- mapper ---
libtool: link: cc -O2 -pipe -O3 -fstack-protector -fno-strict-aliasing -fexceptions -Wall -Wsign-compare -fstack-protector -o mapper mapper.o 
--- Gperf-simple ---
/usr/bin/ld: error: Gperf-simple.c:(function main): cannot preempt symbol '_Ux86_64_init_local' defined in ../src/.libs/libunwind-x86_64.so
/usr/bin/ld: error: Gperf-simple.c:(function main): cannot preempt symbol '_Ux86_64_init_local' defined in ../src/.libs/libunwind-x86_64.so
/usr/bin/ld: error: Gperf-simple.c:(function main): cannot preempt symbol '_Ux86_64_local_addr_space' defined in ../src/.libs/libunwind-x86_64.so
/usr/bin/ld: error: Gperf-simple.c:(function main): cannot preempt symbol '_Ux86_64_set_caching_policy' defined in ../src/.libs/libunwind-x86_64.so
/usr/bin/ld: error: Gperf-simple.c:(function main): cannot preempt symbol '_Ux86_64_local_addr_space' defined in ../src/.libs/libunwind-x86_64.so
/usr/bin/ld: error: Gperf-simple.c:(function main): cannot preempt symbol '_Ux86_64_set_caching_policy' defined in ../src/.libs/libunwind-x86_64.so
/usr/bin/ld: error: Gperf-simple.c:(function main): cannot preempt symbol '_Ux86_64_local_addr_space' defined in ../src/.libs/libunwind-x86_64.so
/usr/bin/ld: error: Gperf-simple.c:(function main): cannot preempt symbol '_Ux86_64_set_caching_policy' defined in ../src/.libs/libunwind-x86_64.so
/usr/bin/ld: error: Gperf-simple.c:(function measure_unwind): cannot preempt symbol '_Ux86_64_init_local' defined in ../src/.libs/libunwind-x86_64.so
/usr/bin/ld: error: Gperf-simple.c:(function measure_unwind): cannot preempt symbol '_Ux86_64_step' defined in ../src/.libs/libunwind-x86_64.so
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** [Gperf-simple] Error code 1

make[2]: stopped in /usr/ports/devel/libunwind/work/libunwind-1.2/tests
3 errors
Comment 1 Danilo Egea Gondolfo freebsd_committer freebsd_triage 2017-05-25 14:06:06 UTC
Was it linking with LLD before ino64?
Comment 2 O. Hartmann 2017-05-28 14:38:04 UTC
I can not say. I updated/installed the port on that specific box on 19th of April this year: 


Name           : libunwind
Version        : 20170113
Installed on   : Wed Apr 19 20:36:45 2017 CEST
Origin         : devel/libunwind
Architecture   : FreeBSD:12:amd64


I use WITH_LLD_IS_LD a while, but the use could be close to that date.

I check on another box which has also WITH_LLD_IS_LD set, but I prevented it from being updated to ino64.
Comment 3 O. Hartmann 2017-06-09 06:04:20 UTC
(In reply to Danilo Egea Gondolfo from comment #1)


It seems to be very tricky and weird, not to say mysterious.

On any box running the most recent 12-CURRENT (as of today, that is r319732: Fri Jun  9 06:27:15 CEST 2017 amd64), those with processor architectures less than Haswell fail (sic!).

Testing on a notebook with a i4200M (Lenovo Thinkpad E540) reveals nothing unusual. Another box, equipted with a   Xeon(R) CPU E5-1650 v3 @ 3.50GHz (Fujitsu Celsius M740) does also show nothing unsusual, on both poudriere and /usr/ports tree, devel/libunwind builds as expected.

Two other boxes, both equipted with IvyBridge architectures (one is a Intel(R) Xeon(R) CPU E3-1245 V2 @ 3.40GHz), the other has i3-32XX something (2-core, consumer grade stuff, box isn't running at this very moment) the port doesn't compile either in poudriere or /usr/ports and shows the error reported.

Another server, oldish Core2Duo, Fujitsu, two sockets with  Intel(R) Xeon(R) CPU           L5420  @ 2.50GHz, does also fail in the reported ways.

All boxes have in common WITH_LLD_IS_LD=yes. It doesn't matter wether the host carrying the jail's OS  has been compiled with -O3 or -O2, the jails, always the most recent 12-CURRENT as the host's kernel itself, use no other optimisations than the standard vanilla settings, but I suppose the linker is LLD also as it is provided by the base and the jail's base is derived/installed from /usr/src, so it is identical to the hosts's system.

Just for the record. I guess LLVM 4.0 has serious issues with different architectures, as it seems to me.
Comment 4 Trond Endrestøl 2017-07-15 17:13:52 UTC
(In reply to O. Hartmann from comment #3)
I too experienced this on base/head r321008 amd64.
I got away by creating a Makefile.local file containing USE_GCC=yes.
Note, this requires lang/gcc5 which might be undesireable for some.
Comment 5 Ed Maste freebsd_committer freebsd_triage 2017-07-27 13:28:27 UTC
There are three possible workarounds at the moment:

1. Force -fPIC on, as in https://github.com/emaste/freebsd-ports/commit/4857444b31ca546e29e221dce2a41092765e6062

For testing in a checkout of the upstream repository I used:
% CFLAGS=-fPIC CC=clang ./configure && gmake && gmake check
but the test suite has some issues; unsure if they exist in stock HEAD, 11.x, etc.

2. Disable __attribute__((visibility ("protected"))):

diff --git a/include/compiler.h b/include/compiler.h
index abd424d..6835844 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -40,7 +40,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 # if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ > 2)
 #  define ALWAYS_INLINE inline __attribute__((always_inline))
 #  define HIDDEN        __attribute__((visibility ("hidden")))
-#  define PROTECTED     __attribute__((visibility ("protected")))
+#  define PROTECTED
 # else
 #  define ALWAYS_INLINE
 #  define HIDDEN

3. Force use of ld.bfd to link

% LDFLAGS=-fuse-ld=bfd CC=clang ./configure && gmake && gmake check
Comment 6 Ed Maste freebsd_committer freebsd_triage 2017-07-27 13:45:53 UTC
Note that gold also fails with this case:

% LDFLAGS=-fuse-ld=gold CC=clang ./configure && gmake
...
/bin/sh ../libtool  --tag=CC   --mode=link clang  -g -O2 -fexceptions -Wall -Wsign-compare  -fuse-ld=gold -o Gperf-simple Gperf-simple.o ../src/libunwind-x86_64.la ../src/libunwind.la 
libtool: link: clang -g -O2 -fexceptions -Wall -Wsign-compare -fuse-ld=gold -o .libs/Gperf-simple Gperf-simple.o  ../src/.libs/libunwind-x86_64.so /home/emaste/src/libunwind/src/.libs/libunwind.so ../src/.libs/libunwind.so -lgcc_s -llzma -Wl,-rpath -Wl,/usr/local/lib
/usr/local/bin/ld.gold: error: Gperf-simple.o: cannot make copy relocation for protected symbol '_Ux86_64_local_addr_space', defined in ../src/.libs/libunwind-x86_64.so
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 7 Ed Maste freebsd_committer freebsd_triage 2017-08-22 20:15:13 UTC
Created attachment 185678 [details]
devel/libunwind: set LLD_UNSAFE
Comment 8 commit-hook freebsd_committer freebsd_triage 2017-12-19 18:07:29 UTC
A commit references this bug:

Author: emaste
Date: Tue Dec 19 18:06:30 UTC 2017
New revision: 456743
URL: https://svnweb.freebsd.org/changeset/ports/456743

Log:
  devel/libunwind: set LLD_UNSAFE

  libunwind.so has symbols with ELF protected visibility which various
  test applications could preempt. Both GNU gold and LLVM's lld fail to
  link this case, with errors like

  lld:
  /usr/bin/ld: error: cannot preempt symbol: _ULx86_64_init_local
  >>> defined in ../src/.libs/libunwind.so
  >>> referenced by Lperf-trace.c
  >>>               Lperf-trace.o:(main)

  gold:
  /usr/local/bin/ld.gold: error: Gperf-simple.o: cannot make copy relocation
      for protected symbol '_Ux86_64_local_addr_space', defined in
      ../src/.libs/libunwind-x86_64.so

  For now prevent libunwind from linking with lld. More information can be
  found in libunwind upstream issue 58
  https://github.com/libunwind/libunwind/issues/58

  PR:		219524
  Approved by:	portmgr (LLD_UNSAFE blanket)
  Sponsored by:	The FreeBSD Foundation

Changes:
  head/devel/libunwind/Makefile
Comment 9 Walter Schwarzenfeld freebsd_triage 2018-03-12 22:15:14 UTC
Forgotten to close?
Comment 10 Ed Maste freebsd_committer freebsd_triage 2018-03-13 01:12:56 UTC
LLD_UNSAFE is a workaround but the underlying issue still exists. It has been fixed upstream and so should be in the next release.
Comment 11 Ed Maste freebsd_committer freebsd_triage 2018-03-27 20:38:03 UTC
(We should test the port with LLD_UNSAFE removed after the next update.)
Comment 12 O. Hartmann 2018-03-30 06:49:31 UTC
With recent CURRENT (FreeBSD 12.0-CURRENT #220 r331732: Thu Mar 29 16:56:41 CEST 2018 amd64) and the follwoing set in /etc/src.conf:
[...]
WITH_LLDB=              YES
WITH_LLD_IS_LD=         YES

the port devel/libunwind with ports tree revision 465861 builds and installs for me.
Comment 13 Harald Schmalzbauer 2018-07-02 22:04:27 UTC
The exactly same issue is back for me here.

Compiling X11-dependencies on haswell and r335236 (12-current from Jun 16th) stops in devel/libunwind:

libtool: link: cc -O2 -pipe -fstack-protector -fno-strict-aliasing -fexceptions -Wall -Wsign-compare -fstack-protector -o forker forker.o 
depbase=`echo Gperf-simple.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`; cc -DHAVE_CONFIG_H -I. -I../include  -I../include  -D_GNU_SOURCE -DNDEBUG  -O2 -pipe  -fstack-protector -fno-strict-aliasing -fexceptions -Wall -Wsign-compare -MT Gperf-simple.o -MD -MP -MF $depbase.Tpo -c -o Gperf-simple.o Gperf-simple.c && mv -f $depbase.Tpo $depbase.Po
/bin/sh ../libtool  --tag=CC    --mode=link cc  -O2 -pipe  -fstack-protector -fno-strict-aliasing -fexceptions -Wall -Wsign-compare   -fstack-protector -o Gperf-simple Gperf-simple.o ../src/libunwind-x86_64.la ../src/libunwind.la 
libtool: link: cc -O2 -pipe -fstack-protector -fno-strict-aliasing -fexceptions -Wall -Wsign-compare -fstack-protector -o .libs/Gperf-simple Gperf-simple.o  ../src/.libs/libunwind-x86_64.so /usr/local/ports-wrktree/nul/deployment/OS-Resources/FreeBSD/OmniLAN/ports/ports/devel/libunwind/work/libunwind-1.2.1/src/.libs/libunwind.so ../src/.libs/libunwind.so -lgcc_s -llzma -Wl,-rpath -Wl,/usr/local/lib
/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_init_local
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)

/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_init_local
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)
… Snipping same as above

I can't tell any more, I'm completely lost with lld and the complete toolchain.

Just can report that "LLD_UNSAFE=     yes" in devel/libunwind/Makefile doesn't seem to have the desired effect here :-(

Thanks,

-harry
Comment 14 Harald Schmalzbauer 2018-08-01 09:19:55 UTC
Since this issue persists unchanged for me, it had to be a local problem, otherwise many more would have reported problems.

So I tried to find the cause, with success: I'm building inside a jail where /usr/bin is a symlink to /.sharedbase/usr/bin.
This breaks
.if defined(LLD_UNSAFE) && ${/usr/bin/ld:L:tA} == /usr/bin/ld.lld
in Mk/bsd.port.mk.  

Since I have no idea why the realpath(3) check to /usr/bin/ld.lld is done, I can't propose a patch; most likely it's for FreeBSD < 12, resp. base compiler variants?
Localy, I simply removed the the &&ed condition and devel/libunwind compiles fine.

-harry
Comment 15 Ed Maste freebsd_committer freebsd_triage 2018-09-05 13:00:09 UTC
(In reply to Harald Schmalzbauer from comment #14)
Yes, the intent of the check is to apply the lld workaround only when needed (when lld is the system linker) -- older versions, and with WITHOUT_LLD_IS_LD set.

Can you give this change a try:

diff --git a/Mk/bsd.port.mk b/Mk/bsd.port.mk
index 89d82591ece7..2597c72ccd3d 100644
--- a/Mk/bsd.port.mk
+++ b/Mk/bsd.port.mk
@@ -1841,7 +1841,7 @@ PKG_DEPENDS+=     ${LOCALBASE}/sbin/pkg:${PKG_ORIGIN}
 .include "${PORTSDIR}/Mk/bsd.gcc.mk"
 .endif
 
-.if defined(LLD_UNSAFE) && ${/usr/bin/ld:L:tA} == /usr/bin/ld.lld
+.if defined(LLD_UNSAFE) && ${/usr/bin/ld:L:tA:T} == ld.lld
 LDFLAGS+=      -fuse-ld=bfd
 BINARY_ALIAS+= ld=${LD}
 .  if !defined(USE_BINUTILS)
Comment 16 Alex Dupre freebsd_committer freebsd_triage 2019-03-01 11:11:45 UTC
It looks like latest libunwind 1.3.1 release may have fixed the issue
Comment 17 Ed Maste freebsd_committer freebsd_triage 2019-03-04 17:43:03 UTC
v1.3.1 includes this commit:

commit 304f9ea971be33c790e1f28f1b268f6c73458183
Author: Dave Watson <davejwatson@fb.com>
Date:   Thu Dec 28 08:26:42 2017 -0800

    Remove PROTECTED visibility
    
    This only works on bfd ld, not lld or gold.
Comment 18 Ed Maste freebsd_committer freebsd_triage 2019-03-04 17:45:12 UTC
Ports tree still has 1.2.1; PR can be closed after update to 1.3.1.
Comment 19 bagas 2019-09-02 15:45:07 UTC
Hello.
My system FreeBSD 12.0-RELEASE-p9 amd64
Start the new jail.
Ports updated.
Install the port portupgrade-2.4.16,2
When installing ports an error, how to fix it?

cat /etc/make.conf 
MAKE_JOBS_UNSAFE=yes

root@terra_test:/usr/ports/ports-mgmt/portupgrade # make install clean
===>  License BSD3CLAUSE accepted by the user
===>   portupgrade-2.4.16,2 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by portupgrade-2.4.16,2 for building
===>  Extracting for portupgrade-2.4.16,2
=> SHA256 Checksum OK for portupgrade/freebsd-portupgrade-2.4.16_GH0.tar.gz.
===>   portupgrade-2.4.16,2 depends on file: /usr/local/bin/ruby25 - not found
===>   ruby-2.5.5_3,1 depends on package: libffi>=0 - found
===>   ruby-2.5.5_3,1 depends on package: autoconf>=2.69 - found
===>   ruby-2.5.5_3,1 depends on package: automake>=1.16.1 - found
===>   ruby-2.5.5_3,1 depends on shared library: libyaml.so - found (/usr/local/lib/libyaml.so)
===>   ruby-2.5.5_3,1 depends on shared library: libedit.so.0 - found (/usr/local/lib/libedit.so.0)
===>   ruby-2.5.5_3,1 depends on shared library: libunwind.so - not found
===>  Building for libunwind-20170615
Making all in src
/usr/bin/make  all-am
Making all in tests
/bin/sh ../libtool  --tag=CC    --mode=link cc  -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing  -fexceptions -Wall -Wsign-compare   -fstack-protector-strong -o Gperf-simple Gperf-simple.o ../src/libunwind-x86_64.la ../src/libunwind.la 
libtool: link: cc -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -fexceptions -Wall -Wsign-compare -fstack-protector-strong -o .libs/Gperf-simple Gperf-simple.o  ../src/.libs/libunwind-x86_64.so /usr/ports/devel/libunwind/work/libunwind-1.2.1/src/.libs/libunwind.so ../src/.libs/libunwind.so -lgcc_s -llzma -Wl,-rpath -Wl,/usr/local/lib
/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_init_local
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)

/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_init_local
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)

/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_local_addr_space
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)

/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_set_caching_policy
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)

/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_local_addr_space
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)

/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_set_caching_policy
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)

/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_local_addr_space
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)

/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_set_caching_policy
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)

/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_init_local
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(measure_unwind)

/usr/bin/ld: error: cannot preempt symbol: _Ux86_64_step
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(measure_unwind)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
make[7]: stopped in /usr/ports/devel/libunwind/work/libunwind-1.2.1/tests
*** Error code 1

Stop.
make[6]: stopped in /usr/ports/devel/libunwind/work/libunwind-1.2.1
*** Error code 1

Stop.
make[5]: stopped in /usr/ports/devel/libunwind
*** Error code 1

Stop.
make[4]: stopped in /usr/ports/devel/libunwind
*** Error code 1

Stop.
make[3]: stopped in /usr/ports/lang/ruby25
*** Error code 1

Stop.
make[2]: stopped in /usr/ports/lang/ruby25
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/ports-mgmt/portupgrade
*** Error code 1

Stop.
make: stopped in /usr/ports/ports-mgmt/portupgrade
root@terra_test:/usr/ports/ports-mgmt/portupgrade #
Comment 20 Walter Schwarzenfeld freebsd_triage 2019-09-02 16:19:48 UTC
(In reply to Ed Maste from comment #18)
Version 1.3.1 is released:


https://github.com/libunwind/libunwind/releases
Comment 21 bagas 2019-09-02 16:25:21 UTC
There is no such version in ports Version 1.3.1 is released.
Only libunwind-1.2.1.
Comment 22 Walter Schwarzenfeld freebsd_triage 2019-09-02 16:29:58 UTC
No, it is not in the port. It is need updated to 1.3.1.
Comment 23 bagas 2019-09-02 16:32:23 UTC
Not understood.
And how do I libunwind update?
On top of the package manager, compile manually?
Comment 24 Walter Schwarzenfeld freebsd_triage 2019-09-02 16:38:59 UTC
You don't have to try. It is job of the maintainer.

(In the moment I try it. Let's wait for the patch. Who ever is faster).
Comment 25 bagas 2019-09-02 16:40:15 UTC
Of course I'll wait!
Comment 26 Walter Schwarzenfeld freebsd_triage 2019-09-02 17:08:06 UTC
Created attachment 207111 [details]
svn-diff-libunwind_1.3.1

Proposed update patch to 1.3.1. Please, try this.
Comment 27 Walter Schwarzenfeld freebsd_triage 2019-09-02 17:14:10 UTC
Comment on attachment 207111 [details]
svn-diff-libunwind_1.3.1

Just a moment , something went wrong.
Comment 28 Walter Schwarzenfeld freebsd_triage 2019-09-02 17:21:12 UTC
Created attachment 207112 [details]
svn-diff-libunwind_1.3.1_v2

This should work.
Comment 29 Walter Schwarzenfeld freebsd_triage 2019-09-02 17:25:41 UTC
Created attachment 207113 [details]
svn-diff-libunwind_1.3.1_v3

Was a typo in.
Comment 30 Walter Schwarzenfeld freebsd_triage 2019-09-02 17:32:23 UTC
No really ChangeLog, but ${WRKSRC}/NEWS shows:

* News for v1.3:

** Iteration of unwind register states support
   Doug Moore <dougm@rice.edu>
** Freebsd/Armv6 support
   Konstantin Belousov <kib@freebsd.org>
** Many, many dwarf bugfixes
** Mips remote unwind support
** aarch64 ptrace support
Comment 31 Walter Schwarzenfeld freebsd_triage 2019-09-02 17:58:05 UTC
Created attachment 207116 [details]
svn-diff-libunwind_1.3.1_v4

Correct Portversion.
Comment 32 bagas 2019-09-03 08:08:13 UTC
roo@terra_test:/usr/ports/devel/libunwind # make install clean
===>  Building for libunwind-1.3.1
make[2]: cannot open Makefile.

make[2]: stopped in /usr/ports/devel/libunwind/work/libunwind-1.3.1
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/devel/libunwind
*** Error code 1

Stop.
make: stopped in /usr/ports/devel/libunwind
root@terra_test:/usr/ports/devel/libunwind #
Comment 33 bagas 2019-09-03 08:19:20 UTC
/usr/ports/devel/libunwind # egrep -v '#|^$' Makefile
PORTNAME=	libunwind
PORTVERSION=	1.3.1
CATEGORIES=	devel
MASTER_SITES=	SAVANNAH
MAINTAINER=	danilo@FreeBSD.org
COMMENT=	Generic stack unwinding library
LICENSE=	MIT
LICENSE_FILE=	${WRKSRC}/COPYING
ONLY_FOR_ARCHS= aarch64 amd64 i386
OPTIONS_DEFINE=	DOCS
OPTIONS_SUB=	yes
DOCS_CONFIGURE_ON=	ac_cv_path_LATEX2MAN=${TRUE}
DOCS_CONFIGURE_OFF=	--disable-documentation
USES=		libtool pathfix pkgconfig
USE_LDCONFIG=	yes
GNU_CONFIGURE=	yes
INSTALL_TARGET=	install-strip
LLD_UNSAFE=	yes
PLIST_SUB=	ARCH=${ARCH:S|i386|x86|:S|amd64|x86_64|}
.include <bsd.port.mk>

###
TIMESTAMP = 1567446744
SHA256 (libunwind-1.3.1.tar.gz) = 43997a3939b6ccdf2f669b50fdb8a4d3205374728c2923ddc2354c65260214f8
SIZE (libunwind-1.3.1.tar.gz) = 801262

###
/usr/ports/devel/libunwind # egrep -v '#|^$' files/patch-include_libunwind-aarch64.h
--- include/libunwind-aarch64.h.orig	2019-09-02 17:16:29 UTC
+++ include/libunwind-aarch64.h
@@ -177,7 +177,7 @@ typedef ucontext_t unw_tdep_context_t;
 
 #define unw_tdep_getcontext(uc) (({					\
   unw_tdep_context_t *unw_ctx = (uc);					\
-  register uint64_t *unw_base asm ("x0") = (uint64_t*) unw_ctx->uc_mcontext.regs;		\
+  register uint64_t *unw_base asm ("x0") = (uint64_t*) unw_ctx->uc_mcontext.mc_gpregs.gp_x;		\
   __asm__ __volatile__ (						\
      "stp x0, x1, [%[base], #0]\n" \
      "stp x2, x3, [%[base], #16]\n" \			

###
/usr/ports/devel/libunwind # egrep -v '#|^$' files/patch-include_libunwind__i.h
--- files/patch-include_libunwind__i.h	(revision 510820)
+++ files/patch-include_libunwind__i.h	(nonexistent)
@@ -1,14 +0,0 @@
---- include/libunwind_i.h.orig	2018-06-15 23:58:15 UTC
-+++ include/libunwind_i.h
-@@ -86,6 +86,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
- #   error Host has unknown byte-order.
- # endif
- #endif
-+#ifdef __FreeBSD__
-+#define __BYTE_ORDER BYTE_ORDER
-+#define __LITTLE_ENDIAN LITTLE_ENDIAN
-+#define __BIG_ENDIAN BIG_ENDIAN
-+#endif
- 
- #if defined(HAVE__BUILTIN_UNREACHABLE)
- # define unreachable() __builtin_unreachable()
Deleted: fbsd:nokeywords
## -1 +0,0 ##
-yes
\ No newline at end of property
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property

###
/usr/ports/devel/libunwind # egrep -v '#|^$' files/patch-src_aarch64_Ginit.c
--- files/patch-src_aarch64_Ginit.c	(revision 510820)
+++ files/patch-src_aarch64_Ginit.c	(working copy)
@@ -1,11 +1,11 @@
---- src/aarch64/Ginit.c.orig	2018-06-15 23:58:20 UTC
+--- src/aarch64/Ginit.c.orig	2019-09-02 16:52:44 UTC
 +++ src/aarch64/Ginit.c
 @@ -44,7 +44,7 @@ static inline void *
  uc_addr (ucontext_t *uc, int reg)
  {
-   if (reg >= UNW_AARCH64_X0 && reg <= UNW_AARCH64_V31)
+   if (reg >= UNW_AARCH64_X0 && reg < UNW_AARCH64_V0)
 -    return &uc->uc_mcontext.regs[reg];
 +    return &uc->uc_mcontext.mc_gpregs.gp_x[reg];
+   else if (reg >= UNW_AARCH64_V0 && reg <= UNW_AARCH64_V31)
+     return &GET_FPCTX(uc)->vregs[reg - UNW_AARCH64_V0];
    else
-     return NULL;
- }



###
/usr/ports/devel/libunwind # egrep -v '#|^$' files/patch-src_coredump___UCD__access__reg_freebsd.c
--- files/patch-src_coredump___UCD__access__reg_freebsd.c	(nonexistent)
+++ files/patch-src_coredump___UCD__access__reg_freebsd.c	(working copy)
@@ -0,0 +1,13 @@
+--- src/coredump/_UCD_access_reg_freebsd.c.orig	2019-09-02 16:42:43 UTC
++++ src/coredump/_UCD_access_reg_freebsd.c
+@@ -129,6 +129,10 @@ _UCD_access_reg (unw_addr_space_t as,
+        return -UNW_EINVAL;
+      }
+   }
++#elif defined(UNW_TARGET_AARCH64)
++  if (regnum < 0 || regnum >= UNW_AARCH64_FPCR)
++    return -UNW_EINVAL;
++  *valp = ui->prstatus->pr_reg.x[regnum];
+ #else
+ #error Port me
+ #endif
Added: fbsd:nokeywords
## -0,0 +1 ##
+yes
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property

###
:/usr/ports/devel/libunwind # egrep -v '^$' files/patch-src_ptrace___UPT__access_fpreg.c
--- files/patch-src_ptrace___UPT__access_fpreg.c	(nonexistent)
+++ files/patch-src_ptrace___UPT__access_fpreg.c	(working copy)
@@ -0,0 +1,20 @@
+--- src/ptrace/_UPT_access_fpreg.c.orig	2019-09-02 16:56:31 UTC
++++ src/ptrace/_UPT_access_fpreg.c
+@@ -84,6 +84,8 @@ _UPT_access_fpreg (unw_addr_space_t as, 
+ #elif defined(__arm__)
+   if ((unsigned) reg < UNW_ARM_F0 || (unsigned) reg > UNW_ARM_F7)
+     return -UNW_EBADREG;
++#elif defined(__aarch64__)
++          memcpy(&fpreg.fp_q[reg], val, sizeof(unw_fpreg_t));
+ #else
+ #error Fix me
+ #endif
+@@ -99,6 +101,8 @@ _UPT_access_fpreg (unw_addr_space_t as, 
+           memcpy(&fpreg.fpr_acc[reg], val, sizeof(unw_fpreg_t));
+ #elif defined(__arm__)
+           memcpy(&fpreg.fpr[reg], val, sizeof(unw_fpreg_t));
++#elif defined(__aarch64__)
++          memcpy(val, &fpreg.fp_q[reg], sizeof(unw_fpreg_t));
+ #else
+ #error Fix me
+ #endif
Added: fbsd:nokeywords
## -0,0 +1 ##
+yes
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property

###
--- files/patch-tests-mapper.c	(revision 510820)
+++ files/patch-tests-mapper.c	(nonexistent)
@@ -1,12 +0,0 @@
---- tests/mapper.c.orig	2014-10-06 14:46:27.000000000 -0400
-+++ tests/mapper.c	2014-10-06 14:47:00.000000000 -0400
-@@ -39,6 +39,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DE
- #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
- # define MAP_ANONYMOUS MAP_ANON
- #endif
-+#if !defined(MAP_NORESERVE)
-+# define MAP_NORESERVE 0
-+#endif
- 
- int
- main (void)
Deleted: fbsd:nokeywords
## -1 +0,0 ##
-yes
\ No newline at end of property
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property

Maybe I'm doing something wrong?
I last patched ports a very long time ago, I don’t remember exactly how this is done.
Comment 34 bagas 2019-09-03 08:21:04 UTC
The libunwind-1.3.1 archive downloaded from here.
https://www.nongnu.org/libunwind/
Comment 35 Walter Schwarzenfeld freebsd_triage 2019-09-03 11:29:54 UTC
Comment on attachment 207116 [details]
svn-diff-libunwind_1.3.1_v4

There is any svn error in, I did not find in the moment.
Comment 36 bagas 2019-09-03 12:25:13 UTC
There is hope of updating port libunwind 1.3.1 to use jail on FreeBSD 12?
Comment 37 Walter Schwarzenfeld freebsd_triage 2019-09-04 16:42:50 UTC
Created attachment 207188 [details]
svn-diff-libunwind_v5

(Test build with mesa-dri, mesa-lib,, xorg-server, gimp-app, ruby25,gstreamer1 works).
Comment 38 bagas 2019-09-04 16:54:52 UTC
it works.
ruby-2.5.6,1                       =
ruby25-bdb-0.6.6_6                 =
Comment 39 Danilo Egea Gondolfo freebsd_committer freebsd_triage 2019-09-15 10:20:05 UTC
Thank you for your patch. Although it's not building either on aarch64 or armv6. I'm trying to look at it.
Comment 40 bagas 2019-09-20 17:52:22 UTC
When will the updated libunwind port appear in the ports?
Comment 41 B.K. 2019-12-21 17:15:33 UTC
Thank you - finally SQUID 4.9 builds fine when manually applying your patch.

FreeBSD 12.0-RELEASE-p12 GENERIC
Comment 42 bagas 2020-03-14 07:59:53 UTC
Hello.
I tried to transfer jail from FreeBSD 11.3 to FreeBSD 12.1
Old system FreeBSD 11.3-RELEASE-p6 amd64.
New system FreeBSD 12.1-RELEASE-p2 amd64.

Is it really impossible to fix the port, a year has passed since the problem!

root@fr_test:/usr/ports/devel/libunwind # make MAKE_JOBS_UNSAFE=yes reinstall clean
===>  Deinstalling for libunwind
===>   libunwind not installed, skipping
===>  Building for libunwind-20170615
Making all in src
/usr/bin/make  all-am
Making all in tests
/bin/sh ../libtool  --tag=CC    --mode=link cc  -O -pipe  -fstack-protector-strong -fno-strict-aliasing  -fexceptions -Wall -Wsign-compare   -fstack-protector-strong -o Gperf-simple Gperf-simple.o ../src/libunwind-x86_64.la ../src/libunwind.la
libtool: link: cc -O -pipe -fstack-protector-strong -fno-strict-aliasing -fexceptions -Wall -Wsign-compare -fstack-protector-strong -o .libs/Gperf-simple Gperf-simple.o  ../src/.libs/libunwind-x86_64.so /usr/ports/devel/libunwind/work/libunwind-1.2.1/src/.libs/libunwind.so ../src/.libs/libunwind.so -lgcc_s -llzma -Wl,-rpath -Wl,/usr/local/lib
ld: error: cannot preempt symbol: _Ux86_64_local_addr_space
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)

ld: error: cannot preempt symbol: _Ux86_64_local_addr_space
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)

ld: error: cannot preempt symbol: _Ux86_64_local_addr_space
>>> defined in ../src/.libs/libunwind-x86_64.so
>>> referenced by Gperf-simple.c
>>>               Gperf-simple.o:(main)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
make[4]: stopped in /usr/ports/devel/libunwind/work/libunwind-1.2.1/tests
*** Error code 1

Stop.
make[3]: stopped in /usr/ports/devel/libunwind/work/libunwind-1.2.1
*** Error code 1

Stop.
make[2]: stopped in /usr/ports/devel/libunwind
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/devel/libunwind
*** Error code 1

Stop.
make: stopped in /usr/ports/devel/libunwind
Comment 43 Zilon 2020-04-05 09:50:21 UTC
Problem is still existing and has not been fixed in the latest update of the port.
Comment 44 iron.udjin 2020-05-15 09:48:54 UTC
Hello,

Have the same issue with devel/libunwind when I try to build it in jail. On main system it builds fine. 
Main system and jail: 12.1-STABLE r361070
Comment 45 Zilon 2020-05-17 16:19:48 UTC
Hello,

the new version libunwind-20200331 seems to build fine now. 

Thanks and BR 
Zilon
Comment 46 Po-Chuan Hsieh freebsd_committer freebsd_triage 2020-05-17 18:16:34 UTC
Thanks!