xref: /linux/tools/objtool/tests/generic/test-data-alignment.sh (revision 8abe5c94bfeb9bb5cf02fa17a9337d2d7bbade75)
1*8abe5c94SSong Liu#!/bin/bash
2*8abe5c94SSong Liu# SPDX-License-Identifier: GPL-2.0
3*8abe5c94SSong Liu#
4*8abe5c94SSong Liu# A cloned data section keeps its alignment.
5*8abe5c94SSong Liu#
6*8abe5c94SSong Liu# Plenty of kernel data is aligned for correctness rather than speed: per-CPU
7*8abe5c94SSong Liu# variables, anything touched by an aligned vector move, structures padded to
8*8abe5c94SSong Liu# own a cacheline. A clone that lands under-aligned either faults on first use
9*8abe5c94SSong Liu# or silently shares a line it was laid out to avoid, and neither shows up
10*8abe5c94SSong Liu# until the patch is loaded on hardware that cares.
11*8abe5c94SSong Liu#
12*8abe5c94SSong Liu# Fixed by 2f2600decb30 ("objtool/klp: Fix alignment of cloned data
13*8abe5c94SSong Liu# sections").
14*8abe5c94SSong Liu#
15*8abe5c94SSong Liu# Covers the same ground as corpus/x86_64/cloned-data-alignment in Joe
16*8abe5c94SSong Liu# Lawrence's klp-build unit test corpus.
17*8abe5c94SSong Liu
18*8abe5c94SSong Liu. "$(dirname "$0")/../lib.sh"
19*8abe5c94SSong Liu
20*8abe5c94SSong Liusetup
21*8abe5c94SSong Liubuild_pair data_alignment.c
22*8abe5c94SSong Liu
23*8abe5c94SSong Liu# The premise: the compiler really did over-align it, and the object is new in
24*8abe5c94SSong Liu# the patch so it has to be cloned rather than referenced.
25*8abe5c94SSong Liuwant="$(in_sections patched.o | sed 's/^ *\[[ 0-9]*\] *//' |
26*8abe5c94SSong Liu	awk '$1 == ".data.aligned_data" { print $NF }')"
27*8abe5c94SSong Liu[ "$want" = 64 ] ||
28*8abe5c94SSong Liu	probe_skip "compiler gave .data.aligned_data alignment '$want', not 64"
29*8abe5c94SSong Liuhas_input_section orig.o .data.aligned_data &&
30*8abe5c94SSong Liu	fail "fixture put aligned_data in the original; nothing to clone"
31*8abe5c94SSong Liu
32*8abe5c94SSong Liurun_diff
33*8abe5c94SSong Liuassert_section .data.aligned_data
34*8abe5c94SSong Liu
35*8abe5c94SSong Liugot="$(out_sections | sed 's/^ *\[[ 0-9]*\] *//' |
36*8abe5c94SSong Liu       awk '$1 == ".data.aligned_data" { print $NF }')"
37*8abe5c94SSong Liu[ "$got" = "$want" ] ||
38*8abe5c94SSong Liu	fail "cloned .data.aligned_data has alignment $got, expected $want"
39*8abe5c94SSong Liu
40*8abe5c94SSong Liupass "cloned data section keeps its alignment"
41