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

libc-test: Resolve alias? #4293

Open
farao opened this issue Mar 3, 2025 · 1 comment
Open

libc-test: Resolve alias? #4293

farao opened this issue Mar 3, 2025 · 1 comment

Comments

@farao
Copy link

farao commented Mar 3, 2025

I'm trying to resolve Warnings of libc-test for a uclibc-based OS (x86_64-unknown-l4re-uclibc). Currently, I'm facing a more general issue for which I'm not sure how to fix it:

  1. There is a type alias in the rust files.

Example:

pub type fsword_t = c_long;

Since this is a "helper type" without pendant in the uclibc, I added this to cfg.skip_type(...)

  1. There is a struct using this type alias as a field type

Example:

pub struct statfs {
// FIXME(ulibc)
pub f_type: fsword_t,

  1. Then we have the problem, that the type alias is not resolved

Example:

warning: [email protected]: .../out/main.c:27500:18: error: unknown type name 'fsword_t';
warning: [email protected]: 27500 |                  fsword_t* __test_field_type_statfs_f_type(struct statfs* b) {
warning: [email protected]:       |                  ^~~~~~~~

=> Is there any way how to resolve this problem?

I tried adding the resolving of type aliases to ctest2:

-            s => (self.opts.type_name)(s, self.structs.contains(s), self.unions.contains(s)),
+            s => {
+                let new_s = (self.opts.type_name)(s, self.structs.contains(s), self.unions.contains(s));
+
+                if self.aliases.contains_key(&new_s) {
+                    self.ty2name(self.aliases.get(&new_s).unwrap(), false)
+                } else {
+                    new_s.to_string()
+                }
+            }

at: https://github.com/JohnTitor/ctest2/blob/05634716fbe6f9ea4bf090ce85776269740b1a58/src/lib.rs#L1214

But this brings up new problems, e.g. that types get resolved that were not meant to be resolved, e.g.

pub type Elf32_Rel = __c_anonymous_elf32_rel;

here's the corresponding warning:

   5 warning: [email protected]: .../out/main.c:14500:67: error: invalid application of 'sizeof' to incomplete type 'struct __c_anonymous_elf64_rel'
   6 warning: [email protected]: 14500 |              uint64_t __test_size_Elf32_Rel(void) { return sizeof(struct __c_anonymous_elf64_rel); }

What do you think? Is...

  • resolving the alias the correct move and think about a solution for the followup errors?
  • or is there an easy solution for the original problem that does not need changes in ctest2?
@tgross35
Copy link
Contributor

tgross35 commented Mar 4, 2025

Hold off on doing any ctest changes, we'll have that in-repo soon #4283. Does ulibc use this type alias? If our definitions do match libc but ctest is causing problems, then fixing ctest is probably the best way forward.

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

No branches or pull requests

2 participants