@@ -866,28 +866,15 @@ void MappingTraits<ELFYAML::ProgramHeader>::mapping(
866
866
namespace {
867
867
868
868
struct NormalizedOther {
869
- NormalizedOther (IO &) {}
870
- NormalizedOther (IO &, Optional<uint8_t > Original) {
871
- if (uint8_t Val = *Original & 0x3 )
872
- Visibility = Val;
873
- if (uint8_t Val = *Original & ~0x3 )
874
- Other = Val;
875
- }
876
-
877
- Optional<uint8_t > denormalize (IO &) {
878
- if (!Visibility && !Other)
879
- return None;
869
+ NormalizedOther (IO &)
870
+ : Visibility(ELFYAML::ELF_STV(0 )), Other(ELFYAML::ELF_STO(0 )) {}
871
+ NormalizedOther (IO &, uint8_t Original)
872
+ : Visibility(Original & 0x3 ), Other(Original & ~0x3 ) {}
880
873
881
- uint8_t Ret = 0 ;
882
- if (Visibility)
883
- Ret |= *Visibility;
884
- if (Other)
885
- Ret |= *Other;
886
- return Ret;
887
- }
874
+ uint8_t denormalize (IO &) { return Visibility | Other; }
888
875
889
- Optional< ELFYAML::ELF_STV> Visibility;
890
- Optional< ELFYAML::ELF_STO> Other;
876
+ ELFYAML::ELF_STV Visibility;
877
+ ELFYAML::ELF_STO Other;
891
878
};
892
879
893
880
} // end anonymous namespace
@@ -909,16 +896,17 @@ void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
909
896
// targets (e.g. MIPS) may use it to specify the named bits to set (e.g.
910
897
// STO_MIPS_OPTIONAL). For producing broken objects we want to allow writing
911
898
// any value to st_other. To do this we allow one more field called "StOther".
912
- // If it is present in a YAML document, we set st_other to its integer value
913
- // whatever it is.
914
- // obj2yaml should not print 'StOther', it should print 'Visibility' and
915
- // 'Other' fields instead.
916
- assert (!IO.outputting () || !Symbol.StOther .hasValue ());
917
- IO.mapOptional (" StOther" , Symbol.StOther );
918
- MappingNormalization<NormalizedOther, Optional<uint8_t >> Keys (IO,
919
- Symbol.Other );
920
- IO.mapOptional (" Visibility" , Keys->Visibility );
921
- IO.mapOptional (" Other" , Keys->Other );
899
+ // If it is present in a YAML document, we set st_other to that integer,
900
+ // ignoring the other fields.
901
+ Optional<llvm::yaml::Hex64> Other;
902
+ IO.mapOptional (" StOther" , Other);
903
+ if (Other) {
904
+ Symbol.Other = *Other;
905
+ } else {
906
+ MappingNormalization<NormalizedOther, uint8_t > Keys (IO, Symbol.Other );
907
+ IO.mapOptional (" Visibility" , Keys->Visibility , ELFYAML::ELF_STV (0 ));
908
+ IO.mapOptional (" Other" , Keys->Other , ELFYAML::ELF_STO (0 ));
909
+ }
922
910
}
923
911
924
912
StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
@@ -927,8 +915,6 @@ StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
927
915
return " Index and Section cannot both be specified for Symbol" ;
928
916
if (Symbol.NameIndex && !Symbol.Name .empty ())
929
917
return " Name and NameIndex cannot both be specified for Symbol" ;
930
- if (Symbol.StOther && Symbol.Other )
931
- return " StOther cannot be specified for Symbol with either Visibility or Other" ;
932
918
return StringRef ();
933
919
}
934
920
0 commit comments