macports-ports icon indicating copy to clipboard operation
macports-ports copied to clipboard

abseil: fix build for old systems

Open barracuda156 opened this issue 1 year ago • 5 comments

Description

Preliminary fix for old systems. If anyone can test the build on PPC natively, please update me.

Type(s)
  • [x] bugfix
  • [ ] enhancement
  • [ ] security fix
Tested on

macOS 10.6.8 Xcode 3.2.6

P. S. On Rosetta the build succeeds with an extra patch, but at the moment it is ugly: https://github.com/abseil/abseil-cpp/issues/1227

Verification

Have you

  • [x] followed our Commit Message Guidelines?
  • [x] squashed and minimized your commits?
  • [x] checked that there aren't other open pull requests for the same change?
  • [ ] referenced existing tickets on Trac with full URL?
  • [x] checked your Portfile with port lint --nitpick?
  • [ ] tried existing tests with sudo port test?
  • [ ] tried a full install with sudo port -vst install?
  • [ ] tested basic functionality of all binary files?

barracuda156 avatar Jul 23 '22 14:07 barracuda156

Notifying maintainers: @judaew for port abseil.

macportsbot avatar Jul 23 '22 14:07 macportsbot

-latomic flag fixes the following error:

Undefined symbols:
  "___atomic_store_8", referenced from:
      __ZN4absl12lts_2022062313base_internal24SpinLockSuggestedDelayNSEi in spinlock_wait.cc.o
  "___atomic_load_8", referenced from:
      __ZN4absl12lts_2022062313base_internal24SpinLockSuggestedDelayNSEi in spinlock_wait.cc.o
ld: symbol(s) not found
collect2: error: ld returned 1 exit status
make[2]: *** [absl/base/libabsl_spinlock_wait.2206.0.0.dylib] Error 1
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/build'
make[1]: *** [absl/base/CMakeFiles/spinlock_wait.dir/all] Error 2

The patch fixes this:

[ 56%] Building CXX object absl/debugging/CMakeFiles/examine_stack.dir/internal/examine_stack.cc.o
cd /opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/build/absl/debugging && /opt/local/bin/g++-mp-12 -Dexamine_stack_EXPORTS -I/opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/abseil-cpp-20220623.0 -pipe -Os -DNDEBUG -I/opt/local/include -D_GLIBCXX_USE_CXX11_ABI=0 -arch ppc -mmacosx-version-min=10.6 -fPIC -Wall -Wextra -Wcast-qual -Wconversion-null -Wformat-security -Wmissing-declarations -Woverlength-strings -Wpointer-arith -Wundef -Wunused-local-typedefs -Wunused-result -Wvarargs -Wvla -Wwrite-strings -DNOMINMAX -std=gnu++14 -MD -MT absl/debugging/CMakeFiles/examine_stack.dir/internal/examine_stack.cc.o -MF CMakeFiles/examine_stack.dir/internal/examine_stack.cc.o.d -o CMakeFiles/examine_stack.dir/internal/examine_stack.cc.o -c /opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/abseil-cpp-20220623.0/absl/debugging/internal/examine_stack.cc
/opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/abseil-cpp-20220623.0/absl/debugging/internal/examine_stack.cc: In function 'void* absl::lts_20220623::debugging_internal::{anonymous}::Allocate(size_t)':
/opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/abseil-cpp-20220623.0/absl/debugging/internal/examine_stack.cc:58:34: error: 'MAP_ANONYMOUS' was not declared in this scope; did you mean 'MAP_ANON'?
   58 |                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
      |                                  ^~~~~~~~~~~~~
      |                                  MAP_ANON
/opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/abseil-cpp-20220623.0/absl/debugging/internal/examine_stack.cc: In function 'void* absl::lts_20220623::debugging_internal::GetProgramCounter(void*)':
/opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/abseil-cpp-20220623.0/absl/debugging/internal/examine_stack.cc:204:17: warning: unused variable 'signal_ucontext' [-Wunused-variable]
  204 |     ucontext_t* signal_ucontext = reinterpret_cast<ucontext_t*>(vuc);
      |                 ^~~~~~~~~~~~~~~
make[2]: *** [absl/debugging/CMakeFiles/examine_stack.dir/internal/examine_stack.cc.o] Error 1
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/build'
make[1]: *** [absl/debugging/CMakeFiles/examine_stack.dir/all] Error 2

And adds PPC to Darwin archs in the same file.

barracuda156 avatar Jul 23 '22 14:07 barracuda156

@mascguy @evanmiller Could you please check if it builds on Leopard? I suspect a patch may be needed for PPC, so that VCRYPTO is not used, and also another one to specify Darwin ppc arch. If yes, I think I know what and where to change.

barracuda156 avatar Jul 23 '22 14:07 barracuda156

A few things:

libatomic is only needed/used if building with gcc, not with clang. We’ve discussed this several places before.

the map anon stuff I added to legacysupport several years ago so you could pick that up with legacysupport

the note says this software needs libc++ with emulated_tls installed, but you deleted that…have you fixed that? If not, it’s probably still broken then on most people’s 10.6.8 with libc++ installation.

The different register names in signal is usually a 10.4 SDK thing, eg

https://github.com/macports/macports-ports/blob/c5356ad48dc76826d13b792d64e6b0fd9551c846/devel/ld64/Portfile#L440

but That one I’d have to look at more carefully to see whether what you did works as it is supposed to.

kencu avatar Jul 24 '22 01:07 kencu

@kencu Thank you for helpful comments!

libatomic is only needed/used if building with gcc, not with clang. We’ve discussed this several places before.

Yes, right. So how is it better to specify the condition? For 10.4–10.5, gcc is the default compiler. For 10.6, clang is for x86 and gcc is for ppc.

the map anon stuff I added to legacysupport several years ago so you could pick that up with legacysupport

I will try it, thank you. But in fact, I want to submit a PR to upstream, I am just waiting until someone tests the port on PPC natively, so that I know which other changes are needed.

Edit: Also the source code already has such a fix in abseil-abseil-cpp-273292d/absl/base/internal/low_level_alloc.cc (that’s where I took it from).

the note says this software needs libc++ with emulated_tls installed, but you deleted that…have you fixed that? If not, it’s probably still broken then on most people’s 10.6.8 with libc++ installation.

From what I understood, some sort of emulated_tls is supported by gcc now. And the port does build, as a matter of fact.

What would you advise? If it is broken with clang on 10.6.x, but builds with gcc, it looks natural just to use gcc on all systems <11. But for some reason this suggestion is unpopular :)

The different register names in signal is usually a 10.4 SDK thing, eg

https://github.com/macports/macports-ports/blob/c5356ad48dc76826d13b792d64e6b0fd9551c846/devel/ld64/Portfile#L440

but That one I’d have to look at more carefully to see whether what you did works as it is supposed to.

I borrowed this part from here: https://www.cs.purdue.edu/homes/hosking/m3/help/gen_html/m3core/src/runtime/POSIX/RTSignalC.c.html Right now I can’t test it on PPC natively, so any feedback is greatly appreciated.

barracuda156 avatar Jul 24 '22 09:07 barracuda156

UPD. I will rebase against master and add a patch to fix ppc build soon.

barracuda156 avatar Sep 02 '22 22:09 barracuda156

@judaew @mascguy So, Ken’s suggestion re PG worked nicely, therefore MAP_ANON patch removed. Stack patch is relevant only for PPC, so it is moved together with the rest and applied only in ppc* build case. I changed CMAKE_SYSTEM_PROCESSOR to CMAKE_OSX_ARCHITECTURES in CMakeLists to fix Rosetta build (this change does not apply to Apple + Clang combo, there is a separate case for that – and the patch is applied only in PPC case anyway). The build system is very stubborn here :)

barracuda156 avatar Sep 03 '22 00:09 barracuda156

@mascguy Did I miss something, macos-11 check succeeds, macos-12 check fails without even beginning?

barracuda156 avatar Sep 03 '22 00:09 barracuda156

@mascguy Did I miss something, macos-11 check succeeds, macos-12 check fails without even beginning?

It looks there was a potential network blip, based on the CI log.

I just restarted.

mascguy avatar Sep 03 '22 01:09 mascguy

@mascguy Okay, all good now.

barracuda156 avatar Sep 03 '22 01:09 barracuda156

@mascguy Cool, 10.6 Intel also fixed now: https://ports.macports.org/port/abseil/details/

P. S. What happened to 10.5 PPC build bots? Dead forever?

barracuda156 avatar Sep 03 '22 12:09 barracuda156

@mascguy Cool, 10.6 Intel also fixed now: https://ports.macports.org/port/abseil/details/

P. S. What happened to 10.5 PPC build bots? Dead forever?

I'll let @ryandesign and/or @jmroot speak to that. But AFAIK, they aren't in use any more, though.

mascguy avatar Sep 03 '22 13:09 mascguy