[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <202410161313.tSgr3bAj-lkp@intel.com>
Date: Wed, 16 Oct 2024 14:19:06 +0800
From: kernel test robot <lkp@...el.com>
To: Tianjia Zhang <tianjia.zhang@...ux.alibaba.com>,
Marc Zyngier <maz@...nel.org>,
Oliver Upton <oliver.upton@...ux.dev>,
Joey Gouly <joey.gouly@....com>,
Suzuki K Poulose <suzuki.poulose@....com>,
Zenghui Yu <yuzenghui@...wei.com>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Bill Wendling <morbo@...gle.com>,
Justin Stitt <justinstitt@...gle.com>,
Pierre-Clément Tosi <ptosi@...gle.com>,
linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.linux.dev,
linux-kernel@...r.kernel.org, llvm@...ts.linux.dev
Cc: oe-kbuild-all@...ts.linux.dev,
Tianjia Zhang <tianjia.zhang@...ux.alibaba.com>
Subject: Re: [PATCH] KVM: arm64: nVHE: gen-hyprel: Silent build warnings
Hi Tianjia,
kernel test robot noticed the following build warnings:
[auto build test WARNING on kvmarm/next]
[also build test WARNING on linus/master v6.12-rc3 next-20241015]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Tianjia-Zhang/KVM-arm64-nVHE-gen-hyprel-Silent-build-warnings/20241009-170027
base: https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next
patch link: https://lore.kernel.org/r/20241009085751.35976-1-tianjia.zhang%40linux.alibaba.com
patch subject: [PATCH] KVM: arm64: nVHE: gen-hyprel: Silent build warnings
config: arm64-defconfig (https://download.01.org/0day-ci/archive/20241016/202410161313.tSgr3bAj-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241016/202410161313.tSgr3bAj-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@...el.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410161313.tSgr3bAj-lkp@intel.com/
All warnings (new ones prefixed by >>):
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c: In function 'section_by_off':
>> arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:166:33: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 4 has type 'Elf64_Off' {aka 'long unsigned int'} [-Wformat=]
166 | fprintf(stderr, "error: %s: " fmt "\n", \
| ^~~~~~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:186:25: note: in expansion of macro 'fatal_error'
186 | fatal_error("assertion " #lhs " " #op " " #rhs \
| ^~~~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:193:41: note: in expansion of macro 'assert_op'
193 | #define assert_ne(lhs, rhs, fmt) assert_op(lhs, rhs, fmt, !=)
| ^~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:233:9: note: in expansion of macro 'assert_ne'
233 | assert_ne(off, 0ULL, "%llu");
| ^~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c: In function 'init_elf':
>> arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:166:33: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 4 has type '__off_t' {aka 'long int'} [-Wformat=]
166 | fprintf(stderr, "error: %s: " fmt "\n", \
| ^~~~~~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:186:25: note: in expansion of macro 'fatal_error'
186 | fatal_error("assertion " #lhs " " #op " " #rhs \
| ^~~~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:195:41: note: in expansion of macro 'assert_op'
195 | #define assert_ge(lhs, rhs, fmt) assert_op(lhs, rhs, fmt, >=)
| ^~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:279:9: note: in expansion of macro 'assert_ge'
279 | assert_ge(stat.st_size, (off_t)sizeof(*elf.ehdr), "%llu");
| ^~~~~~~~~
>> arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:166:33: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 5 has type 'long int' [-Wformat=]
166 | fprintf(stderr, "error: %s: " fmt "\n", \
| ^~~~~~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:186:25: note: in expansion of macro 'fatal_error'
186 | fatal_error("assertion " #lhs " " #op " " #rhs \
| ^~~~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:195:41: note: in expansion of macro 'assert_op'
195 | #define assert_ge(lhs, rhs, fmt) assert_op(lhs, rhs, fmt, >=)
| ^~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:279:9: note: in expansion of macro 'assert_ge'
279 | assert_ge(stat.st_size, (off_t)sizeof(*elf.ehdr), "%llu");
| ^~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c: In function 'emit_rela_abs64':
>> arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:343:59: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 5 has type '__uint64_t' {aka 'long unsigned int'} [-Wformat=]
343 | printf(".reloc %lu, R_AARCH64_PREL32, %s%s + 0x%llx\n",
| ~~~^
| |
| long long unsigned int
| %lx
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c: In function 'emit_rela_section':
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:166:33: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 4 has type '__uint64_t' {aka 'long unsigned int'} [-Wformat=]
166 | fprintf(stderr, "error: %s: " fmt "\n", \
| ^~~~~~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:186:25: note: in expansion of macro 'fatal_error'
186 | fatal_error("assertion " #lhs " " #op " " #rhs \
| ^~~~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:194:41: note: in expansion of macro 'assert_op'
194 | #define assert_lt(lhs, rhs, fmt) assert_op(lhs, rhs, fmt, <)
| ^~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:379:17: note: in expansion of macro 'assert_lt'
379 | assert_lt(elf64toh(rela->r_offset), elf64toh(sh_orig->sh_size), "0x%llx");
| ^~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:166:33: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 5 has type '__uint64_t' {aka 'long unsigned int'} [-Wformat=]
166 | fprintf(stderr, "error: %s: " fmt "\n", \
| ^~~~~~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:186:25: note: in expansion of macro 'fatal_error'
186 | fatal_error("assertion " #lhs " " #op " " #rhs \
| ^~~~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:194:41: note: in expansion of macro 'assert_op'
194 | #define assert_lt(lhs, rhs, fmt) assert_op(lhs, rhs, fmt, <)
| ^~~~~~~~~
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c:379:17: note: in expansion of macro 'assert_lt'
379 | assert_lt(elf64toh(rela->r_offset), elf64toh(sh_orig->sh_size), "0x%llx");
| ^~~~~~~~~
vim +166 arch/arm64/kvm/hyp/nvhe/gen-hyprel.c
bc93763f178fd0 Marc Zyngier 2021-01-30 163
8c49b5d43d4c45 David Brazdil 2021-01-05 164 #define fatal_error(fmt, ...) \
8c49b5d43d4c45 David Brazdil 2021-01-05 165 ({ \
8c49b5d43d4c45 David Brazdil 2021-01-05 @166 fprintf(stderr, "error: %s: " fmt "\n", \
8c49b5d43d4c45 David Brazdil 2021-01-05 167 elf.path, ## __VA_ARGS__); \
8c49b5d43d4c45 David Brazdil 2021-01-05 168 exit(EXIT_FAILURE); \
8c49b5d43d4c45 David Brazdil 2021-01-05 169 __builtin_unreachable(); \
8c49b5d43d4c45 David Brazdil 2021-01-05 170 })
8c49b5d43d4c45 David Brazdil 2021-01-05 171
8c49b5d43d4c45 David Brazdil 2021-01-05 172 #define fatal_perror(msg) \
8c49b5d43d4c45 David Brazdil 2021-01-05 173 ({ \
8c49b5d43d4c45 David Brazdil 2021-01-05 174 fprintf(stderr, "error: %s: " msg ": %s\n", \
8c49b5d43d4c45 David Brazdil 2021-01-05 175 elf.path, strerror(errno)); \
8c49b5d43d4c45 David Brazdil 2021-01-05 176 exit(EXIT_FAILURE); \
8c49b5d43d4c45 David Brazdil 2021-01-05 177 __builtin_unreachable(); \
8c49b5d43d4c45 David Brazdil 2021-01-05 178 })
8c49b5d43d4c45 David Brazdil 2021-01-05 179
8c49b5d43d4c45 David Brazdil 2021-01-05 180 #define assert_op(lhs, rhs, fmt, op) \
8c49b5d43d4c45 David Brazdil 2021-01-05 181 ({ \
8c49b5d43d4c45 David Brazdil 2021-01-05 182 typeof(lhs) _lhs = (lhs); \
8c49b5d43d4c45 David Brazdil 2021-01-05 183 typeof(rhs) _rhs = (rhs); \
8c49b5d43d4c45 David Brazdil 2021-01-05 184 \
8c49b5d43d4c45 David Brazdil 2021-01-05 185 if (!(_lhs op _rhs)) { \
8c49b5d43d4c45 David Brazdil 2021-01-05 @186 fatal_error("assertion " #lhs " " #op " " #rhs \
8c49b5d43d4c45 David Brazdil 2021-01-05 187 " failed (lhs=" fmt ", rhs=" fmt \
8c49b5d43d4c45 David Brazdil 2021-01-05 188 ", line=%d)", _lhs, _rhs, __LINE__); \
8c49b5d43d4c45 David Brazdil 2021-01-05 189 } \
8c49b5d43d4c45 David Brazdil 2021-01-05 190 })
8c49b5d43d4c45 David Brazdil 2021-01-05 191
8c49b5d43d4c45 David Brazdil 2021-01-05 192 #define assert_eq(lhs, rhs, fmt) assert_op(lhs, rhs, fmt, ==)
8c49b5d43d4c45 David Brazdil 2021-01-05 @193 #define assert_ne(lhs, rhs, fmt) assert_op(lhs, rhs, fmt, !=)
8c49b5d43d4c45 David Brazdil 2021-01-05 194 #define assert_lt(lhs, rhs, fmt) assert_op(lhs, rhs, fmt, <)
8c49b5d43d4c45 David Brazdil 2021-01-05 @195 #define assert_ge(lhs, rhs, fmt) assert_op(lhs, rhs, fmt, >=)
8c49b5d43d4c45 David Brazdil 2021-01-05 196
8c49b5d43d4c45 David Brazdil 2021-01-05 197 /*
8c49b5d43d4c45 David Brazdil 2021-01-05 198 * Return a pointer of a given type at a given offset from
8c49b5d43d4c45 David Brazdil 2021-01-05 199 * the beginning of the ELF file.
8c49b5d43d4c45 David Brazdil 2021-01-05 200 */
8c49b5d43d4c45 David Brazdil 2021-01-05 201 #define elf_ptr(type, off) ((type *)(elf.begin + (off)))
8c49b5d43d4c45 David Brazdil 2021-01-05 202
8c49b5d43d4c45 David Brazdil 2021-01-05 203 /* Iterate over all sections in the ELF. */
8c49b5d43d4c45 David Brazdil 2021-01-05 204 #define for_each_section(var) \
bc93763f178fd0 Marc Zyngier 2021-01-30 205 for (var = elf.sh_table; var < elf.sh_table + elf16toh(elf.ehdr->e_shnum); ++var)
8c49b5d43d4c45 David Brazdil 2021-01-05 206
8c49b5d43d4c45 David Brazdil 2021-01-05 207 /* Iterate over all Elf64_Rela relocations in a given section. */
8c49b5d43d4c45 David Brazdil 2021-01-05 208 #define for_each_rela(shdr, var) \
bc93763f178fd0 Marc Zyngier 2021-01-30 209 for (var = elf_ptr(Elf64_Rela, elf64toh(shdr->sh_offset)); \
bc93763f178fd0 Marc Zyngier 2021-01-30 210 var < elf_ptr(Elf64_Rela, elf64toh(shdr->sh_offset) + elf64toh(shdr->sh_size)); var++)
8c49b5d43d4c45 David Brazdil 2021-01-05 211
8c49b5d43d4c45 David Brazdil 2021-01-05 212 /* True if a string starts with a given prefix. */
8c49b5d43d4c45 David Brazdil 2021-01-05 213 static inline bool starts_with(const char *str, const char *prefix)
8c49b5d43d4c45 David Brazdil 2021-01-05 214 {
8c49b5d43d4c45 David Brazdil 2021-01-05 215 return memcmp(str, prefix, strlen(prefix)) == 0;
8c49b5d43d4c45 David Brazdil 2021-01-05 216 }
8c49b5d43d4c45 David Brazdil 2021-01-05 217
8c49b5d43d4c45 David Brazdil 2021-01-05 218 /* Returns a string containing the name of a given section. */
8c49b5d43d4c45 David Brazdil 2021-01-05 219 static inline const char *section_name(Elf64_Shdr *shdr)
8c49b5d43d4c45 David Brazdil 2021-01-05 220 {
bc93763f178fd0 Marc Zyngier 2021-01-30 221 return elf.sh_string + elf32toh(shdr->sh_name);
8c49b5d43d4c45 David Brazdil 2021-01-05 222 }
8c49b5d43d4c45 David Brazdil 2021-01-05 223
8c49b5d43d4c45 David Brazdil 2021-01-05 224 /* Returns a pointer to the first byte of section data. */
8c49b5d43d4c45 David Brazdil 2021-01-05 225 static inline const char *section_begin(Elf64_Shdr *shdr)
8c49b5d43d4c45 David Brazdil 2021-01-05 226 {
bc93763f178fd0 Marc Zyngier 2021-01-30 227 return elf_ptr(char, elf64toh(shdr->sh_offset));
8c49b5d43d4c45 David Brazdil 2021-01-05 228 }
8c49b5d43d4c45 David Brazdil 2021-01-05 229
8c49b5d43d4c45 David Brazdil 2021-01-05 230 /* Find a section by its offset from the beginning of the file. */
8c49b5d43d4c45 David Brazdil 2021-01-05 231 static inline Elf64_Shdr *section_by_off(Elf64_Off off)
8c49b5d43d4c45 David Brazdil 2021-01-05 232 {
83de54b4bb92bc Tianjia Zhang 2024-10-09 233 assert_ne(off, 0ULL, "%llu");
8c49b5d43d4c45 David Brazdil 2021-01-05 234 return elf_ptr(Elf64_Shdr, off);
8c49b5d43d4c45 David Brazdil 2021-01-05 235 }
8c49b5d43d4c45 David Brazdil 2021-01-05 236
8c49b5d43d4c45 David Brazdil 2021-01-05 237 /* Find a section by its index. */
8c49b5d43d4c45 David Brazdil 2021-01-05 238 static inline Elf64_Shdr *section_by_idx(uint16_t idx)
8c49b5d43d4c45 David Brazdil 2021-01-05 239 {
8c49b5d43d4c45 David Brazdil 2021-01-05 240 assert_ne(idx, SHN_UNDEF, "%u");
8c49b5d43d4c45 David Brazdil 2021-01-05 241 return &elf.sh_table[idx];
8c49b5d43d4c45 David Brazdil 2021-01-05 242 }
8c49b5d43d4c45 David Brazdil 2021-01-05 243
8c49b5d43d4c45 David Brazdil 2021-01-05 244 /*
8c49b5d43d4c45 David Brazdil 2021-01-05 245 * Memory-map the given ELF file, perform sanity checks, and
8c49b5d43d4c45 David Brazdil 2021-01-05 246 * populate global state.
8c49b5d43d4c45 David Brazdil 2021-01-05 247 */
8c49b5d43d4c45 David Brazdil 2021-01-05 248 static void init_elf(const char *path)
8c49b5d43d4c45 David Brazdil 2021-01-05 249 {
8c49b5d43d4c45 David Brazdil 2021-01-05 250 int fd, ret;
8c49b5d43d4c45 David Brazdil 2021-01-05 251 struct stat stat;
8c49b5d43d4c45 David Brazdil 2021-01-05 252
8c49b5d43d4c45 David Brazdil 2021-01-05 253 /* Store path in the global struct for error printing. */
8c49b5d43d4c45 David Brazdil 2021-01-05 254 elf.path = path;
8c49b5d43d4c45 David Brazdil 2021-01-05 255
8c49b5d43d4c45 David Brazdil 2021-01-05 256 /* Open the ELF file. */
8c49b5d43d4c45 David Brazdil 2021-01-05 257 fd = open(path, O_RDONLY);
8c49b5d43d4c45 David Brazdil 2021-01-05 258 if (fd < 0)
8c49b5d43d4c45 David Brazdil 2021-01-05 259 fatal_perror("Could not open ELF file");
8c49b5d43d4c45 David Brazdil 2021-01-05 260
8c49b5d43d4c45 David Brazdil 2021-01-05 261 /* Get status of ELF file to obtain its size. */
8c49b5d43d4c45 David Brazdil 2021-01-05 262 ret = fstat(fd, &stat);
8c49b5d43d4c45 David Brazdil 2021-01-05 263 if (ret < 0) {
8c49b5d43d4c45 David Brazdil 2021-01-05 264 close(fd);
8c49b5d43d4c45 David Brazdil 2021-01-05 265 fatal_perror("Could not get status of ELF file");
8c49b5d43d4c45 David Brazdil 2021-01-05 266 }
8c49b5d43d4c45 David Brazdil 2021-01-05 267
8c49b5d43d4c45 David Brazdil 2021-01-05 268 /* mmap() the entire ELF file read-only at an arbitrary address. */
8c49b5d43d4c45 David Brazdil 2021-01-05 269 elf.begin = mmap(0, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
8c49b5d43d4c45 David Brazdil 2021-01-05 270 if (elf.begin == MAP_FAILED) {
8c49b5d43d4c45 David Brazdil 2021-01-05 271 close(fd);
8c49b5d43d4c45 David Brazdil 2021-01-05 272 fatal_perror("Could not mmap ELF file");
8c49b5d43d4c45 David Brazdil 2021-01-05 273 }
8c49b5d43d4c45 David Brazdil 2021-01-05 274
8c49b5d43d4c45 David Brazdil 2021-01-05 275 /* mmap() was successful, close the FD. */
8c49b5d43d4c45 David Brazdil 2021-01-05 276 close(fd);
8c49b5d43d4c45 David Brazdil 2021-01-05 277
8c49b5d43d4c45 David Brazdil 2021-01-05 278 /* Get pointer to the ELF header. */
83de54b4bb92bc Tianjia Zhang 2024-10-09 279 assert_ge(stat.st_size, (off_t)sizeof(*elf.ehdr), "%llu");
8c49b5d43d4c45 David Brazdil 2021-01-05 280 elf.ehdr = elf_ptr(Elf64_Ehdr, 0);
8c49b5d43d4c45 David Brazdil 2021-01-05 281
8c49b5d43d4c45 David Brazdil 2021-01-05 282 /* Check the ELF magic. */
8c49b5d43d4c45 David Brazdil 2021-01-05 283 assert_eq(elf.ehdr->e_ident[EI_MAG0], ELFMAG0, "0x%x");
8c49b5d43d4c45 David Brazdil 2021-01-05 284 assert_eq(elf.ehdr->e_ident[EI_MAG1], ELFMAG1, "0x%x");
8c49b5d43d4c45 David Brazdil 2021-01-05 285 assert_eq(elf.ehdr->e_ident[EI_MAG2], ELFMAG2, "0x%x");
8c49b5d43d4c45 David Brazdil 2021-01-05 286 assert_eq(elf.ehdr->e_ident[EI_MAG3], ELFMAG3, "0x%x");
8c49b5d43d4c45 David Brazdil 2021-01-05 287
8c49b5d43d4c45 David Brazdil 2021-01-05 288 /* Sanity check that this is an ELF64 relocatable object for AArch64. */
8c49b5d43d4c45 David Brazdil 2021-01-05 289 assert_eq(elf.ehdr->e_ident[EI_CLASS], ELFCLASS64, "%u");
bc93763f178fd0 Marc Zyngier 2021-01-30 290 assert_eq(elf.ehdr->e_ident[EI_DATA], ELFENDIAN, "%u");
bc93763f178fd0 Marc Zyngier 2021-01-30 291 assert_eq(elf16toh(elf.ehdr->e_type), ET_REL, "%u");
bc93763f178fd0 Marc Zyngier 2021-01-30 292 assert_eq(elf16toh(elf.ehdr->e_machine), EM_AARCH64, "%u");
8c49b5d43d4c45 David Brazdil 2021-01-05 293
8c49b5d43d4c45 David Brazdil 2021-01-05 294 /* Populate fields of the global struct. */
bc93763f178fd0 Marc Zyngier 2021-01-30 295 elf.sh_table = section_by_off(elf64toh(elf.ehdr->e_shoff));
bc93763f178fd0 Marc Zyngier 2021-01-30 296 elf.sh_string = section_begin(section_by_idx(elf16toh(elf.ehdr->e_shstrndx)));
8c49b5d43d4c45 David Brazdil 2021-01-05 297 }
8c49b5d43d4c45 David Brazdil 2021-01-05 298
8c49b5d43d4c45 David Brazdil 2021-01-05 299 /* Print the prologue of the output ASM file. */
8c49b5d43d4c45 David Brazdil 2021-01-05 300 static void emit_prologue(void)
8c49b5d43d4c45 David Brazdil 2021-01-05 301 {
8c49b5d43d4c45 David Brazdil 2021-01-05 302 printf(".data\n"
8c49b5d43d4c45 David Brazdil 2021-01-05 303 ".pushsection " HYP_RELOC_SECTION ", \"a\"\n");
8c49b5d43d4c45 David Brazdil 2021-01-05 304 }
8c49b5d43d4c45 David Brazdil 2021-01-05 305
8c49b5d43d4c45 David Brazdil 2021-01-05 306 /* Print ASM statements needed as a prologue to a processed hyp section. */
8c49b5d43d4c45 David Brazdil 2021-01-05 307 static void emit_section_prologue(const char *sh_orig_name)
8c49b5d43d4c45 David Brazdil 2021-01-05 308 {
8c49b5d43d4c45 David Brazdil 2021-01-05 309 /* Declare the hyp section symbol. */
8c49b5d43d4c45 David Brazdil 2021-01-05 310 printf(".global %s%s\n", HYP_SECTION_SYMBOL_PREFIX, sh_orig_name);
8c49b5d43d4c45 David Brazdil 2021-01-05 311 }
8c49b5d43d4c45 David Brazdil 2021-01-05 312
8c49b5d43d4c45 David Brazdil 2021-01-05 313 /*
8c49b5d43d4c45 David Brazdil 2021-01-05 314 * Print ASM statements to create a hyp relocation entry for a given
8c49b5d43d4c45 David Brazdil 2021-01-05 315 * R_AARCH64_ABS64 relocation.
8c49b5d43d4c45 David Brazdil 2021-01-05 316 *
8c49b5d43d4c45 David Brazdil 2021-01-05 317 * The linker of vmlinux will populate the position given by `rela` with
8c49b5d43d4c45 David Brazdil 2021-01-05 318 * an absolute 64-bit kernel VA. If the kernel is relocatable, it will
8c49b5d43d4c45 David Brazdil 2021-01-05 319 * also generate a dynamic relocation entry so that the kernel can shift
8c49b5d43d4c45 David Brazdil 2021-01-05 320 * the address at runtime for KASLR.
8c49b5d43d4c45 David Brazdil 2021-01-05 321 *
8c49b5d43d4c45 David Brazdil 2021-01-05 322 * Emit a 32-bit offset from the current address to the position given
8c49b5d43d4c45 David Brazdil 2021-01-05 323 * by `rela`. This way the kernel can iterate over all kernel VAs used
8c49b5d43d4c45 David Brazdil 2021-01-05 324 * by hyp at runtime and convert them to hyp VAs. However, that offset
8c49b5d43d4c45 David Brazdil 2021-01-05 325 * will not be known until linking of `vmlinux`, so emit a PREL32
8c49b5d43d4c45 David Brazdil 2021-01-05 326 * relocation referencing a symbol that the hyp linker script put at
8c49b5d43d4c45 David Brazdil 2021-01-05 327 * the beginning of the relocated section + the offset from `rela`.
8c49b5d43d4c45 David Brazdil 2021-01-05 328 */
8c49b5d43d4c45 David Brazdil 2021-01-05 329 static void emit_rela_abs64(Elf64_Rela *rela, const char *sh_orig_name)
8c49b5d43d4c45 David Brazdil 2021-01-05 330 {
8c49b5d43d4c45 David Brazdil 2021-01-05 331 /* Offset of this reloc from the beginning of HYP_RELOC_SECTION. */
8c49b5d43d4c45 David Brazdil 2021-01-05 332 static size_t reloc_offset;
8c49b5d43d4c45 David Brazdil 2021-01-05 333
8c49b5d43d4c45 David Brazdil 2021-01-05 334 /* Create storage for the 32-bit offset. */
8c49b5d43d4c45 David Brazdil 2021-01-05 335 printf(".word 0\n");
8c49b5d43d4c45 David Brazdil 2021-01-05 336
8c49b5d43d4c45 David Brazdil 2021-01-05 337 /*
8c49b5d43d4c45 David Brazdil 2021-01-05 338 * Create a PREL32 relocation which instructs the linker of `vmlinux`
8c49b5d43d4c45 David Brazdil 2021-01-05 339 * to insert offset to position <base> + <offset>, where <base> is
8c49b5d43d4c45 David Brazdil 2021-01-05 340 * a symbol at the beginning of the relocated section, and <offset>
8c49b5d43d4c45 David Brazdil 2021-01-05 341 * is `rela->r_offset`.
8c49b5d43d4c45 David Brazdil 2021-01-05 342 */
83de54b4bb92bc Tianjia Zhang 2024-10-09 @343 printf(".reloc %lu, R_AARCH64_PREL32, %s%s + 0x%llx\n",
8c49b5d43d4c45 David Brazdil 2021-01-05 344 reloc_offset, HYP_SECTION_SYMBOL_PREFIX, sh_orig_name,
bc93763f178fd0 Marc Zyngier 2021-01-30 345 elf64toh(rela->r_offset));
8c49b5d43d4c45 David Brazdil 2021-01-05 346
8c49b5d43d4c45 David Brazdil 2021-01-05 347 reloc_offset += 4;
8c49b5d43d4c45 David Brazdil 2021-01-05 348 }
8c49b5d43d4c45 David Brazdil 2021-01-05 349
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Powered by blists - more mailing lists