jason
jason

Reputation: 61

How to fix "dangerous relocation: unsupported relocation"

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)

Upvotes: 6

Views: 12960

Answers (1)

Iskren Ivov Chernev
Iskren Ivov Chernev

Reputation: 311

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.

Upvotes: 4

Related Questions