1#!/bin/ksh 2# 3# This file and its contents are supplied under the terms of the 4# Common Development and Distribution License ("CDDL"), version 1.0. 5# You may only use this file in accordance with the terms of version 6# 1.0 of the CDDL. 7# 8# A full copy of the text of the CDDL should have accompanied this 9# source. A copy of the CDDL is also available via the Internet at 10# http://www.illumos.org/license/CDDL. 11# 12 13# Copyright 2026 Oxide Computer Company 14 15# 16# Verify that per-function .gcc_except_table.<sym> input sections are 17# merged into a single .gcc_except_table output section, matching the 18# behaviour of GNU ld. 19# 20 21TESTDIR=$(dirname $0) 22 23tmpdir=/tmp/test.$$ 24mkdir $tmpdir 25cd $tmpdir 26 27function cleanup { 28 cd / 29 rm -fr $tmpdir 30} 31 32trap cleanup EXIT 33 34 35if [[ $PWD != $tmpdir ]]; then 36 print -u2 "Failed to create temporary directory: $tmpdir" 37 exit 1 38fi 39 40function assemble { 41 gcc -c -o $2 $1 42 if (( $? != 0 )); then 43 print -u2 "assembly of ${1} failed" 44 exit 1 45 fi 46} 47 48assemble ${TESTDIR}/gcct1.s gcct1.o 49assemble ${TESTDIR}/gcct2.s gcct2.o 50 51gcc -shared -o gcct.so gcct1.o gcct2.o 52if (( $? != 0 )); then 53 print -u2 "link of gcct[12].o failed" 54 exit 1 55fi 56 57# 58# There must be exactly one section named .gcc_except_table, and no 59# .gcc_except_table.<sym> sections from the per-function inputs. 60# 61nmerged=$(elfdump -c gcct.so | awk ' 62 $3 == "sh_name:" && $4 == ".gcc_except_table" { n++ } 63 END { print n + 0 } 64 ') 65if (( nmerged != 1 )); then 66 print -u2 "FAIL: expected 1 .gcc_except_table section, found ${nmerged}" 67 elfdump -c gcct.so | grep gcc_except >&2 68 exit 1 69fi 70 71nsplit=$(elfdump -c gcct.so | awk ' 72 $3 == "sh_name:" && $4 ~ /^\.gcc_except_table\./ { n++ } 73 END { print n + 0 } 74 ') 75if (( nsplit != 0 )); then 76 print -u2 "FAIL: .gcc_except_table.* sections were not merged" 77 elfdump -c gcct.so | grep gcc_except >&2 78 exit 1 79fi 80 81# 82# Verify the merged section contains the bytes contributed by both inputs. 83# 84hex=$(elfdump -N.gcc_except_table -w /dev/stdout gcct.so | 85 od -An -tx1 | tr -d ' \n') 86case "$hex" in 87*11223344*) ;; 88*) 89 print -u2 "FAIL: merged .gcc_except_table content unexpected: ${hex}" 90 exit 1 91 ;; 92esac 93 94exit 0 95