[PATCH] D63596: [yaml2obj/obj2yaml] - Allow having the symbols and sections with duplicated names.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 21 02:28:18 PDT 2019


grimar added a comment.

In D63596#1553209 <https://reviews.llvm.org/D63596#1553209>, @jhenderson wrote:

> Hmmm... I'm not sure we need any special behaviour at all in the name field of the syntax, and the suggested syntax is not obvious to me. Surely if yaml2obj sees two symbols with the same name, it should just generate two such symbols?
>
> I guess the issue really is how to reference them, but I don't think that should be done through the name field of the symbol personally. I'm still thinking about this, but you could have a separate ID field, which is required to be unique, and allow references be via ID? Example:
>
>   Symbols:
>     - Name: foo
>       ID: foo1 # error if symbol name of foo1 exists
>     - Name: foo
>       ID: foo2
>   Sections:
>     - Name: .rela
>       Type: SHT_RELA
>       Relocations:
>         - Offset: 0
>           Type: R_X86_64_NONE
>           Symbol: foo1 # use ID
>         - Offset: 1
>           Type: R_X86_64_NONE
>           Symbol: foo # error - ambiguous
>  
>   # Possible alternative:
>         - Offset: 0
>           Type: R_X86_64_NONE
>           Symbol: foo # use name, but if multiple found, fallback to ID; error if no ID specified during fallback.
>           ID: foo1
>
>
> The same syntax would work for sections.


I experimented with the code a lot while worked on this patch and having an additional index was a solution
I also considered, but dropped this idea.

At this moment we use `NameToIdxMap` class to lookup symbol or section index by name in many places.
What you suggest needs a major rework of the code. This change will introduce additional complexity for all cases,
even when we have no duplications at all (99% of all cases I guess?).

The logic to "use name, but if multiple found, fallback to ID" seems overcomplicated to me,
it will be hard to read and maintain such YAML. May be we can reference symbols only by ID in all cases,
but it is also inconvenient way generally and is harmfull for readability.

I do not think it is a very often case to have duplicated symbol/sections name, so I selected the less intrusive way.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63596/new/

https://reviews.llvm.org/D63596





More information about the llvm-commits mailing list