Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort out MacOS problems #15

Closed
jacg opened this issue Jul 11, 2023 · 18 comments · Fixed by #82
Closed

Sort out MacOS problems #15

jacg opened this issue Jul 11, 2023 · 18 comments · Fixed by #82

Comments

@jacg
Copy link
Owner

jacg commented Jul 11, 2023

Bizarre MacOS failures in cmake and in GHA, are diverting the time and energy of the only 2 people currently contributing to the project. As neither of these people have access to a machine running MacOS, it's difficult to make any progress on trying to fix these problems.

Yes, getting nain4 to work smoothly for people using MacOS is crucial, but I don't think it's a good use of the 2 developers' time, at this very moment, to divert our limited resources away from all the other work that needs to be done urgently.

I will therefore allow the GHA MacOS job to fail, and I will ignore all MacOS problems until some progress has been made in other areas, especially getting the most important parts of the documentation written and published.

If anyone who actually has a Mac wants to have a go at working on this, that would be very welcome, and we could offer help. But without access to a Mac, this simply has to be given a much lower priority, for a while.

@soleti
Copy link
Contributor

soleti commented Jul 11, 2023

I "fixed" the cmake issue with Catch2 (mentioned in issue #1) by installing catch2 independently with brew install catch2. However, now I get a linking problem similar to the one in the GitHub Action build, but for the arm64 architecture.

FYI, Geant4 builds on my machine just fine.

Undefined symbols for architecture arm64:
  "aPrimaryVertexAllocator()", referenced from:
      nain4::generator::geantino_along_x(G4Event*) in g4-mandatory.cc.o
      G4PrimaryVertex::operator delete(void*) in g4-mandatory.cc.o
  "aPrimaryParticleAllocator()", referenced from:
      nain4::generator::geantino_along_x(G4Event*) in g4-mandatory.cc.o
      G4PrimaryParticle::operator delete(void*) in g4-mandatory.cc.o
  "G4SDManager::GetSDMpointer()", referenced from:
      nain4::sensitive_detector::sensitive_detector(G4String, std::__1::function<bool (G4Step*)>, std::__1::function<void (G4HCofThisEvent*)>) in nain4.cc.o
  "G4SDManager::AddNewDetector(G4VSensitiveDetector*)", referenced from:
      nain4::sensitive_detector::sensitive_detector(G4String, std::__1::function<bool (G4Step*)>, std::__1::function<void (G4HCofThisEvent*)>) in nain4.cc.o
  "G4PVPlacement::G4PVPlacement(HepGeom::Transform3D const&, G4LogicalVolume*, G4String const&, G4LogicalVolume*, bool, int, bool)", referenced from:
      nain4::place::now() in nain4.cc.o
  "G4AllocatorBase::G4AllocatorBase()", referenced from:
      nain4::generator::geantino_along_x(G4Event*) in g4-mandatory.cc.o
  "G4AllocatorBase::~G4AllocatorBase()", referenced from:
      G4Allocator<G4PrimaryVertex>::~G4Allocator() in g4-mandatory.cc.o
      G4Allocator<G4PrimaryVertex>::~G4Allocator() in g4-mandatory.cc.o
      G4Allocator<G4PrimaryParticle>::~G4Allocator() in g4-mandatory.cc.o
      G4Allocator<G4PrimaryParticle>::~G4Allocator() in g4-mandatory.cc.o
  "G4AllocatorPool::Grow()", referenced from:
      nain4::generator::geantino_along_x(G4Event*) in g4-mandatory.cc.o
  "G4AllocatorPool::Reset()", referenced from:
      G4Allocator<G4PrimaryVertex>::ResetStorage() in g4-mandatory.cc.o
      G4Allocator<G4PrimaryParticle>::ResetStorage() in g4-mandatory.cc.o
  "G4AllocatorPool::G4AllocatorPool(unsigned int)", referenced from:
      nain4::generator::geantino_along_x(G4Event*) in g4-mandatory.cc.o
  "G4AllocatorPool::~G4AllocatorPool()", referenced from:
      G4Allocator<G4PrimaryVertex>::~G4Allocator() in g4-mandatory.cc.o
      G4Allocator<G4PrimaryVertex>::~G4Allocator() in g4-mandatory.cc.o
      G4Allocator<G4PrimaryParticle>::~G4Allocator() in g4-mandatory.cc.o
      G4Allocator<G4PrimaryParticle>::~G4Allocator() in g4-mandatory.cc.o
  "G4LogicalVolume::SetSolid(G4VSolid*)", referenced from:
      nain4::combine_geometries(G4VPhysicalVolume*, G4VPhysicalVolume*) in nain4.cc.o
  "G4ParticleTable::FindParticle(G4String const&)", referenced from:
      nain4::generator::geantino_along_x(G4Event*) in g4-mandatory.cc.o
  "G4ParticleTable::GetParticleTable()", referenced from:
      nain4::generator::geantino_along_x(G4Event*) in g4-mandatory.cc.o
  "G4PrimaryVertex::G4PrimaryVertex()", referenced from:
      nain4::generator::geantino_along_x(G4Event*) in g4-mandatory.cc.o
  "G4OpticalPhysics::G4OpticalPhysics(int, G4String const&)", referenced from:
      nain4::use_our_optical_physics(G4RunManager*, int) in nain4.cc.o
  "G4PrimaryParticle::G4PrimaryParticle(G4ParticleDefinition const*, double, double, double)", referenced from:
      nain4::generator::geantino_along_x(G4Event*) in g4-mandatory.cc.o
  "G4VSensitiveDetector::Initialize(G4HCofThisEvent*)", referenced from:
      vtable for nain4::sensitive_detector in nain4.cc.o
  "G4VSensitiveDetector::GetCollectionID(int)", referenced from:
      vtable for nain4::sensitive_detector in nain4.cc.o
  "G4VSensitiveDetector::clear()", referenced from:
      vtable for nain4::sensitive_detector in nain4.cc.o
  "G4VSensitiveDetector::DrawAll()", referenced from:
      vtable for nain4::sensitive_detector in nain4.cc.o
  "G4VSensitiveDetector::PrintAll()", referenced from:
      vtable for nain4::sensitive_detector in nain4.cc.o
  "G4VSensitiveDetector::G4VSensitiveDetector(G4String)", referenced from:
      nain4::sensitive_detector::sensitive_detector(G4String, std::__1::function<bool (G4Step*)>, std::__1::function<void (G4HCofThisEvent*)>) in nain4.cc.o
  "G4VSensitiveDetector::~G4VSensitiveDetector()", referenced from:
      nain4::sensitive_detector::sensitive_detector(G4String, std::__1::function<bool (G4Step*)>, std::__1::function<void (G4HCofThisEvent*)>) in nain4.cc.o
      nain4::sensitive_detector::~sensitive_detector() in nain4.cc.o
      nain4::sensitive_detector::~sensitive_detector() in nain4.cc.o
  "G4VModularPhysicsList::ReplacePhysics(G4VPhysicsConstructor*)", referenced from:
      nain4::use_our_optical_physics(G4RunManager*, int) in nain4.cc.o
  "G4VModularPhysicsList::RegisterPhysics(G4VPhysicsConstructor*)", referenced from:
      nain4::use_our_optical_physics(G4RunManager*, int) in nain4.cc.o
  "G4MaterialPropertiesTable::AddProperty(G4String const&, std::__1::vector<double, std::__1::allocator<double>> const&, std::__1::vector<double, std::__1::allocator<double>> const&, bool, bool)", referenced from:
      nain4::material_properties::add(G4String const&, std::__1::vector<double, std::__1::allocator<double>> const&, std::__1::vector<double, std::__1::allocator<double>> const&) in nain4.cc.o
      nain4::material_properties::add(G4String const&, std::__1::vector<double, std::__1::allocator<double>> const&, double) in nain4.cc.o
  "G4MaterialPropertiesTable::AddConstProperty(G4String const&, double, bool)", referenced from:
      nain4::material_properties::add(G4String const&, double) in nain4.cc.o
  "G4EmStandardPhysics_option4::G4EmStandardPhysics_option4(int, G4String const&)", referenced from:
      nain4::use_our_optical_physics(G4RunManager*, int) in nain4.cc.o
  "G4VUserActionInitialization::~G4VUserActionInitialization()", referenced from:
      nain4::actions::~actions() in g4-mandatory.cc.o
      nain4::actions::~actions() in g4-mandatory.cc.o
  "CLHEP::HepRandom::createInstance()", referenced from:
      __GLOBAL__sub_I_g4_mandatory.cc in g4-mandatory.cc.o
      __GLOBAL__sub_I_nain4.cc in nain4.cc.o
  "G4Box::G4Box(G4String const&, double, double, double)", referenced from:
      nain4::combine_geometries(G4VPhysicalVolume*, G4VPhysicalVolume*) in nain4.cc.o
  "HepGeom::Transform3D::Identity", referenced from:
      nain4::combine_geometries(G4VPhysicalVolume*, G4VPhysicalVolume*) in nain4.cc.o
  "FTFP_BERT::FTFP_BERT(int)", referenced from:
      nain4::use_our_optical_physics(G4RunManager*, int) in nain4.cc.o
  "G4LogicalVolume::GetSolid() const", referenced from:
      nain4::combine_geometries(G4VPhysicalVolume*, G4VPhysicalVolume*) in nain4.cc.o
  "G4VPhysicalVolume::GetTranslation() const", referenced from:
      nain4::combine_geometries(G4VPhysicalVolume*, G4VPhysicalVolume*) in nain4.cc.o
  "G4VSensitiveDetector::Clone() const", referenced from:
      vtable for nain4::sensitive_detector in nain4.cc.o
  "G4VUserActionInitialization::SetUserAction(G4UserRunAction*) const", referenced from:
      nain4::actions::Build() const in g4-mandatory.cc.o
  "G4VUserActionInitialization::SetUserAction(G4UserEventAction*) const", referenced from:
      nain4::actions::Build() const in g4-mandatory.cc.o
  "G4VUserActionInitialization::SetUserAction(G4UserStackingAction*) const", referenced from:
      nain4::actions::Build() const in g4-mandatory.cc.o
  "G4VUserActionInitialization::SetUserAction(G4UserSteppingAction*) const", referenced from:
      nain4::actions::Build() const in g4-mandatory.cc.o
  "G4VUserActionInitialization::SetUserAction(G4UserTrackingAction*) const", referenced from:
      nain4::actions::Build() const in g4-mandatory.cc.o
  "G4VUserActionInitialization::SetUserAction(G4VUserPrimaryGeneratorAction*) const", referenced from:
      nain4::actions::Build() const in g4-mandatory.cc.o
  "G4VUserActionInitialization::BuildForMaster() const", referenced from:
      vtable for nain4::actions in g4-mandatory.cc.o
  "G4VUserActionInitialization::InitializeSteppingVerbose() const", referenced from:
      vtable for nain4::actions in g4-mandatory.cc.o
  "HepGeom::Transform3D::operator*(HepGeom::Transform3D const&) const", referenced from:
      nain4::combine_geometries(G4VPhysicalVolume*, G4VPhysicalVolume*) in nain4.cc.o
  "typeinfo for G4AllocatorBase", referenced from:
      typeinfo for G4Allocator<G4PrimaryVertex> in g4-mandatory.cc.o
      typeinfo for G4Allocator<G4PrimaryParticle> in g4-mandatory.cc.o
  "typeinfo for G4PrimaryVertex", referenced from:
      nain4::generator::geantino_along_x(G4Event*) in g4-mandatory.cc.o
  "typeinfo for G4PrimaryParticle", referenced from:
      nain4::generator::geantino_along_x(G4Event*) in g4-mandatory.cc.o
  "typeinfo for G4VSensitiveDetector", referenced from:
      typeinfo for nain4::sensitive_detector in nain4.cc.o
  "typeinfo for G4VUserActionInitialization", referenced from:
      typeinfo for nain4::actions in g4-mandatory.cc.o
  "typeinfo for G4Box", referenced from:
      nain4::combine_geometries(G4VPhysicalVolume*, G4VPhysicalVolume*) in nain4.cc.o
  "typeinfo for G4VSolid", referenced from:
      nain4::combine_geometries(G4VPhysicalVolume*, G4VPhysicalVolume*) in nain4.cc.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [_deps/nain4-build/libNain4.dylib] Error 1
make[1]: *** [_deps/nain4-build/CMakeFiles/Nain4.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

This was referenced Jul 11, 2023
@soleti
Copy link
Contributor

soleti commented Jul 12, 2023

I made some progress here. I managed to install nain4 by changing the order in target_link_libraries and putting Nain4 first. Also, I had to remove all the tests because, even if Catch2 is installed, it can't find catch2/catch.hpp. I think it has to do with the fact that brew installs Catch2 v3 and not v2. Maybe you could add an option that makes tests optional until we figure out how to install Catch2 v2 on macOS.

@jacg
Copy link
Owner Author

jacg commented Jul 12, 2023

even if Catch2 is installed, it can't find catch2/catch.hpp. I think it has to do with the fact that brew installs Catch2 v3 and not v2.

Sounds very plausible. Catch2 was originally entirely header-based. IIRC, v3 turns it into a library.

I had to remove all the tests

You mean from CMakeLists.txt?

Maybe you could add an option that makes tests optional until we figure out how to install Catch2 v2 on macOS

Given that the tests are the sanity check that confirms that it's worth carrying on trying to use your current installation of n4 at all, and that getting people into the habit of writing automated tests for G4 is half of the point of n4's existence, I'm reluctant to spend resources on this. If anything, I'd prefer to spend the time on upgrading the catch2 version used by n4.

But, in the immediate short-term ... you already have Nix, right? How about trying to get Catch2 v2 with one of the following?

  • nix profile install nixpkgs#catch2
    This installs Catch2 into your Nix profile. This is Nix trying to look like a 'normal' package manager, for the convenience of people who don't get the whole point of Nix, which is to avoid stateful modifications of your environment. Given that Catch2 v < 3 is header-only, I'm not entirely sure what's going to happen. You could try that, and see if cmake finds Catch2 afterwards. This might be the most convenient for you, but I would start off with one of the following alternatives.

  • nix shell nixpkgs#catch2
    This installs Catch2 ephemerally: it is only visible in this shell and will disappear as soon as you leave it.
    A quick experiment shows that it adds the location of Catch2 stuff to various environment variables, which might be enough for cmake to find it ... as long as you run cmake inside that shell. I guess that the nix install ... version would set similar variables in your environment.

  • nix build nixpkgs#catch2
    This installs Catch2 into result/ in your working directory. It's a link to the true location in the Nix store, so you can just rm it, to get rid of it. In result/ you will find include, lib and share which contain everything, including cmake stuff. So you could point your cmake in that general direction.

All the above use the new 'experimental' nix command. There are equivalents for legacy Nix, but I don't remember them off the top of my head. Anyway, it's just a question of adding --extra-experimental-features nix-command to your invocation, if you haven't enabled it already.

BTW, elsewhere you said that flakes are experimental. While this is strictly true, nothing significant has changed in them for years, and far too many people in the Nix world already depend on them for far too many things, and they are so much better than the old way of doing things, so it's almost guaranteed that flakes aren't going to change in any significant backwards-incompatible way.

@jacg
Copy link
Owner Author

jacg commented Jul 12, 2023

I managed to install nain4 by changing the order in target_link_libraries and putting Nain4 first

Can you show exactly what you have, or a diff, whichever is more concise?

@soleti
Copy link
Contributor

soleti commented Jul 12, 2023

But, in the immediate short-term ... you already have Nix, right? How about trying to get Catch2 v2 with one of the following?

Still can't find 'catch2/catch.hpp' unfortunately.
EDIT: actually, if I add include_directories("/usr/local/include/") after installing Catch2 v2 from source it can find it but then we are back to

Undefined symbols for architecture arm64:
  "end(G4VPhysicalVolume*)", referenced from:
      C_A_T_C_H_T_E_S_T_10() in test-nain4.cc.o
      C_A_T_C_H_T_E_S_T_28() in test-nain4.cc.o
...

The diff of what works for me right now is:

< find_package(Catch2 REQUIRED)
< set(ALL_TEST_SOURCES
<   test/catch2-main-test.cc
<   # ${Nain4_SOURCES}
<   # ${Nain4_HEADERS}
<   ${Nain4_TESTS}
< )
---
> # find_package(Catch2 REQUIRED)
> # set(ALL_TEST_SOURCES
> #   test/catch2-main-test.cc
> #   # ${Nain4_SOURCES}
> #   # ${Nain4_HEADERS}
> #   ${Nain4_TESTS}
> # )
66,67c66,67
< # TODO including headers in add_executable apparently makes them show up in IDEs. Verify how?
< add_executable(nain4-tests ${ALL_TEST_SOURCES})
---
> # # TODO including headers in add_executable apparently makes them show up in IDEs. Verify how?
> # add_executable(nain4-tests ${ALL_TEST_SOURCES})
71c71
<   nain4-tests
---
>   Nain4
73c73
<   Catch2::Catch2
---
>   # Catch2::Catch2
75d74
<   Nain4
86,87c85,86
< include(Catch)
< catch_discover_tests(nain4-tests)
---
> # include(Catch)
> # catch_discover_tests(nain4-tests)

@jacg
Copy link
Owner Author

jacg commented Jul 12, 2023

@soleti Some of your undefined symbol problems are likely to have been caused by the presence of old build products, after having changed dependency versions. just nain4/clean (or cd nain4 && just clean) should clear those up.

Otherwise, we have a version that uses Catch2 v3 in the pipeline: #21.

@soleti
Copy link
Contributor

soleti commented Jul 13, 2023

It doesn't look like it's a problem of an old build product, I cleared everything and I get the same error. One other thing is that, as you can see from the diff, I need to put "Nain4" as the first line in target_link_libraries instead of nain4-tests, not sure what to do with this info...

@jacg
Copy link
Owner Author

jacg commented Jul 13, 2023

It doesn't look like it's a problem of an old build product

It may not be right now, but I'm pretty sure that some of the errors you showed around the time you were swapping between catch v2 and v3 looked very much like it.

There are too many orthogonal differences between what you have and what we have, for me to be able to reason about anything: too many combinations to take into account.

We're in the process of finalizing the Catch v3 version. I suggest you try again one we've merged that. It should remove at least one degree of freedom from the problem, making it more tractable.

@jacg
Copy link
Owner Author

jacg commented Jul 13, 2023

The Catch2 v3 version-using code has been merged, and tagged with v0.0.2.

I need to put "Nain4" as the first line in target_link_libraries instead of nain4-tests, not sure what to do with this info...

When I tried moving Nain4, it broke on Linux.

But your diff had irrelevant changes related to removal of Catch2. Could you try with the new version, which will hopefully give us a diff that only addresses a single, self-contained change.

@jacg
Copy link
Owner Author

jacg commented Jul 13, 2023

I have an increasing suspicion that all of these problems are related to inconsistencies between cmake on MacOS and cmake on Linux. Or rather, the need to do things differently in cmake on MacOS and Linux.

Do we know anybody who has experience with this sort of thing?

@jacg
Copy link
Owner Author

jacg commented Jul 14, 2023

I've just realized that I overlooked something important/obvious here: aarch64-darwin was not enabled in the flake!

I have fixed that now: before 3dcd208, the output of nix flake show didn't mention aarch64-darwin; thereafter, it does.

This should get us past the error linked above, but we have other problems beyond it.

@soleti Could you please try just g4-examples/ in the top-level directory?

This tries to compile and run G4's example B1. On GHA x86_64-darwin, it compiles but segfaults at runtime.

  • Does it do the same on aarch64-darwin?
  • If so, maybe you could run it through a debugger to see what's causing the segfault, on your machine, as it's not easy to do via GHA.

@soleti
Copy link
Contributor

soleti commented Jul 14, 2023

Ok, now I was able to install it with Nix (although it had to download 3GB of stuff...). I also get segmentation fault. Using lldb (which I am not familiar with, gdb is still not available on Silicon) I get:

Process 7764 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000000000000
error: memory read failed for 0x0
Target 0: (exampleB1) stopped.

Going up doesn't make things clearer (at least to me):

(lldb) up
frame #1: 0x0000000102849bb8 libc++.1.0.dylib`std::__1::__stdinbuf<char>::imbue(std::__1::locale const&) + 52
libc++.1.0.dylib`std::__1::__stdinbuf<char>::imbue:
->  0x102849bb8 <+52>: str    w0, [x19, #0x58]
    0x102849bbc <+56>: ldr    x0, [x19, #0x48]
    0x102849bc0 <+60>: ldr    x8, [x0]
    0x102849bc4 <+64>: ldr    x8, [x8, #0x38]
(lldb) up
frame #2: 0x000000010284941c libc++.1.0.dylib`std::__1::DoIOSInit::DoIOSInit() + 148
libc++.1.0.dylib`std::__1::DoIOSInit::DoIOSInit:
->  0x10284941c <+148>: add    x0, sp, #0x10
    0x102849420 <+152>: bl     0x10284b034               ; std::__1::locale::~locale()
    0x102849424 <+156>: nop    
    0x102849428 <+160>: ldr    x8, #0x6ed40              ; (void *)0x00000001031743d0: vtable for std::__1::basic_istream<char, std::__1::char_traits<char> >
(lldb) 
frame #3: 0x000000010284a9d4 libc++.1.0.dylib`_GLOBAL__I_000100 + 72
libc++.1.0.dylib`:
->  0x10284a9d4 <+72>: adr    x0, #-0xf58               ; std::__1::DoIOSInit::~DoIOSInit()
    0x10284a9d8 <+76>: nop    
    0x10284a9dc <+80>: adr    x2, #-0x369dc
    0x10284a9e0 <+84>: nop    
(lldb) 
frame #4: 0x00000001a0b4c1e0 dyld`invocation function for block in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const::$_0::operator()() const + 168
dyld`invocation function for block in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const::$_0::operator()() const:
->  0x1a0b4c1e0 <+168>: add    x0, sp, #0x10
    0x1a0b4c1e4 <+172>: bl     0x1a0b2ba90               ; dyld3::ScopedTimer::endTimer()
    0x1a0b4c1e8 <+176>: ldp    x29, x30, [sp, #0xa0]
    0x1a0b4c1ec <+180>: ldp    x20, x19, [sp, #0x90]
(lldb) 
frame #5: 0x00000001a0b8dc60 dyld`invocation function for block in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 172
dyld`invocation function for block in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const:
->  0x1a0b8dc60 <+172>: add    x21, x21, #0x8
    0x1a0b8dc64 <+176>: cmp    x21, x22
    0x1a0b8dc68 <+180>: b.lo   0x1a0b8dbf0               ; <+60>
    0x1a0b8dc6c <+184>: b      0x1a0b8dd2c               ; <+376>
(lldb) 
frame #6: 0x00000001a0b811a4 dyld`invocation function for block in dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 528
dyld`invocation function for block in dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const:
->  0x1a0b811a4 <+528>: ldrb   w8, [x19]
    0x1a0b811a8 <+532>: cbnz   w8, 0x1a0b81308           ; <+884>
    0x1a0b811ac <+536>: add    x8, x25, #0x50
    0x1a0b811b0 <+540>: cmp    x25, x23
(lldb) 
frame #7: 0x00000001a0b2c2d8 dyld`dyld3::MachOFile::forEachLoadCommand(Diagnostics&, void (load_command const*, bool&) block_pointer) const + 296
dyld`dyld3::MachOFile::forEachLoadCommand:
->  0x1a0b2c2d8 <+296>: ldrb   w8, [sp, #0x3f]
    0x1a0b2c2dc <+300>: cbnz   w8, 0x1a0b2c25c           ; <+172>
    0x1a0b2c2e0 <+304>: add    w22, w22, #0x1
    0x1a0b2c2e4 <+308>: ldr    w8, [x20, #0x10]
(lldb) 
frame #8: 0x00000001a0b801cc dyld`dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 192
dyld`dyld3::MachOFile::forEachSection:
->  0x1a0b801cc <+192>: sub    x0, x29, #0x38
    0x1a0b801d0 <+196>: bl     0x1a0b2c354               ; Diagnostics::assertNoError() const
    0x1a0b801d4 <+200>: add    x0, sp, #0x48
    0x1a0b801d8 <+204>: mov    w1, #0x8
(lldb) 
frame #9: 0x00000001a0b82cfc dyld`dyld3::MachOFile::forEachInitializerPointerSection(Diagnostics&, void (unsigned int, unsigned int, bool&) block_pointer) const + 160
dyld`dyld3::MachOFile::forEachInitializerPointerSection:
->  0x1a0b82cfc <+160>: ldp    x29, x30, [sp, #0x60]
    0x1a0b82d00 <+164>: ldp    x20, x19, [sp, #0x50]
    0x1a0b82d04 <+168>: ldp    x22, x21, [sp, #0x40]
    0x1a0b82d08 <+172>: add    sp, sp, #0x70
(lldb) 
frame #10: 0x00000001a0b8d904 dyld`dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 432
dyld`dyld3::MachOAnalyzer::forEachInitializer:
->  0x1a0b8d904 <+432>: mov    x8, sp
    0x1a0b8d908 <+436>: adrp   x16, 374721
    0x1a0b8d90c <+440>: add    x16, x16, #0xed8          ; _NSConcreteStackBlock
    0x1a0b8d910 <+444>: mov    x17, x8
(lldb) 
frame #11: 0x00000001a0b48864 dyld`dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 448
dyld`dyld4::Loader::findAndRunAllInitializers:
->  0x1a0b48864 <+448>: ldrb   w8, [x21, #0x21]
    0x1a0b48868 <+452>: cbz    w8, 0x1a0b48924           ; <+640>
    0x1a0b4886c <+456>: add    x8, sp, #0x68
    0x1a0b48870 <+460>: add    x8, x8, #0x8
(lldb) 
frame #12: 0x00000001a0b48c18 dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 220
dyld`dyld4::Loader::runInitializersBottomUp:
->  0x1a0b48c18 <+220>: ldp    x29, x30, [sp, #0x40]
    0x1a0b48c1c <+224>: ldp    x20, x19, [sp, #0x30]
    0x1a0b48c20 <+228>: ldp    x22, x21, [sp, #0x20]
    0x1a0b48c24 <+232>: ldp    x24, x23, [sp, #0x10]
(lldb) 
frame #13: 0x00000001a0b48bf4 dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 184
dyld`dyld4::Loader::runInitializersBottomUp:
->  0x1a0b48bf4 <+184>: add    w23, w23, #0x1
    0x1a0b48bf8 <+188>: cmp    w23, w22
    0x1a0b48bfc <+192>: b.ne   0x1a0b48b80               ; <+68>
    0x1a0b48c00 <+196>: mov    x0, x19
(lldb) 
frame #14: 0x00000001a0b4c26c dyld`dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const::$_1::operator()() const + 112
dyld`dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const::$_1::operator()() const:
->  0x1a0b4c26c <+112>: ldr    x1, [x19]
    0x1a0b4c270 <+116>: ldr    x8, [x1, #0x30]
    0x1a0b4c274 <+120>: lsl    x12, x8, #3
    0x1a0b4c278 <+124>: add    x9, x12, #0x8
(lldb) 
frame #15: 0x00000001a0b48d98 dyld`dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 304
dyld`dyld4::Loader::runInitializersBottomUpPlusUpwardLinks:
->  0x1a0b48d98 <+304>: ldrb   w8, [x19, #0x21]
    0x1a0b48d9c <+308>: cbz    w8, 0x1a0b48e58           ; <+496>
    0x1a0b48da0 <+312>: add    x8, sp, #0x8
    0x1a0b48da4 <+316>: add    x8, x8, #0x8
(lldb) 
frame #16: 0x00000001a0b6c984 dyld`dyld4::APIs::runAllInitializersForMain() + 468
dyld`dyld4::APIs::runAllInitializersForMain:
->  0x1a0b6c984 <+468>: mov    x0, x20
    0x1a0b6c988 <+472>: mov    x1, x19
    0x1a0b6c98c <+476>: bl     0x1a0b44b04               ; dyld4::Loader::analyzer(dyld4::RuntimeState&) const
    0x1a0b6c990 <+480>: bl     0x1a0b7fea0               ; dyld3::MachOFile::isMainExecutable() const
(lldb) 
frame #17: 0x00000001a0b312d0 dyld`dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3480
dyld`dyld4::prepare:
->  0x1a0b312d0 <+3480>: bl     0x1a0b6aa7c               ; dyld4::notifyMonitoringDyldMain()
    0x1a0b312d4 <+3484>: mov    w0, #0x4
    0x1a0b312d8 <+3488>: movk   w0, #0x1f07, lsl #16
    0x1a0b312dc <+3492>: bl     0x1a0b2bdc0               ; dyld3::kdebug_trace_dyld_enabled(unsigned int)
(lldb) 
frame #18: 0x00000001a0b2fe18 dyld`start + 1964
dyld`start:
->  0x1a0b2fe18 <+1964>: mov    x19, x0
    0x1a0b2fe1c <+1968>: ldrb   w8, [sp, #0xb1]
    0x1a0b2fe20 <+1972>: cbnz   w8, 0x1a0b2fe88           ; <+2076>
    0x1a0b2fe24 <+1976>: ldrb   w8, [sp, #0xb0]
(lldb) 
error: Already at the top of the stack.

@jacg
Copy link
Owner Author

jacg commented Jul 14, 2023

Thanks.

I don't find the output very illuminating, either. I'll try to look at it in more detail, later.

If you can spare some time, maybe you can perform a sanity check: grab $G4_EXAMPLES_DIR/basic/B1/1 and try to compile and run it by whatever means you usually use to compile and run Geant4 stuff on your machine. That should tell us whether the cmake configuration that ships with the example works on MacOS, which will cut our search space in half.

Footnotes

  1. $G4_EXAMPLES_DIR is defined in the shell you enter with nix develop, and using those very files will ensure that we're checking exactly the same version.

@soleti
Copy link
Contributor

soleti commented Jul 14, 2023

Compiling that example in my usual way doesn't give me segfault. The example runs fine.

@jacg
Copy link
Owner Author

jacg commented Jul 14, 2023

Thanks.

Just to be absolutely sure, your usual way does actually use the cmake configuration supplied in the example, rather than, for example, a Nexus-supplied/inspired SCons approach?

@soleti
Copy link
Contributor

soleti commented Jul 14, 2023

Yes, I do use the cmake configuration in the example.

@jacg jacg added this to the First public release: v0.2 milestone Aug 5, 2023
@gonzaponte
Copy link
Collaborator

gonzaponte commented Aug 16, 2023

Hi @soleti, we are experimenting with macos. Can you try to compile and execute the following code using your non-nix G4 installation?

CMakeLists.txt

cmake_minimum_required(VERSION 3.25)
project(Client)
find_package(Geant4 REQUIRED)
include(${Geant4_USE_FILE})
add_executable(client_exe main.cc)
target_link_libraries(
client_exe
PRIVATE
${Geant4_LIBRARIES}
)

main.cc

#include <iostream>
int main() {
  std::cout << "GRR" << std::endl;
}

compile and execute:

cmake -S . -B build && cmake --build build && ./build/client_exe

@jacg jacg mentioned this issue Aug 16, 2023
2 tasks
@soleti
Copy link
Contributor

soleti commented Aug 17, 2023

@gonzaponte that minimal example works on my machine

@jacg jacg closed this as completed in #82 Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants