Homebrew / homebrew-core

🍻 Default formulae for the missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
13.75k stars 12.44k forks source link

osm2pgsql's --tag-transform-script argument segfaults because linking against LuaJIT is missing -pagezero_size, -image_base parameters #55717

Closed kevinstadler closed 4 years ago

kevinstadler commented 4 years ago

What you were trying to do (and why)

I've already been using osm2pgsql (latest 1.2.1_1) successfully for a while, and now wanted to make use of its optional Lua tag transformation feature, but (like the user in #52193 before me) I get a Segmentation fault: 11 whenever I run the binary with the --tag-transform-script argument.

What happened (include command output)

$ osm2pgsql --tag-transform-script style.lua yourimportfile.osm
osm2pgsql version 1.2.1 (64 bit id space)

Allocating memory for dense node cache
Allocating dense node cache in one big chunk
Allocating memory for sparse node cache
Sharing dense sparse
Node-cache: cache=800MB, maxblocks=12800*65536, allocation method=11
Mid: pgsql, cache=800
Using lua based tag processing pipeline with script style.lua
Segmentation fault: 11

Proposed solution/fix

The Segmentation fault: 11 on OSX appears to be related to the following note from the LuaJIT installation page:

If you're building a 64 bit application on OSX which links directly or indirectly against LuaJIT, you need to link your main executable with these flags: -pagezero_size 10000 -image_base 100000000

The straightforward solution seems to be to add these two build parameters around here in the osm2pgsql Formula:

https://github.com/Homebrew/homebrew-core/blob/eeb6b62cbfaec7db8aab0d781ee8ec3f93cf4152/Formula/osm2pgsql.rb#L35-L38

What you expected to happen

osm2pgsql should import the data to my PostGIS database, first passing it through its Lua tag transformation feature.

Step-by-step reproduction instructions (by running brew install commands)

brew install osm2pgsql

In order to come to the part of the binary that segfaults you will need to set up a PostGIS database first, but note that this issue was previously reported in #52193 so it is definitely reproducible.

Result:

brew config output

HOMEBREW_VERSION: 2.3.0
ORIGIN: https://github.com/Homebrew/brew
HEAD: 77e09fc166f5fb7197b239d5e2727ddc0791c121
Last commit: 4 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 2497d436179fb680bfb09025e262f4fe7ff05548
Core tap last commit: 5 minutes ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.IyEymvR4rF/org.macosforge.xquartz:0
HOMEBREW_MAKE_JOBS: 4
CPU: quad-core 64-bit ivybridge
Homebrew Ruby: 2.6.3 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3/bin/ruby
Clang: 10.0 build 1000
Git: 2.26.0 => /usr/local/bin/git
Curl: 7.54.0 => /usr/bin/curl
Java: 9.0.4
macOS: 10.13.6-x86_64
CLT: 10.1.0.0.1.1539992718
Xcode: N/A
XQuartz: 2.7.11 => /opt/X11
jonchang commented 4 years ago

The Segmentation fault: 11 on OSX appears to be related to the following note from the LuaJIT installation page:

If you're building a 64 bit application on OSX which links directly or indirectly against LuaJIT, you need to link your main executable with these flags: -pagezero_size 10000 -image_base 100000000

The straightforward solution seems to be to add these two build parameters around here in the osm2pgsql Formula:

https://github.com/Homebrew/homebrew-core/blob/eeb6b62cbfaec7db8aab0d781ee8ec3f93cf4152/Formula/osm2pgsql.rb#L35-L38

Can you see if this works for you by making the change to the formula and then running brew install -s osm2pgsql? If it does, can you open a pull request that:

This documentation will help you get started and I'm happy to help if you have any questions.

kevinstadler commented 4 years ago

Unfortunately I've never worked with cmake before so I wouldn't know where (or how) exactly to make the required changes (or how to test them)...

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.