Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sun Studio linking gcc libs: exceptions do not work

User_7ZJ07Dec 16 2014 — edited Dec 16 2014

I need to build an application with Sun Studio. This application uses a shared library which can only be build with Gnu C++. The shared lib has a C Interface, so that the code is callable by the Sun Compiler (this is to avoid name mangling issues, see also this question).

Everything besides exception handling works fine. When an exception is thrown in the shared library, the program segfaults. This happens only when the main program is compiled using the Sun Studio Compiler. Compiling the minimal example below with the Gnu C++ compiler, the program works fine and the shared lib detects the exception.

Plan A: link dynamically Here is an illustration of the setup:

GCC                         SOLARIS STUDIO
                  shared
clayer
.so         <-----    application
(no exceptions)             (uses exceptions sol studio)
  
|
  
| use flag -static -static-libstdc++ -static-lib-gcc
   v
gcc_only_lib
.so
libstdc
++.so
(uses gcc exceptions
)

Result: segmentation violation once an exception is thrown


---------------------------------------------------------------

Here is a minimal example to reproduce the problem:

exampleMain.cpp:

#include <clayer.h> #include <stdio.h> 

int main(int argc, char **argv) {

  if (!clayerCall()) printf("got exception\n");

  else printf("OK\n");

}

shared lib header:

extern "C" {  bool clayerCall();  } // end extern "C" 

shared lib source:

#include "clayer.h" 

#include <exception>

#include <stdexcept>

#include <stdio.h> 

extern "C" { 

     bool clayerCall() {

     try {

          throw std::runtime_error("hhh");

          return true;

     } catch (std::exception &ex) { return false; }

} 

} // end extern c


The cmake files look like this:

for the executable

project(exampleMain)

cmake_minimum_required(VERSION 2.8)

set(CMAKE_BUILD_TYPE Debug)

add_definitions(-m64 -fPIC) 

include_directories(../oracle_example) 

link_directories ( ../oracle_example) 

add_executable(example exampleMain.cpp)

target_link_libraries( example stdc++ clayer )

for the library

project(clayer)

cmake_minimum_required(VERSION 2.8)

cmake_policy(VERSION 2.8)

set(CMAKE_BUILD_TYPE Debug) 

add_library( clayer SHARED clayer.cpp )

Comments

Satyaki_De
It is working perfectly in my laptop.

Did you exit from your SQL prompt or How are you checking that?

Regards.

Satyaki De.
Lakmal Rajapakse
Are you connecting as CLASIE and then logging off.
Hoek
What roles are granted to the user?
DBA role perhaps?
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1844531724208
Lakmal Rajapakse
Martijn,

The DBA role does not prevent the trigger been fired. So I think this is not the cause of the issue...

rgds
Lakmal...
Hoek
Hi Lakmal,

Yes, you're right, thanks for pointing out, I was a bit too hasty with my reply.
I ran some tests (which I should have done in the first place before posting ).
SQL>  create table loginfo(msg varchar2(1000));

Table created.

SQL> create or replace trigger test
  2  before logoff on hoek.schema
  3  begin
  4  insert into loginfo values( user||' logged off @ '||to_char(sysdate, 'dd-mm-yyyy hh24:mi:ss'));
  5  end;
  6  /

Trigger created.

SQL> disc
Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> conn hoek/hoek@xe
Verbonden.
SQL> select * from loginfo;

MSG
--------------------------------------------------------------------------------------------------------------------------
HOEK logged off @ 03-03-2010 21:37:27

1 row selected.

SQL> disc
Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> conn hr/hr@xe
Verbonden.
SQL> disc
Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> conn hoek/hoek@xe
Verbonden.
SQL> select * from loginfo;

MSG
--------------------------------------------------------------------------------------------------------------------------
HOEK logged off @ 03-03-2010 21:37:27
HOEK logged off @ 03-03-2010 21:37:57

2 rows selected.

SQL> disc
Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> conn /@xe as sysdba
Verbonden.
SQL> select * from hoek.loginfo;

MSG
--------------------------------------------------------------------------------------------------------------------------
HOEK logged off @ 03-03-2010 21:37:27
HOEK logged off @ 03-03-2010 21:37:57
HOEK logged off @ 03-03-2010 21:41:17

3 rows selected.

SQL> conn hoek/hoek@xe
Verbonden.
SQL> select * from session_roles;

ROLE
------------------------------
DBA
SELECT_CATALOG_ROLE
HS_ADMIN_ROLE
EXECUTE_CATALOG_ROLE
DELETE_CATALOG_ROLE
EXP_FULL_DATABASE
IMP_FULL_DATABASE
GATHER_SYSTEM_STATISTICS
SCHEDULER_ADMIN
PLUSTRACE
XDBADMIN
XDBWEBSERVICES

12 rows selected.
Having DBA role doesn't matter.
MichaelS
when I logoff either from the terminal and from the APEX's web igu admin
which terminal?

How is APEXs web gui disconnecting?

I assume no regular disconnect in either case is made so no insert into the target table has taken place.

But starting and ending a regular sql*plus session should verify that the trigger is indeed working as expected.
741904
Hello,

With 'terminal' I meant pl*sql terminal.

In order to be sure I'm well disconnected I have made a new trigger but now on the event on 'logon'. It works fine:

CREATE OR REPLACE TRIGGER Trig7174
AFTER LOGON ON CLASIE.SCHEMA
CALL p7174

where p7174 is a procedure inserting a value into a table:

CREATE OR REPLACE PROCEDURE p7174 IS
BEGIN
INSERT INTO TEST1 VALUES('p7174');
END;

Then if I can logon I suppose it's only possible if I've been previously logoff.

So to be clear, I connect through pl*sql and I disconnect from it by the 'disconnect' command.

Thank for all suggestions.
Regards.
Claude

Edited by: claude_belgique on Mar 3, 2010 2:33 PM
1 - 7
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 13 2015
Added on Dec 16 2014
1 comment
1,014 views