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

"Exec format error" #229

Closed
jjb opened this issue Jun 17, 2015 · 10 comments
Closed

"Exec format error" #229

jjb opened this issue Jun 17, 2015 · 10 comments

Comments

@jjb
Copy link
Contributor

jjb commented Jun 17, 2015

If I use my rbenv-provided ruby (with gnu readline)...

➔ gitsh
gitsh: /usr/local/share/gitsh/ruby/gitsh.rb: Exec format error

Here is the full build log

➔ which ruby                    
/Users/john/.rbenv/shims/ruby
➔ ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
➔ RUBY=$(which ruby) ./configure
checking for a BSD-compatible install... /opt/local/bin/ginstall -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /opt/local/bin/gmkdir -p
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for ruby... /Users/john/.rbenv/shims/ruby
checking for ruby... (cached) /Users/john/.rbenv/shims/ruby
configure: WARNING: Using a non-system Ruby. Disable rvm, rbenv, etc. or set $RUBY
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for ruby version... ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
find: integration: No such file or directory
find: units: No such file or directory
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating lib/gitsh/Makefile
config.status: creating man/Makefile
config.status: creating vendor/Makefile
config.status: creating spec/Makefile
config.status: creating INSTALL
config.status: executing depfiles commands
➔ make
Making all in src
gcc -DPACKAGE_NAME=\"gitsh\" -DPACKAGE_TARNAME=\"gitsh\" -DPACKAGE_VERSION=\"0.9\" -DPACKAGE_STRING=\"gitsh\ 0.9\" -DPACKAGE_BUGREPORT=\"hello@thoughtbot.com\" -DPACKAGE_URL=\"\" -DPACKAGE=\"gitsh\" -DVERSION=\"0.9\" -I.  -DGITSH_RB_PATH="\"/usr/local/share/gitsh/ruby/gitsh.rb\""   -g -O2 -MT gitsh.o -MD -MP -MF .deps/gitsh.Tpo -c -o gitsh.o gitsh.c
mv -f .deps/gitsh.Tpo .deps/gitsh.Po
gcc  -g -O2   -o gitsh gitsh.o  
sed -e 's|@RUBY[@]|/Users/john/.rbenv/shims/ruby|g' -e 's|@rubydir[@]|/usr/local/share/gitsh/ruby|g' -e 's|@gemsetuppath[@]|/usr/local/share/gitsh/gems/setup.rb|g' ./gitsh.rb.in > gitsh.rb
chmod +x gitsh.rb
Making all in man
make[1]: Nothing to be done for `all'.
Making all in lib/gitsh
sed -e 's|@PACKAGE_VERSION[@]|0.9|g' ./version.rb.in > version.rb
Making all in vendor
make[1]: Nothing to be done for `all'.
Making all in spec
make[1]: Nothing to be done for `all'.
make[1]: Nothing to be done for `all-am'.
➔ sudo make install
Making install in src
 /opt/local/bin/gmkdir -p '/usr/local/bin'
  /opt/local/bin/ginstall -c gitsh '/usr/local/bin'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/ruby'
 /opt/local/bin/ginstall -c gitsh.rb '/usr/local/share/gitsh/ruby'
Making install in man
make[2]: Nothing to be done for `install-exec-am'.
 /opt/local/bin/gmkdir -p '/usr/local/share/man/man1'
 /opt/local/bin/ginstall -c -m 644 man1/gitsh.1 '/usr/local/share/man/man1'
Making install in lib/gitsh
make[2]: Nothing to be done for `install-exec-am'.
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/ruby/gitsh'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/ruby/gitsh/commands'
 /opt/local/bin/ginstall -c -m 644  commands/error_handler.rb commands/factory.rb commands/git_command.rb commands/internal_command.rb commands/noop.rb commands/shell_command.rb commands/tree.rb '/usr/local/share/gitsh/ruby/gitsh/commands'
 /opt/local/bin/ginstall -c -m 644  argument_builder.rb argument_list.rb cli.rb colors.rb completer.rb environment.rb error.rb exit_statuses.rb git_repository.rb history.rb interactive_runner.rb interpreter.rb magic_variables.rb module_delegator.rb parser.rb program_name.rb prompt_color.rb prompter.rb readline_blank_filter.rb script_runner.rb term_info.rb transformer.rb '/usr/local/share/gitsh/ruby/gitsh/.'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/ruby/gitsh/arguments'
 /opt/local/bin/ginstall -c -m 644  arguments/composite_argument.rb arguments/string_argument.rb arguments/variable_argument.rb '/usr/local/share/gitsh/ruby/gitsh/arguments'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/ruby/gitsh'
 /opt/local/bin/ginstall -c -m 644 version.rb '/usr/local/share/gitsh/ruby/gitsh'
Making install in vendor
make[2]: Nothing to be done for `install-exec-am'.
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/blankslate-2.1.2.4/lib'
 /opt/local/bin/ginstall -c -m 644  gems/blankslate-2.1.2.4/lib/blankslate.rb '/usr/local/share/gitsh/gems/blankslate-2.1.2.4/lib'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/source'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/lib/parslet/source/line_cache.rb '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/source'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/pattern'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/lib/parslet/pattern/binding.rb '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/pattern'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/atoms'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/lib/parslet/atoms/alternative.rb gems/parslet-1.5.0/lib/parslet/atoms/base.rb gems/parslet-1.5.0/lib/parslet/atoms/can_flatten.rb gems/parslet-1.5.0/lib/parslet/atoms/capture.rb gems/parslet-1.5.0/lib/parslet/atoms/context.rb gems/parslet-1.5.0/lib/parslet/atoms/dsl.rb gems/parslet-1.5.0/lib/parslet/atoms/dynamic.rb gems/parslet-1.5.0/lib/parslet/atoms/entity.rb gems/parslet-1.5.0/lib/parslet/atoms/lookahead.rb gems/parslet-1.5.0/lib/parslet/atoms/named.rb gems/parslet-1.5.0/lib/parslet/atoms/re.rb gems/parslet-1.5.0/lib/parslet/atoms/repetition.rb gems/parslet-1.5.0/lib/parslet/atoms/scope.rb gems/parslet-1.5.0/lib/parslet/atoms/sequence.rb gems/parslet-1.5.0/lib/parslet/atoms/str.rb gems/parslet-1.5.0/lib/parslet/atoms/visitor.rb '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/atoms'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0/lib'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/lib/parslet.rb '/usr/local/share/gitsh/gems/parslet-1.5.0/lib'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/lib/parslet/atoms.rb gems/parslet-1.5.0/lib/parslet/cause.rb gems/parslet-1.5.0/lib/parslet/convenience.rb gems/parslet-1.5.0/lib/parslet/error_reporter.rb gems/parslet-1.5.0/lib/parslet/export.rb gems/parslet-1.5.0/lib/parslet/expression.rb gems/parslet-1.5.0/lib/parslet/parser.rb gems/parslet-1.5.0/lib/parslet/pattern.rb gems/parslet-1.5.0/lib/parslet/scope.rb gems/parslet-1.5.0/lib/parslet/slice.rb gems/parslet-1.5.0/lib/parslet/source.rb gems/parslet-1.5.0/lib/parslet/transform.rb '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0/example'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/example/boolean_algebra.rb gems/parslet-1.5.0/example/calc.rb gems/parslet-1.5.0/example/capture.rb gems/parslet-1.5.0/example/comments.rb gems/parslet-1.5.0/example/deepest_errors.rb gems/parslet-1.5.0/example/documentation.rb gems/parslet-1.5.0/example/email_parser.rb gems/parslet-1.5.0/example/empty.rb gems/parslet-1.5.0/example/erb.rb gems/parslet-1.5.0/example/ignore.rb gems/parslet-1.5.0/example/ip_address.rb gems/parslet-1.5.0/example/json.rb gems/parslet-1.5.0/example/local.rb gems/parslet-1.5.0/example/mathn.rb gems/parslet-1.5.0/example/minilisp.rb gems/parslet-1.5.0/example/modularity.rb gems/parslet-1.5.0/example/nested_errors.rb gems/parslet-1.5.0/example/parens.rb gems/parslet-1.5.0/example/readme.rb gems/parslet-1.5.0/example/scopes.rb gems/parslet-1.5.0/example/seasons.rb gems/parslet-1.5.0/example/sentence.rb gems/parslet-1.5.0/example/simple.lit gems/parslet-1.5.0/example/simple_xml.rb gems/parslet-1.5.0/example/string_parser.rb gems/parslet-1.5.0/example/test.lit '/usr/local/share/gitsh/gems/parslet-1.5.0/example'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/HISTORY.txt gems/parslet-1.5.0/LICENSE gems/parslet-1.5.0/Rakefile gems/parslet-1.5.0/README '/usr/local/share/gitsh/gems/parslet-1.5.0'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0/example/output'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/example/output/boolean_algebra.out gems/parslet-1.5.0/example/output/calc.out gems/parslet-1.5.0/example/output/capture.out gems/parslet-1.5.0/example/output/comments.out gems/parslet-1.5.0/example/output/deepest_errors.out gems/parslet-1.5.0/example/output/documentation.err gems/parslet-1.5.0/example/output/documentation.out gems/parslet-1.5.0/example/output/email_parser.out gems/parslet-1.5.0/example/output/empty.err gems/parslet-1.5.0/example/output/erb.out gems/parslet-1.5.0/example/output/ignore.out gems/parslet-1.5.0/example/output/ignore_whitespace.out gems/parslet-1.5.0/example/output/ip_address.out gems/parslet-1.5.0/example/output/json.out gems/parslet-1.5.0/example/output/local.out gems/parslet-1.5.0/example/output/mathn.out gems/parslet-1.5.0/example/output/minilisp.out gems/parslet-1.5.0/example/output/modularity.out gems/parslet-1.5.0/example/output/nested_errors.out gems/parslet-1.5.0/example/output/parens.out gems/parslet-1.5.0/example/output/readme.out gems/parslet-1.5.0/example/output/scopes.out gems/parslet-1.5.0/example/output/seasons.out gems/parslet-1.5.0/example/output/sentence.out gems/parslet-1.5.0/example/output/simple_xml.out gems/parslet-1.5.0/example/output/string_parser.out '/usr/local/share/gitsh/gems/parslet-1.5.0/example/output'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/transform'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/lib/parslet/transform/context.rb '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/transform'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems'
 /opt/local/bin/ginstall -c -m 644  gems/setup.rb '/usr/local/share/gitsh/gems'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/error_reporter'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/lib/parslet/error_reporter/deepest.rb gems/parslet-1.5.0/lib/parslet/error_reporter/tree.rb '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/error_reporter'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/rig'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/lib/parslet/rig/rspec.rb '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/rig'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/blankslate-2.1.2.4/spec'
 /opt/local/bin/ginstall -c -m 644  gems/blankslate-2.1.2.4/spec/blankslate_spec.rb '/usr/local/share/gitsh/gems/blankslate-2.1.2.4/spec'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/expression'
 /opt/local/bin/ginstall -c -m 644  gems/parslet-1.5.0/lib/parslet/expression/treetop.rb '/usr/local/share/gitsh/gems/parslet-1.5.0/lib/parslet/expression'
 /opt/local/bin/gmkdir -p '/usr/local/share/gitsh/gems/blankslate-2.1.2.4'
 /opt/local/bin/ginstall -c -m 644  gems/blankslate-2.1.2.4/blankslate.gemspec gems/blankslate-2.1.2.4/Rakefile gems/blankslate-2.1.2.4/README gems/blankslate-2.1.2.4/VERSION '/usr/local/share/gitsh/gems/blankslate-2.1.2.4'
Making install in spec
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
@georgebrock
Copy link
Collaborator

@jjb Thanks for reporting this problem, sorry for not responding sooner. Can you post the contents of /usr/local/share/gitsh/ruby/gitsh.rb here?

From the path to your home directory, it looks like you're on OS X, so a possible work around would be to install Ruby from homebrew, which will give you a non-rbenv Ruby with GNU Readline.

@jjb
Copy link
Contributor Author

jjb commented Aug 8, 2015

#!/Users/john/.rbenv/shims/ruby --disable-gems

$LOAD_PATH.unshift('/usr/local/share/gitsh/ruby')

require '/usr/local/share/gitsh/gems/setup.rb'
require 'gitsh/cli'

begin
  Gitsh::CLI.new.run
rescue => e
  $stderr.puts "gitsh: Error: #{e.message}"
end

@georgebrock
Copy link
Collaborator

@jjb Thanks. That looks correct, and after doing more research into the error message you're seeing, it's probably an issue with the C wrapper around gitsh being compiled for the wrong architecture. If can run /usr/local/share/gitsh/ruby/gitsh.rb directly, and it works, that'll confirm my theory.

Do you have CFLAGS, CXXFLAGS, or LDFLAGS environment variables set? (env | grep FLAGS will help)

@jjb
Copy link
Contributor Author

jjb commented Sep 3, 2015

➔ env | grep FLAGS          
XPC_FLAGS=0x0

@jjb
Copy link
Contributor Author

jjb commented Sep 3, 2015

i don't have time right now to rebuild and test the ruby script directly, sorry

@georgebrock
Copy link
Collaborator

No problem. Sorry I haven't been able to investigate this sooner.

@jjb
Copy link
Contributor Author

jjb commented Oct 11, 2015

I found the cause of the problem. If I change the top line of /usr/local/share/gitsh/ruby/gitsh.rb, it works.

# does not work
#!/Users/john/.rbenv/shims/ruby --disable-gems

# this works
#!/usr/bin/env ruby --disable-gems

This is the same for both bash and zsh. (or maybe it's sh running it anyway in both cases? i can't remember.).

I don't know why it has a problem with the original line.

env is picking the same ruby executable as what was previously hardcoded:

➔ /usr/bin/env which ruby
/Users/john/.rbenv/shims/ruby

I thought maybe periods aren't allowed in shebang lines, so I tried:

ln -s  /Users/john/.rbenv/shims/ruby /tmp/ruby-link

and

#!/tmp/ruby-link --disable-gems

And I got the same error message.

@jjb
Copy link
Contributor Author

jjb commented Jul 5, 2016

still seeing this in 0.10 under macOS 10.11.5, rbenv 1.0.0-21-g9fdce5d, ruby 2.3.1

@georgebrock
Copy link
Collaborator

I've finally managed to reproduce this (entirely by accident) and work out what's going on.

I was wrong about the C wrapper causing problems, it's actually an incompatibility between the gitsh Ruby program and the way the rbenv shim works. On some operating systems, including macOS, it's not possible to use a program as a sh-bang line if it has a sh-bang line itself (see discussion on #7). Unfortunately, the Ruby binary rbenv provides is a shell script with a sh-bang line. The error message results from the C program reporting that it failed to execute the Ruby program, but the root cause is that the Ruby program's sh-bang line is invalid. I've confirmed this by writing a simple shell script that passes its arguments on to system Ruby, and that produces the exact same behaviour.

You mentioned that your motivation for using an rbenv Ruby was to get a version of Ruby linked against GNU Readline instead of libedit. Since v0.11, gitsh has ignored Ruby's Readline integration and provides its own (and maybe, after the discussion we had on #281, that's working better!).

Since this is a rbenv-specific issue, and we recommend using system Ruby, I'm going to close this.

For anyone reading this in the future who really wants to use an rbenv Ruby with gitsh, you can probably work around it by running something like env RUBY="$HOME/.rbenv/versions/2.4.1/bin/ruby" ./configure, but be aware that if you remove that specific Ruby version from rbenv, or you upgrade rbenv and the location of the Ruby versions changes, you'll need to re-build gitsh.

@mjc-gh
Copy link

mjc-gh commented Feb 9, 2024

Sorry to bump a closed issue, but I am getting this issue now when I try to install gitsh using asdf with RUBY=$(which ruby) ./configure. I first get this error:

> gitsh
gitsh: /usr/local/share/gitsh/ruby/gitsh.rb: Exec format error

If I make updates, as suggested in this gist, to update the /usr/local/share/gitsh/ruby/gitsh.rb script's top line to point to use either /usr/bin/env ruby or to point directly to the binary installed by asdf (/Users/username/.asdf/installs/ruby/3.2.2/bin/ruby) I get:

> gitsh
Killed: 9

I've tried with Ruby 2.7.7, 3.06, and 3.2.2 via asdf and they all get the same result.

I am on arm64 arch with macos. The homebrew install is also failing with the error in #388. The system level ruby is:

/usr/bin/ruby --version
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]

When I try to configure with system Ruby, I get:

$ RUBY=/usr/bin/ruby ./configure
checking for a BSD-compatible install... /opt/homebrew/bin/ginstall -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /opt/homebrew/bin/gmkdir -p
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for ruby... /usr/bin/ruby
checking for ruby... (cached) /usr/bin/ruby
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for ruby version... ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]
checking for tgetnum() in -lncurses... yes
checking for readline/readline.h... yes
checking for readline/history.h... yes
checking for readline() in -lreadline... yes
checking for rl_set_screen_size() in stdio.h,readline/readline.h,readline/history.h... yes
checking for rl_completion_append_character in stdio.h,readline/readline.h,readline/history.h... yes
checking for rl_completion_suppress_quote in stdio.h,readline/readline.h,readline/history.h... no
extconf.rb:20:in `require_var': found incompatible version of readline (no rl_completion_suppress_quote) (RuntimeError)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants