Operating System - HP-UX
1820620 Members
1967 Online
109626 Solutions
New Discussion юеВ

Re: Static gcc compilation in HP-UX 10.20/11.x

 
SOLVED
Go to solution
Jim OLeary
Occasional Advisor

Static gcc compilation in HP-UX 10.20/11.x

Hi,

I'm currently trying to develop a toolkit of static binaries for HP-UX 10.20 and 11.x. I can build a majority of the binaries I need, but they all come out dynamically linked. Anybody have any advice for me besides using "gcc -static"? I'm very new to HP-UX, so I could be missing some fundamental concept (e.g. it's impossible) that's standing in my way..

any help/suggestions????
10 REPLIES 10
Mehdi_1
Regular Advisor

Re: Static gcc compilation in HP-UX 10.20/11.x

Hi

Sorry, maybe it 's me, But what you mean by static binaries? Do you mean the link between library and binaries?

If that 's the case, then you need to link to static library in order to have static binary.

If you don't specify static library, linker will link to the shared library rather than static library.


__Mehdi
Jim OLeary
Occasional Advisor

Re: Static gcc compilation in HP-UX 10.20/11.x

Yeah, that's what I'm going for. The point is to build a secure toolkit that can be used on a potentially compromised/rootkitted machine.

Basically, what I'm doing is taking the source for a bunch of different regular binaries (cp,mv,dd, all that stuff) and compiling it statically. (no dependence on any outside files, not dynamically linked).

Just to clarify: when I do--
$ ldd (mybinary)
I want to see:
'not a dynamic executable'

hope this clears it up :)
Jim OLeary
Occasional Advisor

Re: Static gcc compilation in HP-UX 10.20/11.x

Also, I've been poking around online and exploring other options.. it's not essential that I use gcc, but I figured that would be a safe bet because it's what I'm most familiar with on a nix platform.
Jim OLeary
Occasional Advisor

Re: Static gcc compilation in HP-UX 10.20/11.x

anybody??? looks like I do need to use gcc for this particular project...
Steven Gillard_2
Honored Contributor
Solution

Re: Static gcc compilation in HP-UX 10.20/11.x

Well, gcc -static should prevent linking with shared libraries - it works ok here.

Can you provide more details:
* What is the full command line you are using to build the executable?
* What shared libraries end up being linked in?
* Can you run "chatr" on one of the executables and post the output?

Regards,
Steve
benoit Bruckert
Honored Contributor

Re: Static gcc compilation in HP-UX 10.20/11.x

Hi,
from man gcc :
Linker Options
-llibrary -nostartfiles -nostdlib -static -shared -symbolic
-Xlinker option -Wl,option -u symbol
and
-static
On systems that support dynamic linking, this prevents linking
with the shared libraries. On other systems, this option has no
effect.

i think the -static seems to be what you want.
hth
Benoit
Une application mal pans├йe aboutit ├а une usine ├а gaze (GHG)
H.Merijn Brand (procura
Honored Contributor

Re: Static gcc compilation in HP-UX 10.20/11.x

One problem might be that the Makefile should be edited to do realy static build, because gcc -static builds static 'objects', but it probably still uses HP's 'ld' for the linking.

If 'LDFLAGS' does not contain '-static', the final exacutable is still dynamic :(

[ Who just found out this morning in building a static less-381-pa1.1 with pcre for use on SEP's machine. It's now available on my site ]

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Jim OLeary
Occasional Advisor

Re: Static gcc compilation in HP-UX 10.20/11.x

Thanks a lot for the responses so far!

Basically, I'm trying to do this:

http://www.netadmintools.com/part279.html
Jim OLeary
Occasional Advisor

Re: Static gcc compilation in HP-UX 10.20/11.x

ooooops, I was a little quick to hit "submit"


to keep it all in one place, and avoid clicking links.. here's an example:

[blah@asdf coreutils-5.0]$ ./configure
[blah@asdf coreutils-5.0]$ make CC="gcc -static"

[urbana@hazel binutils]$ ./configure
[urbana@hazel binutils]$ make -e LDFLAGS=-all-static

H.Merijn Brand (procura
Honored Contributor

Re: Static gcc compilation in HP-UX 10.20/11.x

maybe there are two easier solutions:

1.
# env CFLAGS=-static LDFLAGS=-static ./configure ...

2.
# export CONFIG_SITE=/tmp/static.pol
# cat >/tmp/static.pol
CFLAGS=-static
LDFLAGS=-static
^D
#

All GNU configure scripts will use the script set in $CONFIG_SITE when it exists. You can make several. Here the head of mine:

a5:/pro/3gl/GNU 103 > head -20 Policy.sh
# $CONFIG_SITE -> /pro/3gl/GNU/policy.sh

echo "OSTYPE: $OSTYPE, CC: $CC, CFLAGS: $CFLAGS, LDFLAGS: $LDFLAGS"
if [ $OSTYPE = hpux -a ${CC:-x} = x ]; then
CC=cc
# CFLAGS="-Ae -fast +Onolimit"
LDFLAGS="-Wl,+vnocompatwarnings $LDFLAGS"
CFLAGS="-Ae +O2 +Onolimit $CFLAGS"
if [ $HOST = d3 ]; then
CFLAGS=$CFLAGS" +DAportable"
fi
elif [ $OSTYPE = aix -a ${CC:-x} = x ]; then
CC=cc
CFLAGS="-O2 -qmaxmem=204800"
elif [ $OSTYPE = osf1 ]; then
CC=cc
CFLAGS="-O2 -std"
elif [ ${CC:-x} = gcc -o ${CC:-x} = gcc32 -o ${CC:-x} = gcc64 ]; then
CFLAGS="-O4 $CFLAGS"
else
a5:/pro/3gl/GNU 104 >

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn