[lld] r195774 - [PECOFF] Fix parameter mapping for /section.

Rui Ueyama ruiu at google.com
Tue Nov 26 16:04:28 PST 2013


On Tue, Nov 26, 2013 at 4:01 PM, Sean Silva <silvas at purdue.edu> wrote:

> +#define TEST_SECTION(testname, arg, expect)
>    \
> +  TEST_F(WinLinkParserTest, testname) {
>    \
> +    EXPECT_TRUE(parse("link.exe", "/section:.text," arg, "a.obj",
> nullptr)); \
> +    llvm::Optional<uint32_t> val = _context.getSectionAttributes(".text");
>   \
> +    EXPECT_TRUE(val.hasValue());
>     \
> +    EXPECT_EQ(expect, *val);
>     \
> +  }
> +
> +TEST_SECTION(SectionD, "d", llvm::COFF::IMAGE_SCN_MEM_DISCARDABLE);
> +TEST_SECTION(SectionE, "e", llvm::COFF::IMAGE_SCN_MEM_EXECUTE);
> +TEST_SECTION(SectionK, "k", llvm::COFF::IMAGE_SCN_MEM_NOT_CACHED);
> +TEST_SECTION(SectionP, "p", llvm::COFF::IMAGE_SCN_MEM_NOT_PAGED);
> +TEST_SECTION(SectionR, "r", llvm::COFF::IMAGE_SCN_MEM_READ);
> +TEST_SECTION(SectionS, "s", llvm::COFF::IMAGE_SCN_MEM_SHARED);
> +TEST_SECTION(SectionW, "w", llvm::COFF::IMAGE_SCN_MEM_WRITE);
>
> Is there a better way to test this? It seems like all it's doing is
> checking is whether you typed (pasted?) the same thing in two different
> files; this same sort of test doesn't seem like it would have caught the
> bug that you are fixing in this commit.
>

It should eventually be tested using llvm-readobj by checking the section
attributes. The problem is that the parser is already implemented in the
driver but the writer is not. So we can write tests only for the drivers,
which ended up tests like the above.

-- Sean Silva
>
>
> On Tue, Nov 26, 2013 at 12:57 PM, Rui Ueyama <ruiu at google.com> wrote:
>
>> Author: ruiu
>> Date: Tue Nov 26 11:57:05 2013
>> New Revision: 195774
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=195774&view=rev
>> Log:
>> [PECOFF] Fix parameter mapping for /section.
>>
>> The current mapping for /section one character options is really bogus.
>> Map to the correct flags.
>>
>> Modified:
>>     lld/trunk/lib/Driver/WinLinkDriver.cpp
>>     lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
>>
>> Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=195774&r1=195773&r2=195774&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
>> +++ lld/trunk/lib/Driver/WinLinkDriver.cpp Tue Nov 26 11:57:05 2013
>> @@ -156,7 +156,7 @@ llvm::COFF::MachineTypes stringToMachine
>>  //
>>  // /section option is to set non-default bits in the Characteristics
>> fields of
>>  // the section header. D, E, K, P, R, S, and W represent discardable,
>> -// not_cachable, not_pageable, shared, execute, read, and write bits,
>> +// execute, not_cachable, not_pageable, read, shared, and write bits,
>>  // respectively. You can specify multiple flags in one /section option.
>>  //
>>  // If the flag starts with "!", the flags represent a mask that should
>> be turned
>> @@ -185,11 +185,11 @@ bool parseSection(StringRef option, std:
>>        attribs |= flag;                          \
>>        break
>>      CASE('d', llvm::COFF::IMAGE_SCN_MEM_DISCARDABLE);
>> -    CASE('e', llvm::COFF::IMAGE_SCN_MEM_NOT_CACHED);
>> -    CASE('k', llvm::COFF::IMAGE_SCN_MEM_NOT_PAGED);
>> -    CASE('p', llvm::COFF::IMAGE_SCN_MEM_SHARED);
>> -    CASE('r', llvm::COFF::IMAGE_SCN_MEM_EXECUTE);
>> -    CASE('s', llvm::COFF::IMAGE_SCN_MEM_READ);
>> +    CASE('e', llvm::COFF::IMAGE_SCN_MEM_EXECUTE);
>> +    CASE('k', llvm::COFF::IMAGE_SCN_MEM_NOT_CACHED);
>> +    CASE('p', llvm::COFF::IMAGE_SCN_MEM_NOT_PAGED);
>> +    CASE('r', llvm::COFF::IMAGE_SCN_MEM_READ);
>> +    CASE('s', llvm::COFF::IMAGE_SCN_MEM_SHARED);
>>      CASE('w', llvm::COFF::IMAGE_SCN_MEM_WRITE);
>>  #undef CASE
>>      default:
>>
>> Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=195774&r1=195773&r2=195774&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
>> +++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Tue Nov 26
>> 11:57:05 2013
>> @@ -236,6 +236,36 @@ TEST_F(WinLinkParserTest, SectionAlignme
>>    EXPECT_EQ(8192U, _context.getSectionDefaultAlignment());
>>  }
>>
>> +TEST_F(WinLinkParserTest, InvalidAlignment) {
>> +  EXPECT_FALSE(parse("link.exe", "/align:1000", "a.obj", nullptr));
>> +  EXPECT_EQ("Section alignment must be a power of 2, but got 1000\n",
>> +            errorMessage());
>> +}
>> +
>> +TEST_F(WinLinkParserTest, Include) {
>> +  EXPECT_TRUE(parse("link.exe", "/include:foo", "a.out", nullptr));
>> +  auto symbols = _context.initialUndefinedSymbols();
>> +  EXPECT_FALSE(symbols.empty());
>> +  EXPECT_EQ("foo", symbols[0]);
>> +}
>> +
>> +TEST_F(WinLinkParserTest, Merge) {
>> +  EXPECT_TRUE(parse("link.exe", "/merge:.foo=.bar", "/merge:.bar=.baz",
>> +                    "a.out", nullptr));
>> +  EXPECT_EQ(".baz", _context.getFinalSectionName(".foo"));
>> +  EXPECT_EQ(".baz", _context.getFinalSectionName(".bar"));
>> +  EXPECT_EQ(".abc", _context.getFinalSectionName(".abc"));
>> +}
>> +
>> +TEST_F(WinLinkParserTest, Merge_Circular) {
>> +  EXPECT_FALSE(parse("link.exe", "/merge:.foo=.bar", "/merge:.bar=.foo",
>> +                     "a.out", nullptr));
>> +}
>> +
>> +//
>> +// Tests for /section
>> +//
>> +
>>  TEST_F(WinLinkParserTest, Section) {
>>    EXPECT_TRUE(parse("link.exe", "/section:.teXT,dekpRSW", "a.obj",
>> nullptr));
>>    uint32_t expect = llvm::COFF::IMAGE_SCN_MEM_DISCARDABLE |
>> @@ -267,31 +297,23 @@ TEST_F(WinLinkParserTest, SectionNegativ
>>    EXPECT_EQ(expect, _context.getSectionAttributeMask(".teXT"));
>>  }
>>
>> -TEST_F(WinLinkParserTest, InvalidAlignment) {
>> -  EXPECT_FALSE(parse("link.exe", "/align:1000", "a.obj", nullptr));
>> -  EXPECT_EQ("Section alignment must be a power of 2, but got 1000\n",
>> -            errorMessage());
>> -}
>> -
>> -TEST_F(WinLinkParserTest, Include) {
>> -  EXPECT_TRUE(parse("link.exe", "/include:foo", "a.out", nullptr));
>> -  auto symbols = _context.initialUndefinedSymbols();
>> -  EXPECT_FALSE(symbols.empty());
>> -  EXPECT_EQ("foo", symbols[0]);
>> -}
>> -
>> -TEST_F(WinLinkParserTest, Merge) {
>> -  EXPECT_TRUE(parse("link.exe", "/merge:.foo=.bar", "/merge:.bar=.baz",
>> -                    "a.out", nullptr));
>> -  EXPECT_EQ(".baz", _context.getFinalSectionName(".foo"));
>> -  EXPECT_EQ(".baz", _context.getFinalSectionName(".bar"));
>> -  EXPECT_EQ(".abc", _context.getFinalSectionName(".abc"));
>> -}
>> +#define TEST_SECTION(testname, arg, expect)
>>      \
>> +  TEST_F(WinLinkParserTest, testname) {
>>      \
>> +    EXPECT_TRUE(parse("link.exe", "/section:.text," arg, "a.obj",
>> nullptr)); \
>> +    llvm::Optional<uint32_t> val =
>> _context.getSectionAttributes(".text");   \
>> +    EXPECT_TRUE(val.hasValue());
>>     \
>> +    EXPECT_EQ(expect, *val);
>>     \
>> +  }
>> +
>> +TEST_SECTION(SectionD, "d", llvm::COFF::IMAGE_SCN_MEM_DISCARDABLE);
>> +TEST_SECTION(SectionE, "e", llvm::COFF::IMAGE_SCN_MEM_EXECUTE);
>> +TEST_SECTION(SectionK, "k", llvm::COFF::IMAGE_SCN_MEM_NOT_CACHED);
>> +TEST_SECTION(SectionP, "p", llvm::COFF::IMAGE_SCN_MEM_NOT_PAGED);
>> +TEST_SECTION(SectionR, "r", llvm::COFF::IMAGE_SCN_MEM_READ);
>> +TEST_SECTION(SectionS, "s", llvm::COFF::IMAGE_SCN_MEM_SHARED);
>> +TEST_SECTION(SectionW, "w", llvm::COFF::IMAGE_SCN_MEM_WRITE);
>>
>> -TEST_F(WinLinkParserTest, Merge_Circular) {
>> -  EXPECT_FALSE(parse("link.exe", "/merge:.foo=.bar", "/merge:.bar=.foo",
>> -                     "a.out", nullptr));
>> -}
>> +#undef TEST_SECTION
>>
>>  //
>>  // Tests for /defaultlib and /nodefaultlib.
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131126/4dd72035/attachment.html>


More information about the llvm-commits mailing list