<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/scripts/genksyms/genksyms.c, branch linux-7.0.y</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=linux-7.0.y</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=linux-7.0.y'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2025-06-07T05:38:07+00:00</updated>
<entry>
<title>genksyms: Fix enum consts from a reference affecting new values</title>
<updated>2025-06-07T05:38:07+00:00</updated>
<author>
<name>Petr Pavlu</name>
<email>petr.pavlu@suse.com</email>
</author>
<published>2025-06-03T13:02:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=c50a04f8f45c7f13972f9097622d1d929033ea8c'/>
<id>urn:sha1:c50a04f8f45c7f13972f9097622d1d929033ea8c</id>
<content type='text'>
Enumeration constants read from a symbol reference file can incorrectly
affect new enumeration constants parsed from an actual input file.

Example:

 $ cat test.c
 enum { E_A, E_B, E_MAX };
 struct bar { int mem[E_MAX]; };
 int foo(struct bar *a) {}
 __GENKSYMS_EXPORT_SYMBOL(foo);

 $ cat test.c | ./scripts/genksyms/genksyms -T test.0.symtypes
 #SYMVER foo 0x070d854d

 $ cat test.0.symtypes
 E#E_MAX 2
 s#bar struct bar { int mem [ E#E_MAX ] ; }
 foo int foo ( s#bar * )

 $ cat test.c | ./scripts/genksyms/genksyms -T test.1.symtypes -r test.0.symtypes
 &lt;stdin&gt;:4: warning: foo: modversion changed because of changes in enum constant E_MAX
 #SYMVER foo 0x9c9dfd81

 $ cat test.1.symtypes
 E#E_MAX ( 2 ) + 3
 s#bar struct bar { int mem [ E#E_MAX ] ; }
 foo int foo ( s#bar * )

The __add_symbol() function includes logic to handle the incrementation of
enumeration values, but this code is also invoked when reading a reference
file. As a result, the variables last_enum_expr and enum_counter might be
incorrectly set after reading the reference file, which later affects
parsing of the actual input.

Fix the problem by splitting the logic for the incrementation of
enumeration values into a separate function process_enum() and call it from
__add_symbol() only when processing non-reference data.

Fixes: e37ddb825003 ("genksyms: Track changes to enum constants")
Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
<entry>
<title>genksyms: use uint32_t instead of unsigned long for calculating CRC</title>
<updated>2025-01-10T14:01:22+00:00</updated>
<author>
<name>Masahiro Yamada</name>
<email>masahiroy@kernel.org</email>
</author>
<published>2025-01-03T07:30:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a56fece7f302ff1eb49535e66bdd5d03ced0ca20'/>
<id>urn:sha1:a56fece7f302ff1eb49535e66bdd5d03ced0ca20</id>
<content type='text'>
Currently, 'unsigned long' is used for intermediate variables when
calculating CRCs.

The size of 'long' differs depending on the architecture: it is 32 bits
on 32-bit architectures and 64 bits on 64-bit architectures.

The CRC values generated by genksyms represent the compatibility of
exported symbols. Therefore, reproducibility is important. In other
words, we need to ensure that the output is the same when the kernel
source is identical, regardless of whether genksyms is running on a
32-bit or 64-bit build machine.

Fortunately, the output from genksyms is not affected by the build
machine's architecture because only the lower 32 bits of the
'unsigned long' variables are used.

To make it even clearer that the CRC calculation is independent of
the build machine's architecture, this commit explicitly uses the
fixed-width type, uint32_t.

Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
<entry>
<title>genksyms: use generic macros for hash table implementation</title>
<updated>2025-01-10T14:01:22+00:00</updated>
<author>
<name>Masahiro Yamada</name>
<email>masahiroy@kernel.org</email>
</author>
<published>2025-01-03T07:30:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=2759bd908f3cc8d286e1fa64ec7ee7f5d1124837'/>
<id>urn:sha1:2759bd908f3cc8d286e1fa64ec7ee7f5d1124837</id>
<content type='text'>
Use macros provided by hashtable.h

Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
<entry>
<title>genksyms: refactor the return points in the for-loop in __add_symbol()</title>
<updated>2025-01-10T14:01:22+00:00</updated>
<author>
<name>Masahiro Yamada</name>
<email>masahiroy@kernel.org</email>
</author>
<published>2025-01-03T07:30:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=2480f53f21b21eb24a33815d4623f54fdb30cf27'/>
<id>urn:sha1:2480f53f21b21eb24a33815d4623f54fdb30cf27</id>
<content type='text'>
free_list() must be called before returning from this for-loop.

Swap 'break' and the combination of free_list() and 'return'.

This reduces the code and minimizes the risk of introducing memory
leaks in future changes.

Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
<entry>
<title>genksyms: reduce the indentation in the for-loop in __add_symbol()</title>
<updated>2025-01-10T14:01:22+00:00</updated>
<author>
<name>Masahiro Yamada</name>
<email>masahiroy@kernel.org</email>
</author>
<published>2025-01-03T07:30:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f034d186bf9e2857079815e5490e2810a1a287a6'/>
<id>urn:sha1:f034d186bf9e2857079815e5490e2810a1a287a6</id>
<content type='text'>
To improve readability, reduce the indentation as follows:

  - Use 'continue' earlier when the symbol does not match

  - flip !sym-&gt;is_declared to flatten the if-else chain

No functional changes are intended.

Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
<entry>
<title>genksyms: fix memory leak when the same symbol is read from *.symref file</title>
<updated>2025-01-10T14:01:22+00:00</updated>
<author>
<name>Masahiro Yamada</name>
<email>masahiroy@kernel.org</email>
</author>
<published>2025-01-03T07:30:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=be2fa44b5180a1f021efb40c55fdf63c249c3209'/>
<id>urn:sha1:be2fa44b5180a1f021efb40c55fdf63c249c3209</id>
<content type='text'>
When a symbol that is already registered is read again from *.symref
file, __add_symbol() removes the previous one from the hash table without
freeing it.

[Test Case]

  $ cat foo.c
  #include &lt;linux/export.h&gt;
  void foo(void);
  void foo(void) {}
  EXPORT_SYMBOL(foo);

  $ cat foo.symref
  foo void foo ( void )
  foo void foo ( void )

When a symbol is removed from the hash table, it must be freed along
with its -&gt;name and -&gt;defn members. However, sym-&gt;name cannot be freed
because it is sometimes shared with node-&gt;string, but not always. If
sym-&gt;name and node-&gt;string share the same memory, free(sym-&gt;name) could
lead to a double-free bug.

To resolve this issue, always assign a strdup'ed string to sym-&gt;name.

Fixes: 64e6c1e12372 ("genksyms: track symbol checksum changes")
Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
<entry>
<title>genksyms: fix memory leak when the same symbol is added from source</title>
<updated>2025-01-10T14:01:22+00:00</updated>
<author>
<name>Masahiro Yamada</name>
<email>masahiroy@kernel.org</email>
</author>
<published>2025-01-03T07:30:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=45c9c4101d3d2fdfa00852274bbebba65fcc3cf2'/>
<id>urn:sha1:45c9c4101d3d2fdfa00852274bbebba65fcc3cf2</id>
<content type='text'>
When a symbol that is already registered is added again, __add_symbol()
returns without freeing the symbol definition, making it unreachable.

The following test cases demonstrate different memory leak points.

[Test Case 1]

Forward declaration with exactly the same definition

  $ cat foo.c
  #include &lt;linux/export.h&gt;
  void foo(void);
  void foo(void) {}
  EXPORT_SYMBOL(foo);

[Test Case 2]

Forward declaration with a different definition (e.g. attribute)

  $ cat foo.c
  #include &lt;linux/export.h&gt;
  void foo(void);
  __attribute__((__section__(".ref.text"))) void foo(void) {}
  EXPORT_SYMBOL(foo);

[Test Case 3]

Preserving an overridden symbol (compile with KBUILD_PRESERVE=1)

  $ cat foo.c
  #include &lt;linux/export.h&gt;
  void foo(void);
  void foo(void) { }
  EXPORT_SYMBOL(foo);

  $ cat foo.symref
  override foo void foo ( int )

The memory leaks in Test Case 1 and 2 have existed since the introduction
of genksyms into the kernel tree. [1]

The memory leak in Test Case 3 was introduced by commit 5dae9a550a74
("genksyms: allow to ignore symbol checksum changes").

When multiple init_declarators are reduced to an init_declarator_list,
the decl_spec must be duplicated. Otherwise, the following Test Case 4
would result in a double-free bug.

[Test Case 4]

  $ cat foo.c
  #include &lt;linux/export.h&gt;

  extern int foo, bar;

  int foo, bar;
  EXPORT_SYMBOL(foo);

In this case, 'foo' and 'bar' share the same decl_spec, 'int'. It must
be unshared before being passed to add_symbol().

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=46bd1da672d66ccd8a639d3c1f8a166048cca608

Fixes: 5dae9a550a74 ("genksyms: allow to ignore symbol checksum changes")
Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
<entry>
<title>genksyms: reduce indentation in export_symbol()</title>
<updated>2024-11-27T23:46:02+00:00</updated>
<author>
<name>Masahiro Yamada</name>
<email>masahiroy@kernel.org</email>
</author>
<published>2024-11-21T23:22:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=091aa11a2983cdc608f3978d365f5479e78917d8'/>
<id>urn:sha1:091aa11a2983cdc608f3978d365f5479e78917d8</id>
<content type='text'>
Modify this function to return earlier when find_symbol() returns NULL,
reducing the level of improve readability.

No functional changes are intended.

Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
<entry>
<title>genksyms: use getopt_long() unconditionally</title>
<updated>2023-11-28T02:22:50+00:00</updated>
<author>
<name>Masahiro Yamada</name>
<email>masahiroy@kernel.org</email>
</author>
<published>2023-11-05T07:52:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=96a29581e735bcf3b4e5a4f2daad9f445025f510'/>
<id>urn:sha1:96a29581e735bcf3b4e5a4f2daad9f445025f510</id>
<content type='text'>
getopt_long() is used by various tools in the kernel (e.g. Kconfig).

It should be fine to use it all the time.

Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
<entry>
<title>genksyms: remove the remnant of the -s option</title>
<updated>2023-11-28T02:22:50+00:00</updated>
<author>
<name>Masahiro Yamada</name>
<email>masahiroy@kernel.org</email>
</author>
<published>2023-11-05T07:52:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a19937d829fbe3103e4596c8810a3e5cb372c6d4'/>
<id>urn:sha1:a19937d829fbe3103e4596c8810a3e5cb372c6d4</id>
<content type='text'>
Commit 74d931716151 ("genksyms: remove symbol prefix support") removed
the -s (--symbol-prefix) option.

Clean up the left-over.

Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
</feed>
