emit: Notice type shadowing, i.e. multiple types with the same name (enum, struct, union, etc)

We can't have on the same compilation unit more than one of struct,
union, enum, class type with the same name, so when trying to create a
file with all types in a multi compilation unit binary debug
information we must disambiguate, do it by addint a __N prefix to the
type name.

This is the same strategy adopted by the bpftool when generating a
vmlinux file using:

  $ bpftool btf dump file vmlinux format c > vmlinux.h

Testing it:

  $ cat a.c
  #include "vmlinux.h"

  int main(void)
  {
  	struct saved_context bla;

  	bla.ds = 1;
  	return bla.ds + 1;
  }
  $

  $ rm -f a ; make a
  cc     a.c   -o a
  $

With an upcoming patch this will be possible using:

  $ pahole --compile > vmlinux.h
  $ rm -f a ; make a
  $

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
3 files changed