|
root / base / usr / src / cmd / sgs / rtld / amd64 / Makefile
Makefile Makefile 150 lines 5.0 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
#

BASEPLAT =	amd64

# Object lists are organized into primary (most frequently used code) and
# secondary lists (less frequently used code).

P_COMOBJS=	debugdata.o \
		analyze.o	elf.o		external.o	globals.o \
		malloc.o	paths.o		setup.o		util.o \
		dlfcns.o	config_elf.o	locale.o	tsort.o \
		remove.o	move.o		tls.o		cap.o

S_COMOBJS=	debug.o		audit.o		object.o

G_MACHOBJS=	doreloc.o

P_MACHOBJS=	amd64_elf.o	_setup.o	dlamd64getunwind.o

CP_MACHOBJS=

S_MACHOBJS=

P_ASOBJS=	boot.o		boot_elf.o	caller.o

S_ASOBJS=

CRTSRCS=	../../../../lib/crt/amd64
CRTI=		pics/crti.o
CRTN=		pics/crtn.o
CRTS=		$(CRTI)		$(CRTN)

include		$(SRC)/cmd/sgs/rtld/Makefile.com
include		$(SRC)/lib/Makefile.lib.64

MAPFILE-ORDER =	../common/mapfile-order-gcc

# Add any machine specific flags.

ASFLAGS +=	-D__amd64 -D_ELF64 $(amd64_ASFLAGS)
ADBGENFLAGS +=	-mlp64
ADBSUB=		$(ADBSUB64)
CPPFLAGS +=	-D_ELF64
# Hammerhead: 64-bit only - runtime linker at flattened path
SONAME=		/lib/ld.so.1

SGSMSGTARG +=	$(SGSMSGINTEL) $(SGSMSGINTEL64) $(SGSMSG64)

LDLIB =		-L ../../libld/$(MACH64)
RTLDLIB =	-L ../../librtld/$(MACH64)

CPICLIB =	$(CPICLIB64)
LDDBGLIBDIR =	$(LDDBGLIBDIR64)
CONVLIBDIR =	$(CONVLIBDIR64)

.KEEP_STATE:

all:		$(RTLD)

install:	all $(ROOTDYNLIB64) $(ROOTCOMPATLINKS) $(ROOTCOMPATLINKS64)

adbmacros:	adb .WAIT $(ADBSCRIPTS)

adbinstall:	adbmacros .WAIT $(ROOTADB64)

include		$(SRC)/cmd/sgs/rtld/Makefile.targ
include		$(SRC)/Makefile.master.64

# Hammerhead: ld.so.1 MUST be linked by illumos ld (sunld), not GNU ld.
# GNU ld produces ELFOSABI_NONE, missing PT_SUNWDTRACE/PT_SUNW_UNWIND program
# headers, and wrong segment alignment — the kernel cannot properly map the
# result. Override LD after Makefile.master.64 (which resets LD=$(LD64)).
#
# `unexport LD_ALTEXEC` does NOT reliably prevent sunld from seeing the
# variable in recipe subshells (gmake may still pass it through).  When
# LD_ALTEXEC is set to gnu-ld-wrapper, sunld re-execs that wrapper,
# which silently ignores `-z dtrace=dtrace_data` — the resulting
# ld.so.1 has PT_SUNWDTRACE with p_memsz=0, and the kernel's
# dtrace_safe_phdr() rejects it with silent ENOEXEC when exec'ing any
# binary that uses ld.so.1 as its interpreter (including /sbin/init).
#
# Use the same wrapper script kernel linking uses: a single-token path
# that unsets LD_ALTEXEC before exec'ing /usr/bin/sunld.  See
# `usr/src/tools/scripts/sunld-kernel.sh`.
unexport LD_ALTEXEC
LD = $(SRC)/tools/scripts/sunld-kernel.sh
GSHARED = -G

# Redefine DYNFLAGS in illumos ld native syntax (no -Wl, prefix).
# The Makefile.targ link rule calls $(LD) directly, not $(CC).
# Note: illumos ld requires space between -z and the keyword.
DYNFLAGS = -h $(SONAME) -z textoff -z defs \
	$(MAPFILES:%=-M %) $(MAPFILE.PGA:%=-M %) \
	-i -e _rt_boot $(VERSREF) $(ZNODLOPEN) \
	$(ZINTERPOSE) -z dtrace=dtrace_data '-R$$ORIGIN' \
	-Bsymbolic
ZNODLOPEN = -z nodlopen
ZINTERPOSE = -z interpose

# Hammerhead: GNU strip corrupts ld.so.1 in two places.
#
# 1. POST_PROCESS_SO runs STRIP_STABS ($(STRIP) -x $@) after the link
#    rule in Makefile.targ.  On Hammerhead $(STRIP) is GNU strip.
# 2. INS.file in Makefile.master passes `-s` to install(1), which
#    invokes GNU strip again at install time.
#
# GNU strip handles the Solaris PT_SUNWDTRACE program header
# incorrectly:
#
#   - sunld with `-z dtrace=dtrace_data` creates a PT_SUNWDTRACE
#     program header with p_filesz=0 (NOBITS — dtrace_data is in
#     .bss), p_memsz=0x40 (= FASTTRAP_SUNWDTRACE_SIZE), p_vaddr set to
#     the symbol address.
#   - GNU strip sees p_filesz=0 and 'optimizes' by zeroing p_memsz as
#     well, and drops the `dtrace_data` symbol entirely.
#   - The kernel's dtrace_safe_phdr() at elf.c:123 rejects any
#     interpreter whose PT_SUNWDTRACE p_memsz < PT_SUNWDTRACE_SIZE (64).
#   - Result: every exec() of a dynamic binary that uses ld.so.1 as
#     its interpreter fails with ENOEXEC (including /sbin/init).
#
# Disable both strip calls.  The rest of POST_PROCESS_SO (mcs -d,
# elfsign) still runs.  ld.so.1 ends up larger (~1.4 MB unstripped vs
# ~474 KB stripped) but exec works.
STRIP_STABS = :
INS.file = $(RM) $@; $(INS) -m $(FILEMODE) -f $(@D) $<