Skip to content

Commit aba62e9

Browse files
committed
Revert "[yaml2obj] - Don't allow setting StOther and Other/Visibility at the same time."
This reverts commit r370032, it was causing check-llvm failures on sanitizer-x86_64-linux-bootstrap-msan llvm-svn: 370198
1 parent 14e07d7 commit aba62e9

File tree

4 files changed

+20
-73
lines changed

4 files changed

+20
-73
lines changed

llvm/include/llvm/ObjectYAML/ELFYAML.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,7 @@ struct Symbol {
107107
ELF_STB Binding;
108108
llvm::yaml::Hex64 Value;
109109
llvm::yaml::Hex64 Size;
110-
Optional<uint8_t> Other;
111-
112-
// This can be used to set any custom value for the st_other field
113-
// when it is not possible to do so using the "Other" field, which only takes
114-
// specific named constants.
115-
Optional<uint8_t> StOther;
110+
uint8_t Other;
116111
};
117112

118113
struct SectionOrType {

llvm/lib/ObjectYAML/ELFEmitter.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,7 @@ toELFSymbols(NameToIdxMap &SN2I, ArrayRef<ELFYAML::Symbol> Symbols,
464464
}
465465
// else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier.
466466
Symbol.st_value = Sym.Value;
467-
468-
if (Sym.Other)
469-
Symbol.st_other = *Sym.Other;
470-
else if (Sym.StOther)
471-
Symbol.st_other = *Sym.StOther;
472-
467+
Symbol.st_other = Sym.Other;
473468
Symbol.st_size = Sym.Size;
474469
}
475470

llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -866,28 +866,15 @@ void MappingTraits<ELFYAML::ProgramHeader>::mapping(
866866
namespace {
867867

868868
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) {}
880873

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; }
888875

889-
Optional<ELFYAML::ELF_STV> Visibility;
890-
Optional<ELFYAML::ELF_STO> Other;
876+
ELFYAML::ELF_STV Visibility;
877+
ELFYAML::ELF_STO Other;
891878
};
892879

893880
} // end anonymous namespace
@@ -909,16 +896,17 @@ void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
909896
// targets (e.g. MIPS) may use it to specify the named bits to set (e.g.
910897
// STO_MIPS_OPTIONAL). For producing broken objects we want to allow writing
911898
// 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+
}
922910
}
923911

924912
StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
@@ -927,8 +915,6 @@ StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
927915
return "Index and Section cannot both be specified for Symbol";
928916
if (Symbol.NameIndex && !Symbol.Name.empty())
929917
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";
932918
return StringRef();
933919
}
934920

llvm/test/tools/yaml2obj/elf-symbol-stother.yaml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,3 @@ Symbols:
7777
StOther: 4
7878
- Name: bar
7979
StOther: 0xff
80-
81-
## Check we can't set StOther for a symbol if Visibility or Other is also specified.
82-
83-
# RUN: not yaml2obj --docnum=5 2>&1 %s | FileCheck %s --check-prefix=ERR2
84-
# RUN: not yaml2obj --docnum=6 2>&1 %s | FileCheck %s --check-prefix=ERR2
85-
86-
# ERR2: error: StOther cannot be specified for Symbol with either Visibility or Other
87-
88-
--- !ELF
89-
FileHeader:
90-
Class: ELFCLASS32
91-
Data: ELFDATA2LSB
92-
Type: ET_REL
93-
Machine: EM_MIPS
94-
Symbols:
95-
- Name: foo
96-
StOther: 0
97-
Other: [ STO_MIPS_OPTIONAL ]
98-
99-
--- !ELF
100-
FileHeader:
101-
Class: ELFCLASS32
102-
Data: ELFDATA2LSB
103-
Type: ET_REL
104-
Machine: EM_MIPS
105-
Symbols:
106-
- Name: foo
107-
StOther: 0
108-
Visibility: STV_DEFAULT

0 commit comments

Comments
 (0)