Tue, 10 Jun 2008 16:39:20 -0700
6647068: libjvm.so is not built PIC
Summary: Remove the preferred base address built with libjvm.so and unified the PIC approach on Solaris & Linux.
Reviewed-by: never, kamg
Contributed-by: xiaobin.lu@sun.com
1 #
2 # Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # This code is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License version 2 only, as
7 # published by the Free Software Foundation.
8 #
9 # This code is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # version 2 for more details (a copy is included in the LICENSE file that
13 # accompanied this code).
14 #
15 # You should have received a copy of the GNU General Public License version
16 # 2 along with this work; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 #
19 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 # CA 95054 USA or visit www.sun.com if you need additional information or
21 # have any questions.
22 #
23 #
25 # Compiler-specific flags for sparcworks.
27 # tell make which C and C++ compilers to use
28 CC = cc
29 CPP = CC
31 # Note that this 'as' is an older version of the Sun Studio 'fbe', and will
32 # use the older style options. The 'fbe' options will match 'cc' and 'CC'.
33 AS = /usr/ccs/bin/as
35 NM = /usr/ccs/bin/nm
36 NAWK = /bin/nawk
38 REORDER_FLAG = -xF
40 # Check for the versions of C++ and C compilers ($CPP and $CC) used.
42 # Get the last thing on the line that looks like x.x+ (x is a digit).
43 COMPILER_REV := \
44 $(shell $(CPP) -V 2>&1 | sed -e 's/^.*\([1-9]\.[0-9][0-9]*\).*/\1/')
45 C_COMPILER_REV := \
46 $(shell $(CC) -V 2>&1 | grep -i "cc:" | sed -e 's/^.*\([1-9]\.[0-9][0-9]*\).*/\1/')
48 # Pick which compiler is validated
49 ifeq ($(JDK_MINOR_VERSION),6)
50 # Validated compiler for JDK6 is SS11 (5.8)
51 VALIDATED_COMPILER_REV := 5.8
52 VALIDATED_C_COMPILER_REV := 5.8
53 else
54 # FIXUP: Change to SS12 (5.9) once it has been validated.
55 # Validated compiler for JDK7 is SS12 (5.9)
56 #VALIDATED_COMPILER_REV := 5.9
57 #VALIDATED_C_COMPILER_REV := 5.9
58 VALIDATED_COMPILER_REV := 5.8
59 VALIDATED_C_COMPILER_REV := 5.8
60 endif
62 # Warning messages about not using the above validated version
63 ENFORCE_COMPILER_REV${ENFORCE_COMPILER_REV} := ${VALIDATED_COMPILER_REV}
64 ifneq (${COMPILER_REV},${ENFORCE_COMPILER_REV})
65 dummy_target_to_enforce_compiler_rev:=\
66 $(info WARNING: You are using CC version ${COMPILER_REV} \
67 and should be using version ${ENFORCE_COMPILER_REV})
68 endif
70 ENFORCE_C_COMPILER_REV${ENFORCE_C_COMPILER_REV} := ${VALIDATED_C_COMPILER_REV}
71 ifneq (${C_COMPILER_REV},${ENFORCE_C_COMPILER_REV})
72 dummy_target_to_enforce_c_compiler_rev:=\
73 $(info WARNING: You are using cc version ${C_COMPILER_REV} \
74 and should be using version ${ENFORCE_C_COMPILER_REV})
75 endif
77 # Fail the build if __fabsf is used. __fabsf exists only in Solaris 8 2/04
78 # and newer; objects with a dependency on this symbol will not run on older
79 # Solaris 8.
80 JVM_FAIL_IF_UNDEFINED = __fabsf
82 JVM_CHECK_SYMBOLS = $(NM) -u -p $(LIBJVM.o) | \
83 $(NAWK) -v f="${JVM_FAIL_IF_UNDEFINED}" \
84 'BEGIN { c=split(f,s); rc=0; } \
85 /:$$/ { file = $$1; } \
86 /[^:]$$/ { for(n=1;n<=c;++n) { \
87 if($$1==s[n]) { \
88 printf("JVM_CHECK_SYMBOLS: %s contains illegal symbol %s\n", \
89 file,$$1); \
90 rc=1; \
91 } \
92 } \
93 } \
94 END { exit rc; }'
96 LINK_LIB.CC/PRE_HOOK += $(JVM_CHECK_SYMBOLS) || exit 1;
98 # Some interfaces (_lwp_create) changed with LP64 and Solaris 7
99 SOLARIS_7_OR_LATER := \
100 $(shell uname -r | awk -F. '{ if ($$2 >= 7) print "-DSOLARIS_7_OR_LATER"; }')
101 CFLAGS += ${SOLARIS_7_OR_LATER}
103 # New architecture options started in SS12 (5.9), we need both styles to build.
104 # The older arch options for SS11 (5.8) or older and also for /usr/ccs/bin/as.
105 # Note: SS12 default for 32bit sparc is now the same as v8plus, so the
106 # settings below have changed all SS12 32bit sparc builds to be v8plus.
107 # The older SS11 (5.8) settings have remained as they always have been.
108 ifeq ($(TYPE),COMPILER2)
109 ARCHFLAG_OLD/sparc = -xarch=v8plus
110 else
111 ifeq ($(TYPE),TIERED)
112 ARCHFLAG_OLD/sparc = -xarch=v8plus
113 else
114 ARCHFLAG_OLD/sparc = -xarch=v8
115 endif
116 endif
117 ARCHFLAG_NEW/sparc = -m32 -xarch=sparc
118 ARCHFLAG_OLD/sparcv9 = -xarch=v9
119 ARCHFLAG_NEW/sparcv9 = -m64 -xarch=sparc
120 ARCHFLAG_OLD/i486 =
121 ARCHFLAG_NEW/i486 = -m32
122 ARCHFLAG_OLD/amd64 = -xarch=amd64
123 ARCHFLAG_NEW/amd64 = -m64
125 # Select the ARCHFLAGs and other SS12 (5.9) options
126 ifeq ($(shell expr $(COMPILER_REV) \>= 5.9), 1)
127 ARCHFLAG/sparc = $(ARCHFLAG_NEW/sparc)
128 ARCHFLAG/sparcv9 = $(ARCHFLAG_NEW/sparcv9)
129 ARCHFLAG/i486 = $(ARCHFLAG_NEW/i486)
130 ARCHFLAG/amd64 = $(ARCHFLAG_NEW/amd64)
131 else
132 ARCHFLAG/sparc = $(ARCHFLAG_OLD/sparc)
133 ARCHFLAG/sparcv9 = $(ARCHFLAG_OLD/sparcv9)
134 ARCHFLAG/i486 = $(ARCHFLAG_OLD/i486)
135 ARCHFLAG/amd64 = $(ARCHFLAG_OLD/amd64)
136 endif
138 # ARCHFLAGS for the current build arch
139 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH))
140 AS_ARCHFLAG = $(ARCHFLAG_OLD/$(BUILDARCH))
142 # Optional sub-directory in /usr/lib where BUILDARCH libraries are kept.
143 ISA_DIR=$(ISA_DIR/$(BUILDARCH))
144 ISA_DIR/sparcv9=/sparcv9
145 ISA_DIR/amd64=/amd64
147 # Use these to work around compiler bugs:
148 OPT_CFLAGS/SLOWER=-xO3
149 OPT_CFLAGS/O2=-xO2
150 OPT_CFLAGS/NOOPT=-xO1
152 #################################################
153 # Begin current (>=5.6) Forte compiler options #
154 #################################################
156 ifeq ($(shell expr $(COMPILER_REV) \>= 5.6), 1)
158 ifeq ("${Platform_arch}", "sparc")
160 # We MUST allow data alignment of 4 for sparc (sparcv9 is ok at 8s)
161 ifndef LP64
162 CFLAGS += -xmemalign=4s
163 endif
165 endif
167 endif
169 #################################################
170 # Begin current (>=5.5) Forte compiler options #
171 #################################################
173 ifeq ($(shell expr $(COMPILER_REV) \>= 5.5), 1)
175 CFLAGS += $(ARCHFLAG)
176 AOUT_FLAGS += $(ARCHFLAG)
177 LIB_FLAGS += $(ARCHFLAG)
178 LFLAGS += $(ARCHFLAG)
180 ifeq ("${Platform_arch}", "sparc")
182 # Flags for Optimization
184 # [phh] Commented out pending verification that we do indeed want
185 # to potentially bias against u1 and u3 targets.
186 #CFLAGS += -xchip=ultra2
188 OPT_CFLAGS=-xO4 $(EXTRA_OPT_CFLAGS)
190 endif # sparc
192 ifeq ("${Platform_arch_model}", "x86_32")
194 OPT_CFLAGS=-xtarget=pentium $(EXTRA_OPT_CFLAGS)
196 # UBE (CC 5.5) has bug 4923569 with -xO4
197 OPT_CFLAGS+=-xO3
199 endif # 32bit x86
201 ifeq ("${Platform_arch_model}", "x86_64")
203 ASFLAGS += $(AS_ARCHFLAG)
204 CFLAGS += $(ARCHFLAG/amd64)
205 # this one seemed useless
206 LFLAGS_VM += $(ARCHFLAG/amd64)
207 # this one worked
208 LFLAGS += $(ARCHFLAG/amd64)
209 AOUT_FLAGS += $(ARCHFLAG/amd64)
211 # -xO3 is faster than -xO4 on specjbb with SS10 compiler
212 OPT_CFLAGS=-xO4 $(EXTRA_OPT_CFLAGS)
214 endif # 64bit x86
216 # Inline functions
217 CFLAGS += $(GAMMADIR)/src/os_cpu/solaris_${Platform_arch}/vm/solaris_${Platform_arch_model}.il
219 # no more exceptions
220 CFLAGS/NOEX=-features=no%except
223 # avoid compilation problems arising from fact that C++ compiler tries
224 # to search for external template definition by just compiling additional
225 # source files in th same context
226 CFLAGS += -template=no%extdef
228 # Reduce code bloat by reverting back to 5.0 behavior for static initializers
229 CFLAGS += -features=no%split_init
231 # Use -D_Crun_inline_placement so we don't get references to
232 # __1c2n6FIpv_0_ or void*operator new(unsigned,void*)
233 # This avoids the hard requirement of the newer Solaris C++ runtime patches.
234 # NOTE: This is an undocumented feature of the SS10 compiler. See 6306698.
235 CFLAGS += -D_Crun_inline_placement
237 # PIC is safer for SPARC, and is considerably slower
238 # a file foo.o which wants to compile -pic can set "PICFLAG/foo.o = -PIC"
239 PICFLAG = -KPIC
240 PICFLAG/DEFAULT = $(PICFLAG)
241 # [RGV] Need to figure which files to remove to get link to work
242 #PICFLAG/BETTER = -pic
243 PICFLAG/BETTER = $(PICFLAG/DEFAULT)
244 PICFLAG/BYFILE = $(PICFLAG/$@)$(PICFLAG/DEFAULT$(PICFLAG/$@))
246 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file.
247 MAPFLAG = -M FILENAME
249 # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
250 SONAMEFLAG = -h SONAME
252 # Build shared library
253 SHARED_FLAG = -G
255 # We don't need libCstd.so and librwtools7.so, only libCrun.so
256 CFLAGS += -library=%none
257 LFLAGS += -library=%none
259 LFLAGS += -mt
261 endif # COMPILER_REV >= 5.5
263 ######################################
264 # End 5.5 Forte compiler options #
265 ######################################
267 ######################################
268 # Begin 5.2 Forte compiler options #
269 ######################################
271 ifeq ($(COMPILER_REV), 5.2)
273 CFLAGS += $(ARCHFLAG)
274 AOUT_FLAGS += $(ARCHFLAG)
275 LIB_FLAGS += $(ARCHFLAG)
276 LFLAGS += $(ARCHFLAG)
278 ifeq ("${Platform_arch}", "sparc")
280 # Flags for Optimization
282 # [phh] Commented out pending verification that we do indeed want
283 # to potentially bias against u1 and u3 targets.
284 #CFLAGS += -xchip=ultra2
286 ifdef LP64
287 # SC5.0 tools on v9 are flakey at -xO4
288 # [phh] Is this still true for 6.1?
289 OPT_CFLAGS=-xO3 $(EXTRA_OPT_CFLAGS)
290 else
291 OPT_CFLAGS=-xO4 $(EXTRA_OPT_CFLAGS)
292 endif
294 CFLAGS += $(GAMMADIR)/src/os_cpu/solaris_sparc/vm/solaris_sparc.il
296 endif # sparc
298 ifeq ("${Platform_arch_model}", "x86_32")
300 OPT_CFLAGS=-xtarget=pentium $(EXTRA_OPT_CFLAGS)
302 # SC5.0 tools on x86 are flakey at -xO4
303 # [phh] Is this still true for 6.1?
304 OPT_CFLAGS+=-xO3
306 CFLAGS += $(GAMMADIR)/src/os_cpu/solaris_x86/vm/solaris_x86_32.il
308 endif # 32bit x86
310 # no more exceptions
311 CFLAGS/NOEX=-noex
313 # Reduce code bloat by reverting back to 5.0 behavior for static initializers
314 CFLAGS += -Qoption ccfe -one_static_init
316 # PIC is safer for SPARC, and is considerably slower
317 # a file foo.o which wants to compile -pic can set "PICFLAG/foo.o = -PIC"
318 PICFLAG = -KPIC
319 PICFLAG/DEFAULT = $(PICFLAG)
320 # [RGV] Need to figure which files to remove to get link to work
321 #PICFLAG/BETTER = -pic
322 PICFLAG/BETTER = $(PICFLAG/DEFAULT)
323 PICFLAG/BYFILE = $(PICFLAG/$@)$(PICFLAG/DEFAULT$(PICFLAG/$@))
325 # Would be better if these weren't needed, since we link with CC, but
326 # at present removing them causes run-time errors
327 LFLAGS += -library=Crun
328 LIBS += -library=Crun -lCrun
330 endif # COMPILER_REV == 5.2
332 ##################################
333 # End 5.2 Forte compiler options #
334 ##################################
336 ##################################
337 # Begin old 5.1 compiler options #
338 ##################################
339 ifeq ($(COMPILER_REV), 5.1)
341 _JUNK_ := $(shell echo >&2 \
342 "*** ERROR: sparkWorks.make incomplete for 5.1 compiler")
343 @exit 1
344 endif
345 ##################################
346 # End old 5.1 compiler options #
347 ##################################
349 ##################################
350 # Begin old 5.0 compiler options #
351 ##################################
353 ifeq (${COMPILER_REV}, 5.0)
355 # Had to hoist this higher apparently because of other changes. Must
356 # come before -xarch specification.
357 # NOTE: native says optimize for the machine doing the compile, bad news.
358 CFLAGS += -xtarget=native
360 CFLAGS += $(ARCHFLAG)
361 AOUT_FLAGS += $(ARCHFLAG)
362 LIB_FLAGS += $(ARCHFLAG)
363 LFLAGS += $(ARCHFLAG)
365 CFLAGS += -library=iostream
366 LFLAGS += -library=iostream -library=Crun
367 LIBS += -library=iostream -library=Crun -lCrun
369 # Flags for Optimization
370 ifdef LP64
371 # SC5.0 tools on v9 are flakey at -xO4
372 OPT_CFLAGS=-xO3 $(EXTRA_OPT_CFLAGS)
373 else
374 OPT_CFLAGS=-xO4 $(EXTRA_OPT_CFLAGS)
375 endif
377 ifeq ("${Platform_arch}", "sparc")
379 CFLAGS += $(GAMMADIR)/src/os_cpu/solaris_sparc/vm/atomic_solaris_sparc.il
381 endif # sparc
383 ifeq ("${Platform_arch_model}", "x86_32")
384 OPT_CFLAGS=-xtarget=pentium $(EXTRA_OPT_CFLAGS)
385 ifeq ("${COMPILER_REV}", "5.0")
386 # SC5.0 tools on x86 are flakey at -xO4
387 OPT_CFLAGS+=-xO3
388 else
389 OPT_CFLAGS+=-xO4
390 endif
392 CFLAGS += $(GAMMADIR)/src/os_cpu/solaris_x86/vm/solaris_x86_32.il
394 endif # 32bit x86
396 # The following options run into misaligned ldd problem (raj)
397 #OPT_CFLAGS = -fast -O4 $(ARCHFLAG/sparc) -xchip=ultra
399 # no more exceptions
400 CFLAGS/NOEX=-noex
402 # PIC is safer for SPARC, and is considerably slower
403 # a file foo.o which wants to compile -pic can set "PICFLAG/foo.o = -PIC"
404 PICFLAG = -PIC
405 PICFLAG/DEFAULT = $(PICFLAG)
406 # [RGV] Need to figure which files to remove to get link to work
407 #PICFLAG/BETTER = -pic
408 PICFLAG/BETTER = $(PICFLAG/DEFAULT)
409 PICFLAG/BYFILE = $(PICFLAG/$@)$(PICFLAG/DEFAULT$(PICFLAG/$@))
411 endif # COMPILER_REV = 5.0
413 ################################
414 # End old 5.0 compiler options #
415 ################################
417 ifeq ("${COMPILER_REV}", "4.2")
418 # 4.2 COMPILERS SHOULD NO LONGER BE USED
419 _JUNK_ := $(shell echo >&2 \
420 "*** ERROR: SC4.2 compilers are not supported by this code base!")
421 @exit 1
422 endif
424 # do not include shared lib path in a.outs
425 AOUT_FLAGS += -norunpath
426 LFLAGS_VM = -norunpath -z noversion
428 # need position-indep-code for shared libraries
429 # (ild appears to get errors on PIC code, so we'll try non-PIC for debug)
430 ifeq ($(PICFLAGS),DEFAULT)
431 VM_PICFLAG/LIBJVM = $(PICFLAG/DEFAULT)
432 else
433 VM_PICFLAG/LIBJVM = $(PICFLAG/BYFILE)
434 endif
435 VM_PICFLAG/AOUT =
437 VM_PICFLAG = $(VM_PICFLAG/$(LINK_INTO))
438 CFLAGS += $(VM_PICFLAG)
440 # less dynamic linking (no PLTs, please)
441 #LIB_FLAGS += $(LINK_MODE)
442 # %%%%% despite -znodefs, -Bsymbolic gets link errors -- Rose
444 LINK_MODE = $(LINK_MODE/$(VERSION))
445 LINK_MODE/debug =
446 LINK_MODE/optimized = -Bsymbolic -znodefs
448 # Have thread local errnos
449 ifeq ($(shell expr $(COMPILER_REV) \>= 5.5), 1)
450 CFLAGS += -mt
451 else
452 CFLAGS += -D_REENTRANT
453 endif
455 ifdef CC_INTERP
456 # C++ Interpreter
457 CFLAGS += -DCC_INTERP
458 endif
460 # Flags for Debugging
461 DEBUG_CFLAGS = -g
462 FASTDEBUG_CFLAGS = -g0
463 # The -g0 setting allows the C++ frontend to inline, which is a big win.
465 # Special global options for SS12
466 ifeq ($(COMPILER_REV),5.9)
467 # There appears to be multiple issues with the new Dwarf2 debug format, so
468 # we tell the compiler to use the older 'stabs' debug format all the time.
469 # Note that this needs to be used in optimized compiles too to be 100%.
470 # This is a workaround for SS12 (5.9) bug 6694600
471 CFLAGS += -xdebugformat=stabs
472 endif
474 # Enable the following CFLAGS additions if you need to compare the
475 # built ELF objects.
476 #
477 # The -g option makes static data global and the "-Qoption ccfe
478 # -xglobalstatic" option tells the compiler to not globalize static
479 # data using a unique globalization prefix. Instead force the use of
480 # a static globalization prefix based on the source filepath so the
481 # objects from two identical compilations are the same.
482 #DEBUG_CFLAGS += -Qoption ccfe -xglobalstatic
483 #FASTDEBUG_CFLAGS += -Qoption ccfe -xglobalstatic
485 ifeq (${COMPILER_REV}, 5.2)
486 COMPILER_DATE := $(shell $(CPP) -V 2>&1 | awk '{ print $$NF; }')
487 ifeq (${COMPILER_DATE}, 2001/01/31)
488 # disable -g0 in fastdebug since SC6.1 dated 2001/01/31 seems to be buggy
489 # use an innocuous value because it will get -g if it's empty
490 FASTDEBUG_CFLAGS = -c
491 endif
492 endif
494 # Uncomment or 'gmake CFLAGS_BROWSE=-sbfast' to get source browser information.
495 # CFLAGS_BROWSE = -sbfast
496 CFLAGS += $(CFLAGS_BROWSE)
498 # ILD is gone as of SS11 (5.8), not supportted in SS10 (5.7)
499 ifeq ($(shell expr $(COMPILER_REV) \< 5.7), 1)
500 # use ild when debugging (but when optimizing we want reproducible results)
501 ILDFLAG = $(ILDFLAG/$(VERSION))
502 ILDFLAG/debug = -xildon
503 ILDFLAG/optimized =
504 AOUT_FLAGS += $(ILDFLAG)
505 endif
507 # Where to put the *.o files (a.out, or shared library)?
508 LINK_INTO = $(LINK_INTO/$(VERSION))
509 LINK_INTO/debug = LIBJVM
510 LINK_INTO/optimized = LIBJVM
512 # We link the debug version into the a.out because:
513 # 1. ild works on a.out but not shared libraries, and using ild
514 # can cut rebuild times by 25% for small changes. (ILD is gone in SS11)
515 # 2. dbx cannot gracefully set breakpoints in shared libraries
516 #
518 # apply this setting to link into the shared library even in the debug version:
519 ifdef LP64
520 LINK_INTO = LIBJVM
521 else
522 #LINK_INTO = LIBJVM
523 endif
525 MCS = /usr/ccs/bin/mcs
526 STRIP = /usr/ccs/bin/strip
528 # Solaris platforms collect lots of redundant file-ident lines,
529 # to the point of wasting a significant percentage of file space.
530 # (The text is stored in ELF .comment sections, contributed by
531 # all "#pragma ident" directives in header and source files.)
532 # This command "compresses" the .comment sections simply by
533 # removing repeated lines. The data can be extracted from
534 # binaries in the field by using "mcs -p libjvm.so" or the older
535 # command "what libjvm.so".
536 LINK_LIB.CC/POST_HOOK += $(MCS) -c $@ || exit 1;
537 # (The exit 1 is necessary to cause a build failure if the command fails and
538 # multiple commands are strung together, and the final semicolon is necessary
539 # since the hook must terminate itself as a valid command.)
541 # Also, strip debug and line number information (worth about 1.7Mb).
542 STRIP_LIB.CC/POST_HOOK = $(STRIP) -x $@ || exit 1;
543 # STRIP_LIB.CC/POST_HOOK is incorporated into LINK_LIB.CC/POST_HOOK
544 # in certain configurations, such as product.make. Other configurations,
545 # such as debug.make, do not include the strip operation.