From: Armando Montanez Date: Fri, 21 Dec 2018 20:45:58 +0000 (+0000) Subject: [TextAPI][elfabi] Fix YAML support for weak symbols X-Git-Tag: llvmorg-8.0.0-rc1~1376 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4cc2113114d226757ce37b69dc6093bb17a5feb8;p=platform%2Fupstream%2Fllvm.git [TextAPI][elfabi] Fix YAML support for weak symbols Weak symbols are supposed to be supported in the ELF TextAPI implementation, but the YAML handler didn't read or write the `Weak` member of ELFSymbol. This change adds the YAML mapping and updates tests to ensure correct behavior. Differential Revision: https://reviews.llvm.org/D56020 llvm-svn: 349950 --- diff --git a/llvm/lib/TextAPI/ELF/TBEHandler.cpp b/llvm/lib/TextAPI/ELF/TBEHandler.cpp index dde9802..b621829 100644 --- a/llvm/lib/TextAPI/ELF/TBEHandler.cpp +++ b/llvm/lib/TextAPI/ELF/TBEHandler.cpp @@ -105,6 +105,7 @@ template <> struct MappingTraits { IO.mapRequired("Size", Symbol.Size); } IO.mapOptional("Undefined", Symbol.Undefined, false); + IO.mapOptional("Weak", Symbol.Weak, false); IO.mapOptional("Warning", Symbol.Warning); } diff --git a/llvm/unittests/TextAPI/ELFYAMLTest.cpp b/llvm/unittests/TextAPI/ELFYAMLTest.cpp index 802a2d7..0aeec16 100644 --- a/llvm/unittests/TextAPI/ELFYAMLTest.cpp +++ b/llvm/unittests/TextAPI/ELFYAMLTest.cpp @@ -65,7 +65,7 @@ TEST(ElfYamlTextAPI, YAMLReadsTBESymbols) { " foo: { Type: Func, Warning: \"Deprecated!\" }\n" " nor: { Type: NoType, Undefined: true }\n" " not: { Type: File, Undefined: true, Size: 111, " - "Warning: \'All fields populated!\' }\n" + "Weak: true, Warning: \'All fields populated!\' }\n" "...\n"; Expected> StubOrErr = readTBEFromBuffer(Data); ASSERT_THAT_ERROR(StubOrErr.takeError(), Succeeded()); @@ -81,6 +81,7 @@ TEST(ElfYamlTextAPI, YAMLReadsTBESymbols) { EXPECT_EQ(SymBar.Size, 42u); EXPECT_EQ(SymBar.Type, ELFSymbolType::Object); EXPECT_FALSE(SymBar.Undefined); + EXPECT_FALSE(SymBar.Weak); EXPECT_FALSE(SymBar.Warning.hasValue()); ELFSymbol const &SymBaz = *Iterator++; @@ -88,6 +89,7 @@ TEST(ElfYamlTextAPI, YAMLReadsTBESymbols) { EXPECT_EQ(SymBaz.Size, 3u); EXPECT_EQ(SymBaz.Type, ELFSymbolType::TLS); EXPECT_FALSE(SymBaz.Undefined); + EXPECT_FALSE(SymBaz.Weak); EXPECT_FALSE(SymBaz.Warning.hasValue()); ELFSymbol const &SymFoo = *Iterator++; @@ -95,6 +97,7 @@ TEST(ElfYamlTextAPI, YAMLReadsTBESymbols) { EXPECT_EQ(SymFoo.Size, 0u); EXPECT_EQ(SymFoo.Type, ELFSymbolType::Func); EXPECT_FALSE(SymFoo.Undefined); + EXPECT_FALSE(SymFoo.Weak); EXPECT_TRUE(SymFoo.Warning.hasValue()); EXPECT_STREQ(SymFoo.Warning->c_str(), "Deprecated!"); @@ -103,6 +106,7 @@ TEST(ElfYamlTextAPI, YAMLReadsTBESymbols) { EXPECT_EQ(SymNor.Size, 0u); EXPECT_EQ(SymNor.Type, ELFSymbolType::NoType); EXPECT_TRUE(SymNor.Undefined); + EXPECT_FALSE(SymNor.Weak); EXPECT_FALSE(SymNor.Warning.hasValue()); ELFSymbol const &SymNot = *Iterator++; @@ -110,6 +114,7 @@ TEST(ElfYamlTextAPI, YAMLReadsTBESymbols) { EXPECT_EQ(SymNot.Size, 111u); EXPECT_EQ(SymNot.Type, ELFSymbolType::Unknown); EXPECT_TRUE(SymNot.Undefined); + EXPECT_TRUE(SymNot.Weak); EXPECT_TRUE(SymNot.Warning.hasValue()); EXPECT_STREQ(SymNot.Warning->c_str(), "All fields populated!"); } @@ -146,6 +151,7 @@ TEST(ElfYamlTextAPI, YAMLWritesTBESymbols) { "TbeVersion: 1.0\n" "Arch: AArch64\n" "Symbols: \n" + " bar: { Type: Func, Weak: true }\n" " foo: { Type: NoType, Size: 99, Warning: Does nothing }\n" " nor: { Type: Func, Undefined: true }\n" " not: { Type: Unknown, Size: 12345678901234 }\n" @@ -158,19 +164,28 @@ TEST(ElfYamlTextAPI, YAMLWritesTBESymbols) { SymFoo.Size = 99u; SymFoo.Type = ELFSymbolType::NoType; SymFoo.Undefined = false; + SymFoo.Weak = false; SymFoo.Warning = "Does nothing"; + ELFSymbol SymBar("bar"); + SymBar.Size = 128u; + SymBar.Type = ELFSymbolType::Func; + SymBar.Weak = true; + ELFSymbol SymNor("nor"); SymNor.Type = ELFSymbolType::Func; SymNor.Undefined = true; + SymNor.Weak = false; ELFSymbol SymNot("not"); SymNot.Size = 12345678901234u; SymNot.Type = ELFSymbolType::Unknown; SymNot.Undefined = false; + SymNot.Weak = false; // Deliberately not in order to check that result is sorted. Stub.Symbols.insert(SymNot); + Stub.Symbols.insert(SymBar); Stub.Symbols.insert(SymFoo); Stub.Symbols.insert(SymNor);