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

Fix redeclaration of RecordDecl in Records defined in array variables #4

Merged

Conversation

giulianobelinassi
Copy link
Collaborator

There are some cases where a variable is declared as follows:

  static const struct mount_opts
  {
    int token;
    int mount_opts;
    int flags;
  } ext4_mount_opts[] = {
    {1, 1, 1}
  };

in this case, the ext4_mount_opts array is declared together with its type, thus resulting in Clang splitting this into two decls in its AST:

  struct mount_opts
  {
    int token;
    int mount_opts;
    int flags;
  };

  static const struct ext4_mount_opts[] = {
    {1, 1, 1}
  };

but since we try to get what the user wrote, it results in two declarations of struct mount_opts, thus clang-extract fails because of a redeclaration error. But since ext4_mount_opts is an array, geting its type returns an array type, not the struct declaration itself, hence check for this case as well.

There are some cases where a variable is declared as follows:

  static const struct mount_opts
  {
    int token;
    int mount_opts;
    int flags;
  } ext4_mount_opts[] = {
    {1, 1, 1}
  };

in this case, the `ext4_mount_opts` array is declared together with its
type, thus resulting in Clang splitting this into two decls in its AST:

  struct mount_opts
  {
    int token;
    int mount_opts;
    int flags;
  };

  static const struct ext4_mount_opts[] = {
    {1, 1, 1}
  };

but since we try to get what the user wrote, it results in two declarations
of `struct mount_opts`, thus clang-extract fails because of a redeclaration
error. But since `ext4_mount_opts` is an array, geting its type returns
an array type, not the struct declaration itself, hence check for this
case as well.

Signed-off-by: Giuliano Belinassi <gbelinassi@suse.de>
@marcosps
Copy link
Collaborator

Now it shows a different issue regarding symbol renaming =/

@giulianobelinassi
Copy link
Collaborator Author

What issue?

@marcosps
Copy link
Collaborator

What issue?

With the resolved issue, now it reports missing symbol:

/home/mpdesouza/kgr/data/x86_64/usr/src/linux-4.12.14-122.150/fs/ext4/super.c:2702:16: error: use of undeclared identifier 'ext4_remount'; did you mean 'ext4_mount'?                                                                                                   
        .remount_fs     = ext4_remount,                                                                                             
                          ^~~~~~~~~~~~                                                                                              
                          ext4_mount                                                                                                
/home/mpdesouza/kgr/data/x86_64/usr/src/linux-4.12.14-122.150/fs/ext4/super.c:1941:23: note: 'ext4_mount' declared here             
static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,                                                       
                      ^                                                                                                             
/home/mpdesouza/kgr/data/x86_64/usr/src/linux-4.12.14-122.150/fs/ext4/super.c:2702:16: error: incompatible function pointer types initializing 'int (*)(struct super_block *, int *, char *)' with an expression of type 'struct dentry *(struct file_system_type *, int, const char *, void *)'                                                                                                            
        .remount_fs     = ext4_remount,                                                                                             
                          ^~~~~~~~~~~~                                                                                              
                                                                                                                                    
Error on pass: FunctionExternalizerPass 

But the symbol is there, and it's also present in the ext4.ko module too.

@giulianobelinassi
Copy link
Collaborator Author

What issue?

With the resolved issue, now it reports missing symbol:

/home/mpdesouza/kgr/data/x86_64/usr/src/linux-4.12.14-122.150/fs/ext4/super.c:2702:16: error: use of undeclared identifier 'ext4_remount'; did you mean 'ext4_mount'?                                                                                                   
        .remount_fs     = ext4_remount,                                                                                             
                          ^~~~~~~~~~~~                                                                                              
                          ext4_mount                                                                                                
/home/mpdesouza/kgr/data/x86_64/usr/src/linux-4.12.14-122.150/fs/ext4/super.c:1941:23: note: 'ext4_mount' declared here             
static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,                                                       
                      ^                                                                                                             
/home/mpdesouza/kgr/data/x86_64/usr/src/linux-4.12.14-122.150/fs/ext4/super.c:2702:16: error: incompatible function pointer types initializing 'int (*)(struct super_block *, int *, char *)' with an expression of type 'struct dentry *(struct file_system_type *, int, const char *, void *)'                                                                                                            
        .remount_fs     = ext4_remount,                                                                                             
                          ^~~~~~~~~~~~                                                                                              
                                                                                                                                    
Error on pass: FunctionExternalizerPass 

But the symbol is there, and it's also present in the ext4.ko module too.

This seems to be another issue. Perhaps open another issue with more details of this problem?

@marcosps
Copy link
Collaborator

Sure, I'll check this again once I start working on this livepatch again.

@marcosps
Copy link
Collaborator

marcosps commented Apr 1, 2024

@giulianobelinassi indeed, the error message changes, and it's not a different issue. You can merge this PR as this fixed the original issue.

@giulianobelinassi giulianobelinassi merged commit 3027853 into SUSE:main Apr 1, 2024
2 checks passed
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.

2 participants