GenFw: Bad definition for symbol


Oliver Steffen
 

Hi everyone,

I get this error when building StandaloneMmPkg for AARCH64 using gcc 11
on Ubuntu 22.04:

Bad definition for symbol '_GLOBAL_OFFSET_TABLE_'@0x5a20 or
unsupported symbol type.

All other Pkgs seem to build without problems. Am I missing something
obvious?
It also works on Fedora 35, gcc 11.


From the build log:

INFO - "GenFw" -e MM_CORE_STANDALONE -o /__w/1/s/Build/StandaloneMm/DEBUG_GCC5/AARCH64/StandaloneMmPkg/Core/StandaloneMmCore/OUTPUT/StandaloneMmCore.efi /__w/1/s/Build/StandaloneMm/DEBUG_GCC5/AARCH64/StandaloneMmPkg/Core/StandaloneMmCore/DEBUG/StandaloneMmCore.dll
INFO - GenFw: ERROR 3000: Invalid
INFO - /__w/1/s/Build/StandaloneMm/DEBUG_GCC5/AARCH64/StandaloneMmPkg/Core/StandaloneMmCore/DEBUG/StandaloneMmCore.dll: Bad definition for symbol '_GLOBAL_OFFSET_TABLE_'@0x5a20 or unsupported symbol type. For example, absolute and undefined symbols are not supported.


$ aarch64-linux-gnu-objdump -t StandaloneMmCore.dll | grep GLOBAL
0000000000005a20 l O *ABS* 0000000000000000 _GLOBAL_OFFSET_TABLE_


Compiler:

root@54a9075a6e3f:/w/local-ci-runs# aarch64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/aarch64-linux-gnu/11/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.2.0-17ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --without-target-system-zlib --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=aarch64-linux-gnu --program-prefix=aarch64-linux-gnu- --includedir=/usr/aarch64-linux-gnu/include --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Ubuntu 11.2.0-17ubuntu1)


Running GenFw with gdb:

Breakpoint 2, WriteSections64 (FilterType=<optimized out>) at Elf64Convert.c:1314
1314 const UINT8 *SymName = GetSymName(Sym);
(gdb) l
1309 // Check section header index found in symbol table and get the section
1310 // header location.
1311 //
1312 if (Sym->st_shndx == SHN_UNDEF
1313 || Sym->st_shndx >= mEhdr->e_shnum) {
1314 const UINT8 *SymName = GetSymName(Sym);
1315 if (SymName == NULL) {
1316 SymName = (const UINT8 *)"<unknown>";
1317 }
1318
1319 //
1320 // Skip error on EM_RISCV64 becasue no symble name is built
1321 // from RISC-V toolchain.
1322 //
1323 if (mEhdr->e_machine != EM_RISCV64) {
1324 Error (NULL, 0, 3000, "Invalid",
1325 "%s: Bad definition for symbol '%s'@%#llx or unsupported symbol type. "
1326 "For example, absolute and undefined symbols are not supported.",
1327 mInImageName, SymName, Sym->st_value);
1328
1329 exit(EXIT_FAILURE);
1330 }
1331 continue;
1332 }
(gdb) print *Sym
$3 = {st_name = 2778, st_info = 1 '\001', st_other = 0 '\000', st_shndx = 65521, st_value = 23072, st_size = 0}
(gdb) print *mEhdr
$4 = {e_ident = "\177ELF\002\001\001\000\000\000\000\000\000\000\000", e_type = 3, e_machine = 183, e_version = 1,
e_entry = 18332, e_phoff = 64, e_shoff = 558048, e_flags = 0, e_ehsize = 64, e_phentsize = 56, e_phnum = 2,
e_shentsize = 64, e_shnum = 25, e_shstrndx = 24}

One can see that st_shndx = 65521, while e_shnum = 25.


Any ideas?

Thanks!!

Cheers,
Oliver


Oliver Steffen
 

On 08.04.2022 14:08, Oliver Steffen wrote:
Hi everyone,

I get this error when building StandaloneMmPkg for AARCH64 using gcc 11
on Ubuntu 22.04:

Bad definition for symbol '_GLOBAL_OFFSET_TABLE_'@0x5a20 or
unsupported symbol type.
One solution is to add `-fno-stack-protector` to
`GCC5_AARCH64_CC_FLAGS`.

-- Oliver