Position Independent Code

 
kishore_10
New Member

Position Independent Code

How to create Position Independent Code using HP's assembler "as" command?

I am trying to compile "Openssl on HPUX 10.20"

# uname -a
HP-UX SIS B.10.20 A 9000/867 ........

There is a "pa-risc.s" file
I am trying to produce pa-risc.o file using following command.

# as +z pa-risc.s -o pa-risc.o

it is producing pa-risc.o file however with lot of warnings, some of the warning are...

as: "pa-risc.s", line 649: warning 36: Use of %fr10R is incorrect for the current LEVEL of 1.0
as: "pa-risc.s", line 649: warning 36: Use of XMPYU is incorrect for the current LEVEL of 1.0
as: "pa-risc.s", line 651: warning 36: Use of %fr9R is incorrect for the current LEVEL of 1.0
.......etc.

and when i build to produce shared library and i am getting following error

/usr/ccs/bin/ld: DP relative code in file libcrypto.a(pa-risc.o) - shared library must be position
independent. Use +z or +Z to recompile.
*** Error exit code 1

what is going wrong :(, my unix knowledge is very less, can any body help me?

I also tried to produce pa-risc.o file with GNU binutil 2.11.2 "as". it is producing .o file without any problem, however it is not a PIC code, I am unable to find a way to produce PIC code with GNU's "as"

pa-risc.s file is attached with the message

please help me to solve this problem
10 REPLIES 10
ranganath ramachandra
Esteemed Contributor

Re: Position Independent Code

the linker is telling you the compiler option to use (it thinks you compiled a c program). i think, unfortunately it is at the assembly code level that the difference between pic and non-pic code lies - to get pic code you have to write pic code in the assembly. the code you have was not written pic and hence not for a shared library. are you sure you need it to build a shared library ?
 
--
ranga
(i work for hpe)

Accept or Kudo

Mike Stroyan
Honored Contributor

Re: Position Independent Code

The "warning 36" messages are because the instructions and register names are for a higher level than the default PA1.0.
You should have a ".LEVEL 2.0" directive in the file.

The code looks very much like the output of "cc -S". Perhaps you started from C code and intended to tweak the assembly language somehow. If it was initially created that way you should just go back and use "cc +z -S" to create PIC instructions to start from.

PIC code needs to refer to functions and global variables using relative branches and DLT table lookups. That is discussed somewhat in the "HP Assembler Reference Manual" at
http://www.docs.hp.com./hpux/dev/index.html#Assembler
Mike Stroyan
Honored Contributor

Re: Position Independent Code

I overlooked that you were on 10.20. That will only go as high as ".LEVEL 1.1".

If there is no .c version of this pa-risc.s file, then you would need to rewrite many
instructions to create equivalent PIC code.
kishore_10
New Member

Re: Position Independent Code

Hi, Thanks to all,
First of all that code pa-risc.s along with openssl. I dont know how to write assembly code at all. I think openssl has its equivalant .c file, using that I ll try to produce new .s file. And yes i need to create shared library.

I have one question,
basically i am trying to use assembly to enhance the performance of my shared library. Is it worth to convert the .c file to .s and then produce .o file and then use it to produce shared library.

once again thanks a lot.
Muthukumar_5
Honored Contributor

Re: Position Independent Code

Hai,

It is worth to create the .c file with debugging symbols (-g) and then using the ld command. Don't use the main() program in the in .c which is to be converted as shared library. If you want to do the postion independant,compile the .c file with -WI,+nodefaultrpath flags.

Use the steps as.,

cc -g -o *.c -WI,+nodefaultrpath
some warnings will be come for using the .c file without main()
ld -o -b <*.o>

We can get the assembley information using the debugging symbols on gdb or wdb with info assembley command. The step of changes will be decreased. Using the debugging symbols will be very good to debug the problem and all.

Regards,
Muthukumar.
Easy to suggest when don't know about the problem!
ranganath ramachandra
Esteemed Contributor

Re: Position Independent Code

read the README ... :)
---
All assember in this directory are just version of the file crypto/bn/bn_mulw.c.
---

you just have to change the makefile to use this C file instead of the assembly source. just make sure you change the makefile to compile it with +z/+Z (if using cc/aCC) or -fpic/-fPIC (if using gcc).
 
--
ranga
(i work for hpe)

Accept or Kudo

ranganath ramachandra
Esteemed Contributor

Re: Position Independent Code

ok i just saw the the top level Makefile itself lets you use the C code:
----
# Set BN_ASM to bn_asm.o if you want to use the C version
BN_ASM= bn_asm.o
----
i guess you have set it to
BN_ASM= asm/pa-risc2.o # HP-UX PA-RISC

i think using the C code is much better than using assembly because if you are building position independent code, the compiler can do a lot more optimization for that case. this is especially true if you dont know assembly :)
 
--
ranga
(i work for hpe)

Accept or Kudo

kishore_10
New Member

Re: Position Independent Code

Hi ranganath,
First of all Thanks a lot for you support,

As you thought, yes, I have changed the make file in order to use asm/pa-risc.s file (Not pa-risc2.s it is for RISC 2.0).

From the replies i came to know that, pa-risc.s file not a PIC file. As Mike Stroyans adviced, I am trying to produce new pa-risc.s file from bn_asm.c file. Before that please tell me one thing, is it worth to do that. What i mean to say is, producing a pa-risc.o file using .c or from .s file which one is faster. (same thing i asked in my previous question.)

regards,
Kishore
ranganath ramachandra
Esteemed Contributor

Re: Position Independent Code

i dont think it makes a difference in execution. it may in fact be better to leave it as C code, because all optimizations will be dont prior to the assembler stage. the next time you want to build, you may be able to make use of the better optimization of a newer version of the compiler or another compiler altogether.
 
--
ranga
(i work for hpe)

Accept or Kudo