linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Pierre Sarrazin <sarrazip@machinasapiens.com>
To: linuxppc-dev@lists.linuxppc.org
Subject: R_PPC_REL24 relocation out of range, with trivial program
Date: Thu, 02 Mar 2000 18:25:46 -0500	[thread overview]
Message-ID: <38BEF87A.B614DB7F@machinasapiens.com> (raw)


This is another message about the "R_PPC_REL24 relocation out of range"
problem. I have a trivial program and library system that illustrates it.
I have read some of the previous messages on this topic but the solutions
proposed did not make a difference.

The problem happens when the dlopened library exports a C++
function returning 'string', but not when it exports a function
returning 'const char *'.

Here is the program:

--[ prog.cpp ]----------------------------------------------------------------
#include <assert.h>
#include <stdio.h>

#include <dlfcn.h>

#ifdef STRING_EXAMPLE
#include <string>
using namespace std;
#endif

int main()
{
	void *handle = dlopen("./libf.so", RTLD_NOW);
	if (!handle)
	{
		fprintf(stderr, "dlopen: %s\n", dlerror());
		return 1;
	}

	#ifdef STRING_EXAMPLE

	string (*pf)(void) = (string (*)(void)) dlsym(handle, "f");
	assert(pf);
	string s = (*pf)();
	printf("s = [%s]\n", s.c_str());

	#else

	const char *(*pg)(void) = (const char *(*)(void)) dlsym(handle, "g");
	assert(pg);
	const char *s = (*pg)();
	printf("s = [%s]\n", s);

	#endif

	dlclose(handle);

	return 0;
}
------------------------------------------------------------------------------

Here is the library source:

--[ f.cpp ]-------------------------------------------------------------------
#include <stdio.h>

#ifdef STRING_EXAMPLE

#include <string>

using namespace std;

extern "C" string f(void)
{
	printf("f()\n");
	return "pizza";
}

#else

extern "C" const char *g(void)
{
	printf("g()\n");
	return "spaghetti";
}

#endif
------------------------------------------------------------------------------


The Makefile defines STRING_EXAMPLE by default.  The problem only
occurs when it is defined. Here is the Makefile:


--[ Makefile ]----------------------------------------------------------------
# Program that illustrates the problem with the error message
# "R_PPC_REL24 relocation out of range" on LinuxPPC R5.
#
# By Pierre Sarrazin <sarrazip@iname.com> March 2, 2000.

FPIC=-fPIC
DEFINES=-DSTRING_EXAMPLE
CXXFLAGS=-g -Wall $(FPIC) $(DEFINES)

all: prog libf.so

prog: prog.o
	$(CXX) $(CXXFLAGS) -o $@ $< -ldl

prog.o: prog.cpp
	$(CXX) $(CXXFLAGS) -c $<

libf.so: f.o
	$(CXX) -shared -o $@ $<

f.o: f.cpp
	$(CXX) $(CXXFLAGS) -c $<

clean:
	rm prog prog.o libf.so f.o

distrib:
	tar czf R_PPC_REL24-relocation.tar.gz Makefile prog.cpp f.cpp
------------------------------------------------------------------------------


Here is a session on the LinuxPPC R5 machine. The compiler is
"gcc version 2.95.2 19991024 (release)". I have installed the
"binutils-2.9.5.0.14-0a" RPM.

------------------------------------------------------------------------------
$ make
g++ -g -Wall -fPIC -DSTRING_EXAMPLE -c prog.cpp
g++ -g -Wall -fPIC -DSTRING_EXAMPLE -o prog prog.o -ldl
g++ -g -Wall -fPIC -DSTRING_EXAMPLE -c f.cpp
g++ -shared -o libf.so f.o
$ ./prog
dlopen: ./libf.so: R_PPC_REL24 relocation out of range
$ make clean
rm prog prog.o libf.so f.o
$ make DEFINES=
g++ -g -Wall -fPIC  -c prog.cpp
g++ -g -Wall -fPIC  -o prog prog.o -ldl
g++ -g -Wall -fPIC  -c f.cpp
g++ -shared -o libf.so f.o
$ ./prog
g()
s = [spaghetti]
$
------------------------------------------------------------------------------


Here is a session on a Pentium-based RedHat 5.2 system. It uses
"gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)" and
binutils-2.9.1.0.15-1.


------------------------------------------------------------------------------
$ make
g++ -g -Wall -fPIC -DSTRING_EXAMPLE -c prog.cpp
g++ -g -Wall -fPIC -DSTRING_EXAMPLE -o prog prog.o -ldl
g++ -g -Wall -fPIC -DSTRING_EXAMPLE -c f.cpp
g++ -shared -o libf.so f.o
$ ./prog
f()
s = [pizza]
$
------------------------------------------------------------------------------


--
Pierre Sarrazin <sarrazip@machinasapiens.com>

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

             reply	other threads:[~2000-03-02 23:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-02 23:25 Pierre Sarrazin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2000-04-03 20:38 R_PPC_REL24 relocation out of range, with trivial program Pierre Sarrazin
2000-04-03 20:46 ` David Edelsohn
2000-04-03 21:34 ` Franz Sirl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38BEF87A.B614DB7F@machinasapiens.com \
    --to=sarrazip@machinasapiens.com \
    --cc=linuxppc-dev@lists.linuxppc.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).