Currently, llvm-objcopy assumes that any SHT_REL/SHT_RELA type section with the SHF_ALLOC attribute is a dynamic relocation section, and therefore treats any linked symbol and string tables as being of the dynamic variety.
However, the ELF spec permits the use of SHF_ALLOC for ordinary SHT_RELA type sections as well, and so this heuristic is not entirely accurate, and may produce incorrect results, resulting in cryptic error messages such as
llvm-strip: error: Link field value 48 in section .rela.text is not a symbol table
where the file in question does in fact have a SYMTAB section at #48.
While this occurs rarely for normal user programs, the Linux kernel uses partially linked ET_REL objects as its loadable module format, and there, we sometimes rely on SHF_ALLOC to indicate to the module loader that the static relocations (which the Linux kernel fixes up at module load time) need to be preserved in memory after loading of the module completes.
So let's extend the existing heuristic with a check against the file type: for ET_REL type files, which are only partiallly linked and cannot carry dynamic relocations, we assume that the RELA sections are static. For ET_DYN/ET_EXEC type files, we stick to the old behavior, which is to use the SHF_ALLOC flag as a hint to decide whether relocation sections are static or dynamic.
Note that this requires that reading the section headers is deferred until after we figure out the file type, which also means that the code that finds the executable header offset needs to be reworked somewhat so it does not rely on this.