Skip to content

Commit 86648a0

Browse files
authored
Merge pull request #456 from libtom/mp-has-comment
s_mp_rand_platform: add comment regarding MP_HAS requiring dead code elim
2 parents 59d62c9 + c47d5e8 commit 86648a0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

doc/bn.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ \subsection{Build Depends}
298298
includes itself twice). This is to help resolve as many dependencies as possible. In the last pass
299299
the symbol \texttt{LTM\_LAST} will be defined. This is useful for ``trims''.
300300

301+
Note that the configuration system relies
302+
on dead code elimination. Unfortunately this can result in linking errors on compilers which
303+
perform insufficient dead code elimination. In particular MSVC with the /Od option enabled shows this issue.
304+
The issue can be resolved by passing the /O option instead to the compiler.
305+
301306
\subsection{Build Trims}
302307
A trim is a manner of removing functionality from a function that is not required. For instance,
303308
to perform RSA cryptography you only require exponentiation with odd moduli so even moduli support

s_mp_rand_platform.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ mp_err s_read_wincsp(void *p, size_t n);
117117
mp_err s_read_getrandom(void *p, size_t n);
118118
mp_err s_read_urandom(void *p, size_t n);
119119

120+
/*
121+
* Note: libtommath relies on dead code elimination
122+
* for the configuration system, i.e., the MP_HAS macro.
123+
*
124+
* If you observe linking errors in this functions,
125+
* your compiler does not perform the dead code compilation
126+
* such that the unused functions are still referenced.
127+
*
128+
* This happens for example for MSVC if the /Od compilation
129+
* option is given. The option /Od instructs MSVC to
130+
* not perform any "optimizations", not even removal of
131+
* dead code wrapped in `if (0)` blocks.
132+
*
133+
* If you still insist on compiling with /Od, simply
134+
* comment out the lines which result in linking errors.
135+
*
136+
* We intentionally don't fix this issue in order
137+
* to have a single point of failure for misconfigured compilers.
138+
*/
120139
mp_err s_mp_rand_platform(void *p, size_t n)
121140
{
122141
mp_err err = MP_ERR;

0 commit comments

Comments
 (0)