Re: How to fix the link order of scons?

Mats Wichmann <[email protected]>
Newsgroups gmane.comp.programming.tools.scons.user
Message-ID <[email protected]>
On 9/8/22 05:55, Lan Yang wrote:
> Dear Scons users,
> 
> There's a Scons feature that's been bothering me for two weeks.
> 
> *"When the source files are the same,
> the sequential compilation and linking order of scons is not fixed,
> which is reflected in the inconsistent map files generated."*
> 
> I compiled RT-Thread <https://github.com/RT-Thread/rt-thread> with 
> Scons, an open source embedded OS.
> In the case that nothing is changed in the same project,
> the map files generated two times are different,
> which leads to different BIN files (the firmware downloaded to the MCU) 
> that are finally generated.
> This means that the same source code may make the MCU behave differently,
> which brings some potential bugs.
> 
> When we use Keil <https://www.keil.com/> or other MCU SDK, the map files 
> generated by continuous compilation are the same.
> 
> Therefore, I hope to fix the link order of Scons so that the same source 
> code can be compiled to generate the same map file and firmware.
> 
> *So, can Scons fix the order of links? How to fix the link order of Scons?*
> 
> Best regards,
> Lan


I know this thread has continued, just wanted to note: SCons tries very 
hard to maintain consistency across builds.  Glob, however, (like its 
ancestor, Python´s glob.glob) returns entries in the order given by 
iterating through a directory sequentially, which may or may not be 
sorted, or even stable, depending on the implementation of the 
filesystem underneath (I personally find the latter a little surprising 
but there do appear to be cases where it is not stable).

A number of SCons' own test cases written long ago are aware of this and 
use code conceptually like this to accomodate:

srcs = sorted(Glob(PATTERN, key=lambda t: t.name))

(that is because Glob returns node objects, rather than strings, unless 
you specify the ¨strings=True" keyword argument; if you tell it to 
return strings you would not use the key function, of course)


In fact, other build systems have this challenge too.  For example, here 
is a description of a similar issue for GNU Make:

https://reproducible-builds.org/docs/stable-inputs/


_______________________________________________
Scons-users mailing list
[email protected]
https://pairlist4.pair.net/mailman/listinfo/scons-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.