microsoft / microsoft/STL

special_math.cpp: Statically linked library contains and depends on Boost symbols

Open
#362 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

blocked bug
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

Description
Boost symbols embedded in static library can conflict with user code and/or custom boost installations.

Example 1
In this example one can override behaviour of standard library function using custom boost symbol.

PS G:\dev\test> type .\test.cpp
#include <cmath>
#include <cstdio>

namespace boost::math {
template<typename T>
T zeta(T)
{
    return 0;
}
}

int main()
{
    auto a = boost::math::zeta(10.0);
    auto b = std::riemann_zeta(10.0);
    std::printf("boost = %f\nstd   = %f\n", a, b);
    return 0;
}
PS G:\dev\test> cl -EHsc -std:c++17 -MDd -nologo .\test.cpp
test.cpp
PS G:\dev\test> .\test.exe
boost = 0.000000
std   = 1.000995
PS G:\dev\test> cl -EHsc -std:c++17 -MTd -nologo .\test.cpp
test.cpp
PS G:\dev\test> .\test.exe
boost = 0.000000
std   = 0.000000
PS G:\dev\test> cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.24.28314 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Playing with different compiler flags I also got following output once:

boost = 1.000995
std   = 1.000995

but I forgot exact combination and wasn't able to reproduce it later.

Example 2
In this example one can link to boost symbols contained in STL.

PS G:\dev\test> type .\test.cpp
#include <cmath>
#include <cstdio>

namespace boost::math {
template<typename T>
T zeta(T);

extern template double zeta<double>(double);
}

int main()
{
    auto a = boost::math::zeta(10.0);
    std::printf("boost = %f\n", a);
    return 0;
}
PS G:\dev\test> cl -EHsc -std:c++17 -MT -nologo .\test.cpp
test.cpp
PS G:\dev\test> .\test.exe
boost = 1.000995
PS G:\dev\test> cl -EHsc -std:c++17 -MD -nologo .\test.cpp
test.cpp
test.obj : error LNK2019: unresolved external symbol "double __cdecl boost::math::zeta<double>(double)" (??$zeta@N@math@boost@@YANN@Z) referenced in function main
test.exe : fatal error LNK1120: 1 unresolved externals

Expected behavior
STL shouldn't expose any third-party symbols to user code in order to avoid conflicts.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with special_math.cpp and reproduce both linker examples to inspect which Boost symbols are present in the statically linked library. Compare the static and dynamic cases; done means the STL no longer exposes or provides conflicting Boost symbols in either example.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.