boostorg / boostorg/build

bjam' always 'bus error' on NetBSD/sparc (presumably, other strict-alignement 32 bits arch as well)

Open
#608 2 comments 1 reaction 0 assignees View on GitHub
bug transition
Dominant language
C++
Stars
251
Forks
63
PR merge metrics
No merged PRs in 30d

Description

Originally reported downstream at pkgsrc (http://gnats.netbsd.org/55269).

# The observation:

Trying to compile the "boost" meta-package in pkgsrc on NetBSD 9.0/sparc, 'bjam' always crashes with a 'bus error'. The culprit is the function `timestamp_init` in `tools/build/src/engine/timestamp.cpp`, which does:

`time->secs = secs;`

where `secs` are `time_t`, currently 8 bytes. This is only legal on SPARC if `time->secs` is 8-bytes aligned, which it isn't, so the 8-bytes store causes a 'bus error'. The reason for the nonalignment is that it comes from the hash table implementation in hash.cpp, which does:

`#define hash_item_data(item) ((HASHDATA *)((char *)item + sizeof(ITEM)))`

`ITEM` is the size of a pointer, and `item` is properly aligned (at least 8 bytes), so this is _never_ aligned properly with 32-bits pointers... This result in reliable crashes on 32-bits machine with strict alignment requirements (i.e., sparc).

# my fix

The following patch fixes the problem for me, but might be a bit overkill (memory wastage) on 32-bits architecture that supports unaligned access. It should be a no-op on 64-bits architecture.

```
--- tools/build/src/engine/hash.cpp.orig 2019-12-10 01:20:17.000000000 +0100
+++ tools/build/src/engine/hash.cpp 2020-05-16 14:55:46.086210410 +0200
@@ -33,8 +33,8 @@
typedef struct item ITEM;
struct item
{
- ITEM * next;
-};
+ ITEM * next __attribute__ ((aligned (8)));
+} __attribute__ ((aligned (8)));

#define MAX_LISTS 32
```
There is probably better solution than that, that would generally respect alinement's rules on all platforms.

Contributor guide

Open the contributing guide

Research direction

Start with tools/build/src/engine/timestamp.cpp and tools/build/src/engine/hash.cpp, especially timestamp_init and the hash_item_data layout described in the report. Reproduce the bjam bus error on NetBSD/sparc or another strict-alignment 32-bit platform, then verify that the alignment handling is portable and the build completes without the crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.