LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 06-14-2012, 05:10 AM   #1
RajeshMani
LQ Newbie
 
Registered: Mar 2012
Posts: 4

Rep: Reputation: Disabled
Question Migration issue from unix to linux


I have faced with following issues during the migration of an application from Unix (Solaris - 32 bit OS) to RHEL 5 (64 bit OS). I will be very much thankful to whom who can give some idea on it.
(1) One of the code uses #pragma ident, #ident and #pragma map, which is ignored when compiled in Linux. Will it affect in the functioning / performance of the application.
(2) Is there any problem - during 32 bit to 64 bit conversion, in using function pointers (doubly linked list) as an element in structures.
(3) What are the major issues to be considered while doing this type of migration

Thank You
 
Old 06-15-2012, 02:41 PM   #2
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, Debian, EasyPeasy, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,671
Blog Entries: 20

Rep: Reputation: 111Reputation: 111
1. It would be an unusual app that would be affected by those. Portable apps normally would not be. But you may face the issue if the app was written for Solaris and you are now porting it to Linux/GNU.

2. Function pointers, like other pointers, will be larger. Structs having pointers should not normally be used for writing external data. But some programmers are know do such a dumb thing, so if the data goes external and comes back, written by the 32 bit version and read by by the 64 bit version, you'll have much trouble. But that trouble can sometimes exist even with different C compilers for the same pointer size.

3. At the programming level, be sure your code is written in the properly semi-abstract portable manner (reference symbols that describe the architecture instead of hard coding numbers. A few constants like 0xffffffff might need to be rewritten ... (~0) would be a better way that adapts to the integer size.
 
1 members found this post helpful.
Old 06-15-2012, 03:24 PM   #3
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
I'd like to add to what Skaparen wrote that you should pay particular attention to code that uses int variables to temporarily hold the value of a pointer. That is surprisingly common, and will fail when you move from 32-bit to 64-bit architectures.

One should use intptr_t from stdint.h instead of int to store a pointer in an integer variable. If that is not possible, then one can, in practice, use long. (Code that uses long to store pointers works fine in Linux, because all 32-bit architectures are ILP32 and 64-bit LP64; thus long and pointer always the same size.)
 
Old 06-15-2012, 07:34 PM   #4
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, Debian, EasyPeasy, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,671
Blog Entries: 20

Rep: Reputation: 111Reputation: 111
I would just avoid using an integer to hold a pointer where possible. But legacy code often has these issues, often from the days when people thought 640K is all the memory anyone would ever need.
 
Old 06-16-2012, 10:45 AM   #5
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by Skaperen View Post
I would just avoid using an integer to hold a pointer where possible. But legacy code often has these issues, often from the days when people thought 640K is all the memory anyone would ever need.
No need to insult! We are, after all, talking about Unix systems, not some dumpster-diven mockery of an operating system.

The typical use is actually the opposite -- using a void pointer to hold an integer value -- but the same rules apply: don't use int, use intptr_t if possible (and long otherwise). A lot of interfaces use a void pointer to hold any type of user data; the pthread thread functions are a good example.

I was racking my brain to think of any good examples where one might need to hold a pointer in an integer variable (instead of the opposite), but I could not think of any. I don't think I've ever needed to do so myself. (Pointer differences I often store in integer variables; in general, one should use ptrdiff_t, but if you know the order of the pointers, then size_t is safe, too. That is not the same thing, however.)

So, I do agree: don't use an integer to hold a pointer. But, like I said, one may have to use a (void) pointer to hold an integer; and then, the integer should be of intptr_t or long type.
 
Old 06-17-2012, 08:46 AM   #6
Maz_
LQ Newbie
 
Registered: May 2006
Location: Finland
Distribution: fedora
Posts: 15

Rep: Reputation: 0
also pay attention to compiler warnings. For example fumction returning pointer with no declaration works on 32 bit world (because int is the default return value). On 64 bit world returned address may be truncated.

And ints were typically used to hold pointer values when some pointer arithmetic was involved.
 
Old 06-17-2012, 09:57 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,033

Rep: Reputation: 285Reputation: 285Reputation: 285
Just try it; if your program compiles and works without problems, then everything is okay; otherwise try one or more of these:

* switch to 32 bit mode: -m32 flag at compilation and linking
* examine compiler warnings (if any; use flags -W -Wall -pedantic)
* use debugger (if there are runtime errors)
* use efence (or similar product) if suspect invalid memory usage
* examine the whole code carefully (takes lot of time)
 
Old 06-18-2012, 02:40 AM   #8
RajeshMani
LQ Newbie
 
Registered: Mar 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by Skaperen View Post
1. It would be an unusual app that would be affected by those. Portable apps normally would not be. But you may face the issue if the app was written for Solaris and you are now porting it to Linux/GNU.

2. Function pointers, like other pointers, will be larger. Structs having pointers should not normally be used for writing external data. But some programmers are know do such a dumb thing, so if the data goes external and comes back, written by the 32 bit version and read by by the 64 bit version, you'll have much trouble. But that trouble can sometimes exist even with different C compilers for the same pointer size.

3. At the programming level, be sure your code is written in the properly semi-abstract portable manner (reference symbols that describe the architecture instead of hard coding numbers. A few constants like 0xffffffff might need to be rewritten ... (~0) would be a better way that adapts to the integer size.
Hi Skaperen,

Thank You for attending my query.

As you said that there may arise problems when migrating from Solaris to Linux in para 1, the same happened to me. Can you distinguish anyone (like pragma etc)?

And about function pointers, these are used to create/generate some messaging structures for data interchange. Initially it was designed in 32 bit Solaris and now migrating to RHEL5 (64 bit), and this is also a constraint to me which is not able to create the structure properly.
 
Old 06-18-2012, 01:44 PM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,033

Rep: Reputation: 285Reputation: 285Reputation: 285
The best idea would be actually trying to compile and run the program.
 
Old 06-19-2012, 02:15 AM   #10
Maz_
LQ Newbie
 
Registered: May 2006
Location: Finland
Distribution: fedora
Posts: 15

Rep: Reputation: 0
nevem is correct. Try it out. Also running program with valgrind might ve a good idea - although if program has some strict timing criterias you may not be able to use valgrind which typically significantly slows down execution.
 
Old 06-19-2012, 02:40 AM   #11
Expertsfromindia
LQ Newbie
 
Registered: Jun 2012
Posts: 3

Rep: Reputation: 0
i m agree with Maz_
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Migration of data file in Unix to linux pandunr Linux - Newbie 3 08-11-2011 12:49 AM
Unix to Linux permissions issue mindcontrolusa Linux - General 2 01-06-2011 04:35 PM
server Migration unix to redhat linux mmee Red Hat 5 01-17-2010 10:28 PM
Migration d'UNIX vers Linux ou Windows Elise78 Linux - Enterprise 3 06-02-2004 10:17 AM
Linux 7 to 9 namespace migration issue er13b6ac Linux - Software 1 09-09-2003 05:27 AM


All times are GMT -5. The time now is 10:52 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration