Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "dangerous relocation: unsupported relocation"

Tags:

c

linux

gcc

I'm compiling linux-4.19(gcc-8.2 bintutils-2.31), however it always fails with errors like:

aarch64-oe-linux-ld.bfd: drivers/platform/gsi/gsi.o: relocation R_AARCH64_ABS32 against `__crc_gsi_write_channel_scratch' can not be used when making a shared object
aarch64-oe-linux-ld.bfd: drivers/platform/gsi/gsi.o:/usr/src/kernel/drivers/platform/gsi/gsi.c:4383:(.data+0x0): dangerous relocation: unsupported relocation
aarch64-oe-linux-ld.bfd: drivers/platform/gsi/gsi.o:(.data+0x28): dangerous relocation: unsupported relocation
aarch64-oe-linux-ld.bfd: drivers/platform/gsi/gsi.o:(.data+0x50): dangerous relocation: unsupported relocation
aarch64-oe-linux-ld.bfd: drivers/platform/gsi/gsi.o:(__verbose+0x0): dangerous relocation: unsupported relocation
aarch64-oe-linux-ld.bfd: drivers/platform/gsi/gsi.o:(__verbose+0x8): dangerous relocation: unsupported relocation

I've tried below solutions, but these didn't work.

  1. Add -fPIC flag to the driver
  2. Use gcc-7.3 (binutils-2.31)
  3. Use binutils-2.33 (gcc-8.2)
like image 857
jason Avatar asked Nov 07 '22 12:11

jason


1 Answers

The problem is not the relocation, it is the following warning (should appear before the error)

WARNING: EXPORT symbol "gsi_write_channel_scratch" [vmlinux] version generation failed, symbol will not be versioned.

If you read more about genksyms here you'll understand that it complains because it can't parse something before the place it complains about. In this particular case the issue is a __packed return type (which it doesn't understand). __packed is only useful when declaring structs and unions. I guess it makes sense for function arguments to serve as documentation, but it's not necessary.

So just drop __packed from the previous function __gsi_update_mhi_channel_scratch return type and you're set.

like image 192
Iskren Ivov Chernev Avatar answered Nov 14 '22 10:11

Iskren Ivov Chernev