Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update struct layout for aarch64 linux to match value on device #165

Merged
merged 1 commit into from
Jun 1, 2021

Conversation

robbavey
Copy link
Contributor

@robbavey robbavey commented Jun 1, 2021

The struct layout for aarch64 linux does not match that on AWS graviton2 nodes,
missing several entries.

This commit updates the layout to match the stat structure obtained from the
device:

pahole -C stat /usr/lib/debug/lib64/libc.so.6.debug

struct stat {
	__dev_t                    st_dev;               /*     0     8 */
	__ino_t                    st_ino;               /*     8     8 */
	__mode_t                   st_mode;              /*    16     4 */
	__nlink_t                  st_nlink;             /*    20     4 */
	__uid_t                    st_uid;               /*    24     4 */
	__gid_t                    st_gid;               /*    28     4 */
	__dev_t                    st_rdev;              /*    32     8 */
	__dev_t                    __pad1;               /*    40     8 */
	__off_t                    st_size;              /*    48     8 */
	__blksize_t                st_blksize;           /*    56     4 */
	int                        __pad2;               /*    60     4 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	__blkcnt_t                 st_blocks;            /*    64     8 */
	struct timespec            st_atim;              /*    72    16 */
	struct timespec            st_mtim;              /*    88    16 */
	struct timespec            st_ctim;              /*   104    16 */
	int                        __glibc_reserved[2];  /*   120     8 */

	/* size: 128, cachelines: 2, members: 16 */
};

This commit also updates the unit test for FileStat to include a test to
verify nlink values - this was failing prior to this update.

Relates: #164

The struct layout for aarch64 linux does not match that on AWS graviton2 nodes,
missing several entries.

This commit updates the layout to match the `stat` structure obtained from the
device:

```
pahole -C stat /usr/lib/debug/lib64/libc.so.6.debug

struct stat {
	__dev_t                    st_dev;               /*     0     8 */
	__ino_t                    st_ino;               /*     8     8 */
	__mode_t                   st_mode;              /*    16     4 */
	__nlink_t                  st_nlink;             /*    20     4 */
	__uid_t                    st_uid;               /*    24     4 */
	__gid_t                    st_gid;               /*    28     4 */
	__dev_t                    st_rdev;              /*    32     8 */
	__dev_t                    __pad1;               /*    40     8 */
	__off_t                    st_size;              /*    48     8 */
	__blksize_t                st_blksize;           /*    56     4 */
	int                        __pad2;               /*    60     4 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	__blkcnt_t                 st_blocks;            /*    64     8 */
	struct timespec            st_atim;              /*    72    16 */
	struct timespec            st_mtim;              /*    88    16 */
	struct timespec            st_ctim;              /*   104    16 */
	int                        __glibc_reserved[2];  /*   120     8 */

	/* size: 128, cachelines: 2, members: 16 */
};
```

This commit also updates the unit test for FileStat to include a test to
verify `nlink` values - this was failing prior to this update.
@headius
Copy link
Member

headius commented Jun 1, 2021

Thanks again! This is the layout for glibc, I assume. Do we need to verify that any other libc are different, like musl?

@headius headius merged commit deb2f88 into jnr:master Jun 1, 2021
@headius headius added this to the 3.1.7 milestone Jun 1, 2021
@robbavey
Copy link
Contributor Author

robbavey commented Jun 2, 2021

@headius Thanks for the quick merge! You are correct, this is the layout for glibc.
I'm not particuarly familiar with musl, but I just quickly installed it on an aarm64 node, and the shape looks broadly the same:

/usr/include/aarch64-linux-musl/bits/stat.h:

struct stat {
        dev_t st_dev;
        ino_t st_ino;
        mode_t st_mode;
        nlink_t st_nlink;
        uid_t st_uid;
        gid_t st_gid;
        dev_t st_rdev;
        unsigned long __pad;
        off_t st_size;
        blksize_t st_blksize;
        int __pad2;
        blkcnt_t st_blocks;
        struct timespec st_atim;
        struct timespec st_mtim;
        struct timespec st_ctim;
        unsigned __unused[2];
};

Diff:

struct stat {
        dev_t st_dev;
        ino_t st_ino;
        mode_t st_mode;
        nlink_t st_nlink;
        uid_t st_uid;
        gid_t st_gid;
        dev_t st_rdev;
+      unsigned long __pad;
-       __dev_t  __pad1;
        off_t st_size;
        blksize_t st_blksize;
        int __pad2;
        blkcnt_t st_blocks;
        struct timespec st_atim;
        struct timespec st_mtim;
        struct timespec st_ctim;
+      unsigned __unused[2];
-       int __glibc_reserved[2];
};

@headius
Copy link
Member

headius commented Jun 2, 2021

Thanks for the extra footwork! Those diffs seem like no problem.

@zunley
Copy link
Contributor

zunley commented Jun 3, 2021

aarch64 stat layout in glibc
aarch64 stat layout in musl
There are consistant.

@headius
Copy link
Member

headius commented Jun 3, 2021

@shanjiantao Thank you!

@headius
Copy link
Member

headius commented Jun 3, 2021

I will be pushing out a round of JNR releases today or tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Struct layout for LinuxFileStatAARCH64 does not match that on Amazon Graviton2 nodes
3 participants