Compiling 1.9.1p0 on AIX 5.3 using xlc

Hi,

I’m trying to compile Ruby using the native compiler xlc on AIX. Ruby
seems to have compiled, but it falls over with a SEGV as soon as I run
‘make test’, it falls over.

The reason I want to use the native compilers rather than gcc is to be
sure that C++ name mangling is not an issue when I link Ruby’s libraries
with my own code.

The output and my rbconfig.rb are attached below. Anyone have any
ideas?

Cheers,
Graza.

/home/build/ruby-1.9.1-p0/.ext/powerpc-aix5.3.0.0/enc/trans/transdb.so: [BUG] Segmentation fault ruby 1.9.1p0 (2009-01-30) [powerpc-aix5.3.0.0]

– control frame ----------
c:0009 p:-570765290 s:0022 b:0022 l:000021 d:000021 TOP
c:0008 p:---- s:0020 b:0020 l:000019 d:000019 CFUNC :require
c:0007 p:0014 s:0016 b:0016 l:000007 d:000015 BLOCK
internal:prelude:3
c:0006 p:---- s:0013 b:0013 l:000012 d:000012 FINISH
c:0005 p:---- s:0011 b:0011 l:000010 d:000010 CFUNC :each
c:0004 p:0014 s:0008 b:0008 l:000007 d:000007 TOP
internal:prelude:1
c:0003 p:---- s:0006 b:0006 l:000005 d:000005 FINISH
c:0002 p:-570713662 s:0004 b:0004 l:000003 d:000003 TOP
c:0001 p:0000 s:0002 b:0002 l:000f28 d:000f28 TOP

– Ruby level backtrace
information-----------------------------------------
internal:prelude:3:in require' <internal:prelude>:3:in block in ’
internal:prelude:1:in each' <internal:prelude>:1:in

[NOTE]
You may encounter a bug of Ruby interpreter. Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

make: *** [test-sample] IOT/Abort trap (core dumped)

# This file was created by mkconfig.rb when ruby was built. Any # changes made to this file will be lost the next time ruby is built.

module RbConfig
RUBY_VERSION == “1.9.1” or
raise “ruby lib version (1.9.1) doesn’t match executable version
(#{RUBY_VERSION})”

TOPDIR =
File.dirname(FILE).chomp!(“/lib/ruby/1.9.1/powerpc-aix5.3.0.0”)
DESTDIR = ‘’ unless defined? DESTDIR
CONFIG = {}
CONFIG[“DESTDIR”] = DESTDIR
CONFIG[“INSTALL”] = ‘’
CONFIG[“EXEEXT”] = “”
CONFIG[“prefix”] = (TOPDIR || DESTDIR + “/ruby/install/path”)
CONFIG[“ruby_install_name”] = “ruby”
CONFIG[“RUBY_INSTALL_NAME”] = “ruby”
CONFIG[“RUBY_SO_NAME”] = “ruby”
CONFIG[“BUILTIN_TRANSSRCS”] = " newline.c"
CONFIG[“MANTYPE”] = “man”
CONFIG[“NROFF”] = “/usr/bin/nroff”
CONFIG[“vendorhdrdir”] = “$(rubyhdrdir)/vendor_ruby”
CONFIG[“sitehdrdir”] = “$(rubyhdrdir)/site_ruby”
CONFIG[“rubyhdrdir”] =
“$(includedir)/$(RUBY_INSTALL_NAME)-$(ruby_version)”
CONFIG[“configure_args”] = " ‘–prefix=/ruby/install/path’
‘CC=/usr/vac/bin/xlc’ ‘CFLAGS=-O3 -q64 -qcpluscmt -qlanglvl=extended
-qcheck=nullptr -Wl,-brtl -I/nfs/home/gagnew/aix/app/include’
‘LDFLAGS=-L/nfs/home/gagnew/aix/app/lib’ ‘CXX=/usr/vac/bin/xlc’"
CONFIG[“vendordir”] = “$(libdir)/$(RUBY_INSTALL_NAME)/vendor_ruby”
CONFIG[“sitedir”] = “$(libdir)/$(RUBY_INSTALL_NAME)/site_ruby”
CONFIG[“ruby_version”] = “1.9.1”
CONFIG[“sitearch”] = “powerpc-aix5.3.0.0”
CONFIG[“arch”] = “powerpc-aix5.3.0.0”
CONFIG[“MAKEFILES”] = “Makefile”
CONFIG[“THREAD_MODEL”] = “pthread”
CONFIG[“EXPORT_PREFIX”] = “”
CONFIG[“COMMON_HEADERS”] = “”
CONFIG[“COMMON_MACROS”] = “”
CONFIG[“COMMON_LIBS”] = “”
CONFIG[“MAINLIBS”] = “”
CONFIG[“ENABLE_SHARED”] = “no”
CONFIG[“DLDLIBS”] = " -lc"
CONFIG[“SOLIBS”] = “”
CONFIG[“LIBRUBYARG_SHARED”] = “-l$(RUBY_SO_NAME)”
CONFIG[“LIBRUBYARG_STATIC”] = “-l$(RUBY_SO_NAME)-static”
CONFIG[“LIBRUBYARG”] = “$(LIBRUBYARG_STATIC)”
CONFIG[“LIBRUBY”] = “$(LIBRUBY_A)”
CONFIG[“LIBRUBY_ALIASES”] = “lib$(RUBY_SO_NAME).so”
CONFIG[“LIBRUBY_SO”] =
“lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR).$(TEENY)”
CONFIG[“LIBRUBY_A”] = “lib$(RUBY_SO_NAME)-static.a”
CONFIG[“RUBYW_INSTALL_NAME”] = “”
CONFIG[“rubyw_install_name”] = “”
CONFIG[“LIBRUBY_DLDFLAGS”] = “-eInit_$(TARGET)”
CONFIG[“LIBRUBY_LDSHARED”] = “$(CC) -G”
CONFIG[“warnflags”] = “”
CONFIG[“debugflags”] = “-g”
CONFIG[“optflags”] = “”
CONFIG[“cflags”] = “$(optflags) $(debugflags) $(warnflags)”
CONFIG[“cppflags”] = “”
CONFIG[“RDOCTARGET”] = “install-doc”
CONFIG[“ARCHFILE”] = “ruby.imp”
CONFIG[“EXTOUT”] = “.ext”
CONFIG[“PREP”] = “miniruby$(EXEEXT)”
CONFIG[“setup”] = “Setup”
CONFIG[“EXTSTATIC”] = “”
CONFIG[“STRIP”] = “strip”
CONFIG[“TRY_LINK”] = “$(CC) $(LDFLAGS) -oconftest $(INCFLAGS)
-I$(hdrdir) $(CPPFLAGS) $(CFLAGS) $(src) $(LIBPATH) $(LOCAL_LIBS)
$(LIBS)”
CONFIG[“LIBPATHENV”] = “SHLIB_PATH”
CONFIG[“RPATHFLAG”] = " -blibpath:%1$-s"
CONFIG[“LIBPATHFLAG”] = " -L%1$-s"
CONFIG[“LINK_SO”] = “”
CONFIG[“LIBEXT”] = “a”
CONFIG[“DLEXT2”] = “”
CONFIG[“DLEXT”] = “so”
CONFIG[“LDSHAREDXX”] = “$(CXX) -G”
CONFIG[“LDSHARED”] = “$(CC) -G”
CONFIG[“CCDLFLAGS”] = “”
CONFIG[“STATIC”] = “”
CONFIG[“ARCH_FLAG”] = “”
CONFIG[“DLDFLAGS”] = “-eInit_$(TARGET)”
CONFIG[“ALLOCA”] = “”
CONFIG[“RMALL”] = “rm -fr”
CONFIG[“RMDIRS”] = “$(top_srcdir)/tool/rmdirs”
CONFIG[“MAKEDIRS”] = “mkdir -p”
CONFIG[“CP”] = “cp”
CONFIG[“RM”] = “rm -f”
CONFIG[“INSTALL_DATA”] = “$(INSTALL) -m 644”
CONFIG[“INSTALL_SCRIPT”] = “$(INSTALL)”
CONFIG[“INSTALL_PROGRAM”] = “$(INSTALL)”
CONFIG[“SET_MAKE”] = “”
CONFIG[“LN_S”] = “ln -s”
CONFIG[“DLLWRAP”] = “”
CONFIG[“WINDRES”] = “”
CONFIG[“NM”] = “nm”
CONFIG[“OBJCOPY”] = “”
CONFIG[“OBJDUMP”] = “”
CONFIG[“ASFLAGS”] = “”
CONFIG[“AS”] = “as”
CONFIG[“AR”] = “ar”
CONFIG[“RANLIB”] = “ranlib”
CONFIG[“COUTFLAG”] = “-o "
CONFIG[“OUTFLAG”] = “-o "
CONFIG[“CPPOUTFILE”] = “> conftest.i”
CONFIG[“GNU_LD”] = “no”
CONFIG[“EGREP”] = “/usr/bin/grep -E”
CONFIG[“GREP”] = “/usr/bin/grep”
CONFIG[“CPP”] = “/usr/vac/bin/xlc -E”
CONFIG[“CXXFLAGS”] = " -g”
CONFIG[“CXX”] = “/usr/vac/bin/xlc”
CONFIG[“OBJEXT”] = “o”
CONFIG[“CPPFLAGS”] = " $(DEFS) $(cppflags)”
CONFIG[“LDFLAGS”] = “-L. -L/home/build/aix/app/lib”
CONFIG[“CFLAGS”] = “-O3 -q64 -qcpluscmt -qlanglvl=extended
-qcheck=nullptr -Wl,-brtl -I/nfs/home/gagnew/aix/app/include -g”
CONFIG[“CC”] = “/usr/vac/bin/xlc”
CONFIG[“target_os”] = “aix5.3.0.0”
CONFIG[“target_vendor”] = “ibm”
CONFIG[“target_cpu”] = “powerpc”
CONFIG[“target”] = “powerpc-ibm-aix5.3.0.0”
CONFIG[“host_os”] = “aix5.3.0.0”
CONFIG[“host_vendor”] = “ibm”
CONFIG[“host_cpu”] = “powerpc”
CONFIG[“host”] = “powerpc-ibm-aix5.3.0.0”
CONFIG[“build_os”] = “aix5.3.0.0”
CONFIG[“build_vendor”] = “ibm”
CONFIG[“build_cpu”] = “powerpc”
CONFIG[“build”] = “powerpc-ibm-aix5.3.0.0”
CONFIG[“TEENY”] = “1”
CONFIG[“MINOR”] = “9”
CONFIG[“MAJOR”] = “1”
CONFIG[“BASERUBY”] = “ruby”
CONFIG[“target_alias”] = “”
CONFIG[“host_alias”] = “”
CONFIG[“build_alias”] = “”
CONFIG[“LIBS”] = "-lpthread -lrt -ldl -lcrypt -lm "
CONFIG[“ECHO_T”] = “”
CONFIG[“ECHO_N”] = “”
CONFIG[“ECHO_C”] = “\\c”
CONFIG[“DEFS”] = “”
CONFIG[“mandir”] = “$(datarootdir)/man”
CONFIG[“localedir”] = “$(datarootdir)/locale”
CONFIG[“libdir”] = “$(exec_prefix)/lib”
CONFIG[“psdir”] = “$(docdir)”
CONFIG[“pdfdir”] = “$(docdir)”
CONFIG[“dvidir”] = “$(docdir)”
CONFIG[“htmldir”] = “$(docdir)”
CONFIG[“infodir”] = “$(datarootdir)/info”
CONFIG[“docdir”] = “$(datarootdir)/doc/$(PACKAGE)”
CONFIG[“oldincludedir”] = “/usr/include”
CONFIG[“includedir”] = “$(prefix)/include”
CONFIG[“localstatedir”] = “$(prefix)/var”
CONFIG[“sharedstatedir”] = “$(prefix)/com”
CONFIG[“sysconfdir”] = “$(prefix)/etc”
CONFIG[“datadir”] = “$(datarootdir)”
CONFIG[“datarootdir”] = “$(prefix)/share”
CONFIG[“libexecdir”] = “$(exec_prefix)/libexec”
CONFIG[“sbindir”] = “$(exec_prefix)/sbin”
CONFIG[“bindir”] = “$(exec_prefix)/bin”
CONFIG[“exec_prefix”] = “$(prefix)”
CONFIG[“PACKAGE_BUGREPORT”] = “”
CONFIG[“PACKAGE_STRING”] = “”
CONFIG[“PACKAGE_VERSION”] = “”
CONFIG[“PACKAGE_TARNAME”] = “”
CONFIG[“PACKAGE_NAME”] = “”
CONFIG[“PATH_SEPARATOR”] = “:”
CONFIG[“SHELL”] = “/bin/sh”
CONFIG[“rubylibdir”] =
“$(libdir)/$(ruby_install_name)/$(ruby_version)”
CONFIG[“archdir”] = “$(rubylibdir)/$(arch)”
CONFIG[“sitelibdir”] = “$(sitedir)/$(ruby_version)”
CONFIG[“sitearchdir”] = “$(sitelibdir)/$(sitearch)”
CONFIG[“vendorlibdir”] = “$(vendordir)/$(ruby_version)”
CONFIG[“vendorarchdir”] = “$(vendorlibdir)/$(sitearch)”
CONFIG[“topdir”] = File.dirname(FILE)
MAKEFILE_CONFIG = {}
CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
def RbConfig::expand(val, config = CONFIG)
val.gsub!(/$$|$(([^()]+))|${([^{}]+)}/) do
var = $&
if !(v = $1 || $2)
‘$’
elsif key = config[v = v[/\A[^:]+(?=(?::(.?)=(.))?\z)/]]
pat, sub = $1, $2
config[v] = false
RbConfig::expand(key, config)
config[v] = key
key = key.gsub(/#{Regexp.quote(pat)}(?=\s|\z)/n) {sub} if pat
key
else
var
end
end
val
end
CONFIG.each_value do |val|
RbConfig::expand(val)
end
end
Config = RbConfig # compatibility for ruby-1.8.4 and older.
CROSS_COMPILING = nil unless defined? CROSS_COMPILING

Not sure if it’s the root-cause at this stage, but I’ve found that core
dump is happening when trying to load enc/trans/transdb.so. Having
looked closer at warnings etc when rebuilding, I saw that the linker was
complaining that the Init_ symbol didn’t exist. The search for this
symbol is actually as a result of this:

CONFIG[“DLDFLAGS”] = “-eInit_$(TARGET)”

The setting of $TARGET is something that used to happen in 1.8 as part
of building the ext directory, but it not happening when building the
contents of the enc directory in 1.9.1.

So, I’ve gotten over this hurdle by modifying the enc.mk file to use the
following value for dldflags:

dldflags = -eInit_$(basename $(notdir $@))

The -e option to th compiler sets the entry point of the shared library
in AIX. This is needed because in dln.c, the load() function is
expected to return a pointer to this function. But as I trace through
this, the encdb.so still wasn’t loading due to unresolved symbols.

I’ve further modified enc.mk to link in encoding.o to resolve these
missing symbols. So now encdb.so loads. Now I’m getting a problem with
miniruby getting into an infinite loop. For some reason it’s spinning
on line 384 in st.c.

unpack_entries(table = (nil), 0x110296f70, 0x0), line 384 in "st.c" dmyencoding.enc_register_at(index = 150994943, name = "\360", encoding = 0x0fffffffffffdb30), line 204 in "encoding.c" dmyencoding.enc_register(name = "", encoding = 0x09001000a067c4d0), line 219 in "encoding.c" dmyencoding.rb_encdb_declare(name = ""), line 255 in "encoding.c" Init_encdb(), line 1 in "encdb.h" unnamed block in dln_load(file = "c\343"), line 1348 in "dln.c" dln_load(file = "c\343"), line 1348 in "dln.c" load_ext(path = 4295785724), line 532 in "load.c" rb_vm_call_cfunc(recv = 1152921504606838400, func = 0x00000001101cc5d0, arg = 4295439756, blockptr = (nil), filename = 1152921504606838400), line 1371 in "vm.c" unnamed block in rb_require_safe(fname = 4564958760, safe = 0), line 567 in "load.c" rb_require_safe(fname = 4564958760, safe = 0), line 567 in "load.c" dmyencoding.require_enc(enclib = 0), line 452 in "encoding.c" rb_protect(proc = 0x000000011002c648, data = 4564958760, state = (nil)), line 647 in "eval.c" dmyencoding.load_encoding(name = (invalid char ptr (0xbadc0ffee0ddf00d))), line 474 in "encoding.c" dmyencoding.rb_enc_find_index(name = "^I"), line 514 in "encoding.c" process_options(arg = 12), line 1280 in "ruby.c" rb_vm_call_cfunc(recv = 4564961360, func = 0x000000011002e9c8, arg = 0, blockptr = 0x0000000100196288, filename = 1152921504606842768), line 1371 in "vm.c" ruby_process_options(argc = 1767859311, argv = 0x74002e646f5f736f), line 1805 in "ruby.c" unnamed block in ruby_options(argc = 12, argv = 0x0ffffffffffff470), line 88 in "eval.c" ruby_options(argc = 12, argv = 0x0ffffffffffff470), line 88 in "eval.c" unnamed block in main(argc = 12, argv = 0x0ffffffffffff470), line 34 in "main.c" main(argc = 12, argv = 0x0ffffffffffff470), line 34 in "main.c"

Anyone with any clues here? I’ve also tried linking with encdb.so with
dmyencoding.o since dmyenoding.c just does a #define and then a #include
of encoding.c, but it doesn’t make any difference.

I’m now completely stuck.

Graham A. wrote:

missing symbols. So now encdb.so loads. Now I’m getting a problem with
miniruby getting into an infinite loop. For some reason it’s spinning
on line 384 in st.c.
[…]
I’m now completely stuck.

I have a similar issue when compiling trunk with llvm (version does not
seem to matter). miniruby spins and is only killable with -9. I
submitted a but report for this, answer was that only gcc is supported.

Hi Nakada-san,

I’ve tried to register on redmine to be able to log these things as
bugs, but for some reason it won’t let me in. The forgot password page
accepts my email address, so it would seem that I’m registered, but I
don’t then receive an email indicating a new password or how to get back
in.

The patch you provided works fine. Thanks for that.

The missing symbols reported when loading encdb.so were rb_encdb_declare
and rb_encdb_alias although there were other errors. The missing
symbols and other errors were found by adding the follwoing lines to
aix_loaderror in dln.c:

{
int pid, st;
if (pid = fork()) {
waitpid(pid, &st, 0);
}
else {
message[0] = “execerror”;
message[1] = pathname;
execvp("/usr/sbin/execerror",message);
}
}

This produces better output than the original code in the aix_loaderror
function:

exec(): 0509-036 Cannot load program /nfs/home/gagnew/aix/ruby-1.9.1-p0/.ext/powerpc-aix5.3.0.0/enc/encdb.so because of the following errors:
0509-161 There is not enough memory for the process.
rtld: 0712-001 Symbol rb_encdb_declare/nfs/home/gagnew/aix/ruby-1.9.1-p0/.ext/powerpc-aix5.3.0.0/enc/encdb.so was referenced
from module /nfs/home/gagnew/aix/ruby-1.9.1-p0/.ext/powerpc-aix5.3.0.0/enc/encdb.so(), but a runtime definition
of the symbol was not found.
rtld: 0712-001 Symbol rb_encdb_alias was referenced
from module /nfs/home/gagnew/aix/ruby-1.9.1-p0/.ext/powerpc-aix5.3.0.0/enc/encdb.so(), but a runtime definition
of the symbol was not found.
rtld: 0712-002 fatal error: exiting.
0509-021 Additional errors occurred but are not reported.

I’ve noticed that the prelude code ignores the errors reported when
loading encdb.so. There are other symbols missing when loading
euc_jp.so:

exec(): 0509-036 Cannot load program /nfs/home/gagnew/aix/ruby-1.9.1-p0/.ext/powerpc-aix5.3.0.0/enc/euc_jp.so because of the following errors:
rtld: 0712-001 Symbol rb_enc_register was referenced
from module /nfs/home/gagnew/aix/ruby-1.9.1-p0/.ext/powerpc-aix5.3.0.0/enc/euc_jp.so(), but a runtime definition
of the symbol was not found.
rtld: 0712-002 fatal error: exiting.

Cheers,
Gra.

Hi,

At Thu, 5 Mar 2009 00:54:05 +0900,
Graham A. wrote in [ruby-talk:330286]:

I’m trying to compile Ruby using the native compiler xlc on AIX. Ruby
seems to have compiled, but it falls over with a SEGV as soon as I run
‘make test’, it falls over.

Why not register to http://redmine.ruby-lang.org ?

At Fri, 20 Mar 2009 00:11:00 +0900,
Graham A. wrote in [ruby-talk:331586]:

So, I’ve gotten over this hurdle by modifying the enc.mk file to use the
following value for dldflags:

dldflags = -eInit_$(basename $(notdir $@))

Does the following patch work?

I’ve further modified enc.mk to link in encoding.o to resolve these
missing symbols. So now encdb.so loads. Now I’m getting a problem with
miniruby getting into an infinite loop. For some reason it’s spinning
on line 384 in st.c.

What are missing symbols?

Index: enc/depend

— enc/depend (revision 23012)
+++ enc/depend (working copy)
@@ -1,2 +1,4 @@
+% CONFIG[“DLDFLAGS”].sub!(/(\A|\s)(-\S+(?:\s*\w*)?$(TARGET)\S*)/,
‘\1’)
+% dldflags = $2
% enable_shared = CONFIG[‘ENABLE_SHARED’] == ‘yes’
% deffile = (true if /$(DEFFILE)/ =~ CONFIG[“LINK_SO”])
@@ -104,10 +106,15 @@ $(TRANSOBJS): ruby.h intern.h config.h d
% df = (“enc/#{e}.def” if deffile)
$(ENCSODIR)/<%=e%>.$(DLEXT): <%=obj%>
+% cmd = link_so.sub(/$(OBJS)/) {obj}
+% base = File.basename(e)
+% cmd.sub!(/(?=$(DLDFLAGS))/) {dldflags.sub(/$(TARGET)/) {base}

  • " "} if dldflags
    % if df
    echo> <%=df%> EXPORTS
  • echo>> <%=df%> <%=EXPORT_PREFIX%>Init_<%=File.basename(e)%>
  • echo>> <%=df%> <%=EXPORT_PREFIX%>Init_<%=base%>
    +% cmd.sub!(/$(DEFFILE)/) {df}
    +% cmd.gsub!(/-(?:implib|pdb):/) {|s|“#{s}enc/#{e.sub(/[^/]+\z/,
    ‘’)}”}
    % end
    @$(MAKEDIRS) “$(@D)”
  • <%=link_so.sub(/$(OBJS)/) {obj}.sub(/$(DEFFILE)/)
    {df}.gsub(/-(?:implib|pdb):/) {|s|“#{s}enc/#{e.sub(/[^/]+\z/, ‘’)}”}%>
  • <%=cmd%>

% end

Hi Kanemoto-san,

Thanks for the patch. That’s resolved the problem.

I was wondering whether the common.mk should run nm over all the objects
in $(OBJS) rather than just $(COMMONOBJS) and encoding.o? This seems a
more generic solution to me.

Cheers,
Gra.

Hi Graham,

The missing symbols reported when loading encdb.so were rb_encdb_declare
and rb_encdb_alias although there were other errors.
It seems that some symbols are not exported.