# # 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) $<