Skip to content

Commit 9244696

Browse files
committed
Merge tag 'kbuild-fixes-v6.13-3' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild
Pull Kbuild fixes from Masahiro Yamada: - Fix escaping of '$' in scripts/mksysmap - Fix a modpost crash observed with the latest binutils - Fix 'provides' in the linux-api-headers pacman package * tag 'kbuild-fixes-v6.13-3' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: kbuild: pacman-pkg: provide versioned linux-api-headers package modpost: work around unaligned data access error modpost: refactor do_vmbus_entry() modpost: fix the missed iteration for the max bit in do_input() scripts/mksysmap: Fix escape chars '$'
2 parents 5635d8b + 3854430 commit 9244696

File tree

5 files changed

+46
-34
lines changed

5 files changed

+46
-34
lines changed

scripts/mksysmap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# (do not forget a space before each pattern)
2727

2828
# local symbols for ARM, MIPS, etc.
29-
/ \\$/d
29+
/ \$/d
3030

3131
# local labels, .LBB, .Ltmpxxx, .L__unnamed_xx, .LASANPC, etc.
3232
/ \.L/d
@@ -39,7 +39,7 @@
3939
/ __pi_\.L/d
4040

4141
# arm64 local symbols in non-VHE KVM namespace
42-
/ __kvm_nvhe_\\$/d
42+
/ __kvm_nvhe_\$/d
4343
/ __kvm_nvhe_\.L/d
4444

4545
# lld arm/aarch64/mips thunks

scripts/mod/file2alias.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ struct devtable {
132132
* based at address m.
133133
*/
134134
#define DEF_FIELD(m, devid, f) \
135-
typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f))
135+
typeof(((struct devid *)0)->f) f = \
136+
get_unaligned_native((typeof(f) *)((m) + OFF_##devid##_##f))
136137

137138
/* Define a variable f that holds the address of field f of struct devid
138139
* based at address m. Due to the way typeof works, for a field of type
@@ -600,7 +601,7 @@ static void do_pnp_card_entry(struct module *mod, void *symval)
600601
static void do_pcmcia_entry(struct module *mod, void *symval)
601602
{
602603
char alias[256] = {};
603-
unsigned int i;
604+
604605
DEF_FIELD(symval, pcmcia_device_id, match_flags);
605606
DEF_FIELD(symval, pcmcia_device_id, manf_id);
606607
DEF_FIELD(symval, pcmcia_device_id, card_id);
@@ -609,10 +610,6 @@ static void do_pcmcia_entry(struct module *mod, void *symval)
609610
DEF_FIELD(symval, pcmcia_device_id, device_no);
610611
DEF_FIELD_ADDR(symval, pcmcia_device_id, prod_id_hash);
611612

612-
for (i=0; i<4; i++) {
613-
(*prod_id_hash)[i] = TO_NATIVE((*prod_id_hash)[i]);
614-
}
615-
616613
ADD(alias, "m", match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID,
617614
manf_id);
618615
ADD(alias, "c", match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID,
@@ -623,10 +620,14 @@ static void do_pcmcia_entry(struct module *mod, void *symval)
623620
function);
624621
ADD(alias, "pfn", match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO,
625622
device_no);
626-
ADD(alias, "pa", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1, (*prod_id_hash)[0]);
627-
ADD(alias, "pb", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2, (*prod_id_hash)[1]);
628-
ADD(alias, "pc", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3, (*prod_id_hash)[2]);
629-
ADD(alias, "pd", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4, (*prod_id_hash)[3]);
623+
ADD(alias, "pa", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1,
624+
get_unaligned_native(*prod_id_hash + 0));
625+
ADD(alias, "pb", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2,
626+
get_unaligned_native(*prod_id_hash + 1));
627+
ADD(alias, "pc", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3,
628+
get_unaligned_native(*prod_id_hash + 2));
629+
ADD(alias, "pd", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4,
630+
get_unaligned_native(*prod_id_hash + 3));
630631

631632
module_alias_printf(mod, true, "pcmcia:%s", alias);
632633
}
@@ -654,10 +655,9 @@ static void do_input(char *alias,
654655
{
655656
unsigned int i;
656657

657-
for (i = min / BITS_PER_LONG; i < max / BITS_PER_LONG + 1; i++)
658-
arr[i] = TO_NATIVE(arr[i]);
659-
for (i = min; i < max; i++)
660-
if (arr[i / BITS_PER_LONG] & (1ULL << (i%BITS_PER_LONG)))
658+
for (i = min; i <= max; i++)
659+
if (get_unaligned_native(arr + i / BITS_PER_LONG) &
660+
(1ULL << (i % BITS_PER_LONG)))
661661
sprintf(alias + strlen(alias), "%X,*", i);
662662
}
663663

@@ -812,15 +812,13 @@ static void do_virtio_entry(struct module *mod, void *symval)
812812
* Each byte of the guid will be represented by two hex characters
813813
* in the name.
814814
*/
815-
816815
static void do_vmbus_entry(struct module *mod, void *symval)
817816
{
818-
int i;
819817
DEF_FIELD_ADDR(symval, hv_vmbus_device_id, guid);
820-
char guid_name[(sizeof(*guid) + 1) * 2];
818+
char guid_name[sizeof(*guid) * 2 + 1];
821819

822-
for (i = 0; i < (sizeof(*guid) * 2); i += 2)
823-
sprintf(&guid_name[i], "%02x", TO_NATIVE((guid->b)[i/2]));
820+
for (int i = 0; i < sizeof(*guid); i++)
821+
sprintf(&guid_name[i * 2], "%02x", guid->b[i]);
824822

825823
module_alias_printf(mod, false, "vmbus:%s", guid_name);
826824
}

scripts/mod/modpost.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,9 +1138,9 @@ static Elf_Addr addend_386_rel(uint32_t *location, unsigned int r_type)
11381138
{
11391139
switch (r_type) {
11401140
case R_386_32:
1141-
return TO_NATIVE(*location);
1141+
return get_unaligned_native(location);
11421142
case R_386_PC32:
1143-
return TO_NATIVE(*location) + 4;
1143+
return get_unaligned_native(location) + 4;
11441144
}
11451145

11461146
return (Elf_Addr)(-1);
@@ -1161,24 +1161,24 @@ static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, unsigned int r_type)
11611161
switch (r_type) {
11621162
case R_ARM_ABS32:
11631163
case R_ARM_REL32:
1164-
inst = TO_NATIVE(*(uint32_t *)loc);
1164+
inst = get_unaligned_native((uint32_t *)loc);
11651165
return inst + sym->st_value;
11661166
case R_ARM_MOVW_ABS_NC:
11671167
case R_ARM_MOVT_ABS:
1168-
inst = TO_NATIVE(*(uint32_t *)loc);
1168+
inst = get_unaligned_native((uint32_t *)loc);
11691169
offset = sign_extend32(((inst & 0xf0000) >> 4) | (inst & 0xfff),
11701170
15);
11711171
return offset + sym->st_value;
11721172
case R_ARM_PC24:
11731173
case R_ARM_CALL:
11741174
case R_ARM_JUMP24:
1175-
inst = TO_NATIVE(*(uint32_t *)loc);
1175+
inst = get_unaligned_native((uint32_t *)loc);
11761176
offset = sign_extend32((inst & 0x00ffffff) << 2, 25);
11771177
return offset + sym->st_value + 8;
11781178
case R_ARM_THM_MOVW_ABS_NC:
11791179
case R_ARM_THM_MOVT_ABS:
1180-
upper = TO_NATIVE(*(uint16_t *)loc);
1181-
lower = TO_NATIVE(*((uint16_t *)loc + 1));
1180+
upper = get_unaligned_native((uint16_t *)loc);
1181+
lower = get_unaligned_native((uint16_t *)loc + 1);
11821182
offset = sign_extend32(((upper & 0x000f) << 12) |
11831183
((upper & 0x0400) << 1) |
11841184
((lower & 0x7000) >> 4) |
@@ -1195,8 +1195,8 @@ static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, unsigned int r_type)
11951195
* imm11 = lower[10:0]
11961196
* imm32 = SignExtend(S:J2:J1:imm6:imm11:'0')
11971197
*/
1198-
upper = TO_NATIVE(*(uint16_t *)loc);
1199-
lower = TO_NATIVE(*((uint16_t *)loc + 1));
1198+
upper = get_unaligned_native((uint16_t *)loc);
1199+
lower = get_unaligned_native((uint16_t *)loc + 1);
12001200

12011201
sign = (upper >> 10) & 1;
12021202
j1 = (lower >> 13) & 1;
@@ -1219,8 +1219,8 @@ static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, unsigned int r_type)
12191219
* I2 = NOT(J2 XOR S)
12201220
* imm32 = SignExtend(S:I1:I2:imm10:imm11:'0')
12211221
*/
1222-
upper = TO_NATIVE(*(uint16_t *)loc);
1223-
lower = TO_NATIVE(*((uint16_t *)loc + 1));
1222+
upper = get_unaligned_native((uint16_t *)loc);
1223+
lower = get_unaligned_native((uint16_t *)loc + 1);
12241224

12251225
sign = (upper >> 10) & 1;
12261226
j1 = (lower >> 13) & 1;
@@ -1241,7 +1241,7 @@ static Elf_Addr addend_mips_rel(uint32_t *location, unsigned int r_type)
12411241
{
12421242
uint32_t inst;
12431243

1244-
inst = TO_NATIVE(*location);
1244+
inst = get_unaligned_native(location);
12451245
switch (r_type) {
12461246
case R_MIPS_LO16:
12471247
return inst & 0xffff;

scripts/mod/modpost.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@
6565
#define TO_NATIVE(x) \
6666
(target_is_big_endian == host_is_big_endian ? x : bswap(x))
6767

68+
#define __get_unaligned_t(type, ptr) ({ \
69+
const struct { type x; } __attribute__((__packed__)) *__pptr = \
70+
(typeof(__pptr))(ptr); \
71+
__pptr->x; \
72+
})
73+
74+
#define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
75+
76+
#define get_unaligned_native(ptr) \
77+
({ \
78+
typeof(*(ptr)) _val = get_unaligned(ptr); \
79+
TO_NATIVE(_val); \
80+
})
81+
6882
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
6983

7084
#define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)

scripts/package/PKGBUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ _package-headers() {
103103

104104
_package-api-headers() {
105105
pkgdesc="Kernel headers sanitized for use in userspace"
106-
provides=(linux-api-headers)
106+
provides=(linux-api-headers="${pkgver}")
107107
conflicts=(linux-api-headers)
108108

109109
_prologue

0 commit comments

Comments
 (0)