public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug java/28153]  New: Under Windows Xp the generated JNI headers need to have a '_' prepended for each function.
@ 2006-06-24 16:21 bcmpinc at hotmail dot com
  2006-06-26 17:22 ` [Bug java/28153] " tromey at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: bcmpinc at hotmail dot com @ 2006-06-24 16:21 UTC (permalink / raw)
  To: java-prs

I had some problems when I tried to compile a JNI-example from wikipedia:
  http://en.wikipedia.org/wiki/JNI

I compiled the Java-source containing the native function 
with 'gcj -C' (gcc version 3.4.2 (mingw-special)):
  public native void sayHello();

I passed the class-file to 'gcjh -jni' and it produced a header with the line:
  extern JNIEXPORT void JNICALL Java_JavaSide_sayHello (JNIEnv *env, jobject);

I implemented the function, compiled it with 'g++ -O2 -shared'
When I tried to run the java class it gave an error when it called the native
function.

I examined some other dll's used by java (with depens.exe) and all the
functions 
had a '_' prepended.
I changed the line in the header file to:
  extern JNIEXPORT void JNICALL _Java_JavaSide_sayHello (JNIEnv *env, jobject);

Recompiled the C++ source and ran the java class. This time the function worked 
without any problems.


-- 
           Summary: Under Windows Xp the generated JNI headers need to have
                    a '_' prepended for each function.
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bcmpinc at hotmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28153


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug java/28153] Under Windows Xp the generated JNI headers need to have a '_' prepended for each function.
  2006-06-24 16:21 [Bug java/28153] New: Under Windows Xp the generated JNI headers need to have a '_' prepended for each function bcmpinc at hotmail dot com
@ 2006-06-26 17:22 ` tromey at gcc dot gnu dot org
  2006-06-26 21:01 ` bcmpinc at hotmail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: tromey at gcc dot gnu dot org @ 2006-06-26 17:22 UTC (permalink / raw)
  To: java-prs



------- Comment #1 from tromey at gcc dot gnu dot org  2006-06-26 17:22 -------
Does the JDK's javah put that "_" into the generated header?

I suspect that you are seeing a problem with the C compiler, not a problem
with JNI header generation.
In particular I think that "_", most likely, should be added by the C
compiler and not added to the header.


-- 

tromey at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28153


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug java/28153] Under Windows Xp the generated JNI headers need to have a '_' prepended for each function.
  2006-06-24 16:21 [Bug java/28153] New: Under Windows Xp the generated JNI headers need to have a '_' prepended for each function bcmpinc at hotmail dot com
  2006-06-26 17:22 ` [Bug java/28153] " tromey at gcc dot gnu dot org
@ 2006-06-26 21:01 ` bcmpinc at hotmail dot com
  2006-06-26 21:21 ` dannysmith at users dot sourceforge dot net
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bcmpinc at hotmail dot com @ 2006-06-26 21:01 UTC (permalink / raw)
  To: java-prs



------- Comment #2 from bcmpinc at hotmail dot com  2006-06-26 21:01 -------
(In reply to comment #1)
> Does the JDK's javah put that "_" into the generated header?
No, JDK's javah creates a header equivalent to the header created by 'gcjh
-jni'.

> I suspect that you are seeing a problem with the C compiler, not a problem
> with JNI header generation.
I tried compiling with JDK's jni-headers and the javah-header. It still needs
the "_" prepended.

> In particular I think that "_", most likely, should be added by the C
> compiler and not added to the header.
I think you're right, but it's strange that the C compiler should recognize
that it's compiling a native java function. Most exported non-java functions
don't have a "_" prepended, even if they're in a library containing a lot of
java functions.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28153


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug java/28153] Under Windows Xp the generated JNI headers need to have a '_' prepended for each function.
  2006-06-24 16:21 [Bug java/28153] New: Under Windows Xp the generated JNI headers need to have a '_' prepended for each function bcmpinc at hotmail dot com
  2006-06-26 17:22 ` [Bug java/28153] " tromey at gcc dot gnu dot org
  2006-06-26 21:01 ` bcmpinc at hotmail dot com
@ 2006-06-26 21:21 ` dannysmith at users dot sourceforge dot net
  2006-06-26 22:26 ` dannysmith at users dot sourceforge dot net
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dannysmith at users dot sourceforge dot net @ 2006-06-26 21:21 UTC (permalink / raw)
  To: java-prs



------- Comment #3 from dannysmith at users dot sourceforge dot net  2006-06-26 21:21 -------
I think you may be running into a compiler (MSVC vs GNUC) difference between
handling of __stdcall (==JNICALL) symbols.

For a function void __stdcall foo (int), 
both MSVC and GNUC generate an assembler name of '_foo@4'.  The underscore is
prefix to all assembler names, the @4 is unique to stdcall

MSVC uses the name '_foo@4' in the dll export table when exporting from a dll,
but 'foo@4' when exporting from a staticly linked object.

GNUC uses 'foo@4' in both. 

If you look in info for binutils, under dlltool, you will see 
 --ext-prefix-alias <prefix> Add aliases with <prefix>.
That might help.  However, I don't think that similar is supported by ld.

Danny


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28153


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug java/28153] Under Windows Xp the generated JNI headers need to have a '_' prepended for each function.
  2006-06-24 16:21 [Bug java/28153] New: Under Windows Xp the generated JNI headers need to have a '_' prepended for each function bcmpinc at hotmail dot com
                   ` (2 preceding siblings ...)
  2006-06-26 21:21 ` dannysmith at users dot sourceforge dot net
@ 2006-06-26 22:26 ` dannysmith at users dot sourceforge dot net
  2006-06-27  3:20 ` tromey at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dannysmith at users dot sourceforge dot net @ 2006-06-26 22:26 UTC (permalink / raw)
  To: java-prs



------- Comment #4 from dannysmith at users dot sourceforge dot net  2006-06-26 22:26 -------
(In reply to comment #3)
> I think you may be running into a compiler (MSVC vs GNUC) difference between
> handling of __stdcall (==JNICALL) symbols.

Um, and this should all be taken care of by the #ifdef WIN32 code in
jni.cc:_Jv_LookupJNIMethod 

Danny


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28153


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug java/28153] Under Windows Xp the generated JNI headers need to have a '_' prepended for each function.
  2006-06-24 16:21 [Bug java/28153] New: Under Windows Xp the generated JNI headers need to have a '_' prepended for each function bcmpinc at hotmail dot com
                   ` (3 preceding siblings ...)
  2006-06-26 22:26 ` dannysmith at users dot sourceforge dot net
@ 2006-06-27  3:20 ` tromey at gcc dot gnu dot org
  2006-07-06  0:05 ` tromey at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: tromey at gcc dot gnu dot org @ 2006-06-27  3:20 UTC (permalink / raw)
  To: java-prs



------- Comment #5 from tromey at gcc dot gnu dot org  2006-06-27 03:20 -------
Yeah, jni.cc handles the lookup side of things.

The declaration side of things in user JNI code should be
handled by jni_md.h.  It has a bunch of win32-specific code
which boils down to:

#define JNIIMPORT        __declspec(dllimport)
#define JNIEXPORT        __declspec(dllexport)

#define JNICALL          __stdcall

It might be handy to see a small preprocessed source file.
Perhaps you're picking up the wrong jni.h, jni_md.h, or
perhaps the logic in jni_md.h is broken somehow.

Oops, I just looked at your version... jni_md.h is not in
3.4.  In 3.4 the same logic appears, only it is in jni.h.

It is possible that we fixed some bugs in this area since 3.4.
I don't remember.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28153


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug java/28153] Under Windows Xp the generated JNI headers need to have a '_' prepended for each function.
  2006-06-24 16:21 [Bug java/28153] New: Under Windows Xp the generated JNI headers need to have a '_' prepended for each function bcmpinc at hotmail dot com
                   ` (4 preceding siblings ...)
  2006-06-27  3:20 ` tromey at gcc dot gnu dot org
@ 2006-07-06  0:05 ` tromey at gcc dot gnu dot org
  2006-07-06 12:37 ` bcmpinc at hotmail dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: tromey at gcc dot gnu dot org @ 2006-07-06  0:05 UTC (permalink / raw)
  To: java-prs



------- Comment #6 from tromey at gcc dot gnu dot org  2006-07-06 00:05 -------
Any word on this?


-- 

tromey at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28153


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug java/28153] Under Windows Xp the generated JNI headers need to have a '_' prepended for each function.
  2006-06-24 16:21 [Bug java/28153] New: Under Windows Xp the generated JNI headers need to have a '_' prepended for each function bcmpinc at hotmail dot com
                   ` (5 preceding siblings ...)
  2006-07-06  0:05 ` tromey at gcc dot gnu dot org
@ 2006-07-06 12:37 ` bcmpinc at hotmail dot com
  2006-08-07 16:30 ` tromey at gcc dot gnu dot org
  2007-01-30 21:03 ` tromey at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: bcmpinc at hotmail dot com @ 2006-07-06 12:37 UTC (permalink / raw)
  To: java-prs



------- Comment #7 from bcmpinc at hotmail dot com  2006-07-06 12:37 -------

extern JNIEXPORT void JNICALL Java_JavaSide_sayHello (JNIEnv *env, jobject);

After preprossesing this becomes:

__attribute__((dllexport)) void __attribute__((__stdcall__))
Java_sample_myNative
  (JNIEnv *, jobject, jstring);


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28153


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug java/28153] Under Windows Xp the generated JNI headers need to have a '_' prepended for each function.
  2006-06-24 16:21 [Bug java/28153] New: Under Windows Xp the generated JNI headers need to have a '_' prepended for each function bcmpinc at hotmail dot com
                   ` (6 preceding siblings ...)
  2006-07-06 12:37 ` bcmpinc at hotmail dot com
@ 2006-08-07 16:30 ` tromey at gcc dot gnu dot org
  2007-01-30 21:03 ` tromey at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: tromey at gcc dot gnu dot org @ 2006-08-07 16:30 UTC (permalink / raw)
  To: java-prs



------- Comment #8 from tromey at gcc dot gnu dot org  2006-08-07 16:30 -------
I think comment #3 explains the problem.
So, this is either a more general GCC bug, or it is not a bug at all.
In any case it isn't a gcj problem :-)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28153


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug java/28153] Under Windows Xp the generated JNI headers need to have a '_' prepended for each function.
  2006-06-24 16:21 [Bug java/28153] New: Under Windows Xp the generated JNI headers need to have a '_' prepended for each function bcmpinc at hotmail dot com
                   ` (7 preceding siblings ...)
  2006-08-07 16:30 ` tromey at gcc dot gnu dot org
@ 2007-01-30 21:03 ` tromey at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: tromey at gcc dot gnu dot org @ 2007-01-30 21:03 UTC (permalink / raw)
  To: java-prs



------- Comment #9 from tromey at gcc dot gnu dot org  2007-01-30 21:03 -------
This was fixed a while ago.


-- 

tromey at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28153


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-01-30 21:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-24 16:21 [Bug java/28153] New: Under Windows Xp the generated JNI headers need to have a '_' prepended for each function bcmpinc at hotmail dot com
2006-06-26 17:22 ` [Bug java/28153] " tromey at gcc dot gnu dot org
2006-06-26 21:01 ` bcmpinc at hotmail dot com
2006-06-26 21:21 ` dannysmith at users dot sourceforge dot net
2006-06-26 22:26 ` dannysmith at users dot sourceforge dot net
2006-06-27  3:20 ` tromey at gcc dot gnu dot org
2006-07-06  0:05 ` tromey at gcc dot gnu dot org
2006-07-06 12:37 ` bcmpinc at hotmail dot com
2006-08-07 16:30 ` tromey at gcc dot gnu dot org
2007-01-30 21:03 ` tromey at gcc dot gnu dot org

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 read-only IMAP folder(s) and NNTP newsgroup(s).