Skip to content

[BUG] Call graph (C): indirect calls through function pointers and dispatch tables are not linked to their implementations (unverified hypothesis) #8956

Closed

Description

@squid-protocol

Summary

In C, a call through a struct member, a table entry or a callback argument names a function only at runtime. The engine records the member name as a call (for example do_recv), and that name does not match any repository definition, so the row lands in fcall_external and no edge reaches the function that the table really holds. In the curl scan, the member-call names that have a definition elsewhere in the repo are recorded as external, not linked. This is consistent with lower-bound PageRank, fan-in, and blast-radius numbers for C, but this issue is a hypothesis. Nobody has hand-checked a sample of dispatch call sites against the graph. Acceptance step 1 does that check before any fix is designed.

Note on the root cause: the code reading below explains why such edges are missing, but the mechanism has not been confirmed by a fix or a sample. Do not treat it as settled.

Class: indirect-call resolution gaps

The class is "a call whose callee is named only through a value at runtime". Members differ in syntax but share one question: does the resolver connect the caller to the implementation the value points to?

form example status evidence
struct-member function pointer, member access cf->next->cft->do_recv(cf->next, data, buf, len, pnread) not resolved (name recorded, no edge to implementations) lib/cfilters.h:221 (struct Curl_cftype, 14 function-pointer members); 87 cft->name( call lines in 21 files (study clone, HEAD 3dde2fb68); study DB: do_recv 8 external callers, 0 resolved edges; has_data_pending 16 / 0; query 28 / 0; do_send 8 / 0
dispatch through a scheme table conn->scheme->run->connect_it(data, protocol_done) not resolved lib/multi.c:1956, lib/url.c:2244; struct Curl_protocol at lib/protocol.h:115, struct Curl_scheme at lib/protocol.h:250; study DB: connect_it 2 external, 0 resolved
callback passed as an argument, or a table initializer { ..., cf_tcp_connect, ... } register_cb(foo);, static const struct Curl_cftype X = {..., foo, ...} not resolved C reference edges are off (reference_edges is set only in languages/python.py:97 and languages/embedded_python.py:75; gitgalaxy/core/detector.py:9494 gates on it). The C call pattern is \b(ident)\s*\( (_shared_patterns.py:253), so a bare name with no ( produces no row. Read from code; not run on a C sample
parenthesised deref call (*fp)(x) (*handler)(ctx) not resolved (no name captured for fp) same pattern: the name must be followed by (; in (*fp)(x) it is followed by ). Read from code; not run
local or parameter function pointer called by name fp(x) cb(data) partial, unverified: recorded as a call to cb; links only if the repo defines a function cb (wrong link possible, not measured) CALLS_OUT_C_STYLE as above; gitgalaxy/core/call_resolver.py ladder (docs/function_call_graph.md, "How a call is linked")
macro-wrapped call, object-like redirect #define xmalloc malloc partial: literal name counted, which allocator runs is invisible docs/known_blind_spots.md:119
macro-wrapped call, function-like alias #define failf(...) Curl_failf(...) partial: #7828 (closed) fixed one alias case; coverage not re-measured here docs/known_blind_spots.md:119-121; #7828
C platform variants (same name defined per OS) libuv uv__io_poll handled as variant candidates, not confident edges docs/function_call_graph.md, fcall_candidates (#8161)
Python function values (key=sort_key, Depends(get_db)) handled (reference edges; 99.7% precision on 323 judged, fastapi) docs/function_call_graph.md:83, and the references row at ~line 117-118
Java interface and virtual dispatch x.save() on an interface ambiguous by design (receiver row, never an edge) docs/function_call_graph.md:62
Python getattr, dicts of callables out of reach, documented docs/function_call_graph.md:139
C++ virtual / function-object dispatch, Go and Rust function values unverified in this issue not measured here

Why this matters for the C numbers: the libclang reference used to score C skips calls through a pointer: docs/graph_accuracy.md:268 ("A call through a function pointer names no function and is skipped"). So the C recall figures (tests/call_graph_resolution_c_baseline.json: recall_pct 50.8, resolution_recall_pct 55.3, libclang 18.1.1; the 66% for C in #8161 is a separate 20-repo run) cannot see these forms at all. The DOOM oracle also reports pointer references as function-pointer edges and does not score them (tests/tools/doom_speedrun/callgraph_oracle.py:419-424, doom_scorer.py:234; the convention was left open in #5874 and the kind is excluded by #6266). No existing gate measures recall on dispatch-table calls.

Sibling-language equivalents (to verify, not assumed): the same class in Go (function values in struct fields), Rust (Box<dyn Fn> fields), C++ (virtual calls through base pointers, function objects) and JavaScript (object-literal callbacks, def_shape: member, docs/function_call_graph.md). Mark each unverified until a sample is hand-checked.

Evidence in hand (curl, study clone at HEAD 3dde2fb68)

  • The member-call names above are recorded as fcall_external callers and have no resolved edges.
  • One name has both: do_connect, 11 external member-call sites (cf->next->cft->do_connect(), and one resolved edge cf_tcp_connect -> do_connect in lib/cf-socket.c at step file. That edge is a genuine direct call in the same file. So in this sample the failure mode is missing edges, not wrong ones. No wrong link was observed among the sampled names.
  • The implementations that the tables hold (for example cf_recvbuf_recv in lib/cf-recvbuf.c:52) are never linked from the call sites. Table initializers are not read as edges.

These are counts from the scan DB and reads of the source, not a measured recall. They do not show how many real calls are missed in total.

Acceptance

  1. Hand-checked sample (the first deliverable, no engine change). Pick 20 curl dispatch call sites (10 cft-> form, 10 ->run-> or other table form) and 10 table initializers. For each call site, read the table initializer that the pointer holds at that call (for example the Curl_cft_tcp filter type), name the implementation, and check whether the graph links the caller to it. Record a table: form x (linked / external / absent / wrong). Post it on this issue.
  2. Mechanism check. From the sample, state whether the missing edges come from (a) member-call names not matched to implementations, (b) table initializers not read as references, or (c) something else. A cause is "confirmed" only if the sample shows it.
  3. Recall gate blind spot. Record in docs/graph_accuracy.md (C section, ~line 256) that the libclang gate does not score pointer calls, with the number from step 1. Do not change the gate in this issue.
  4. Decide the design in a separate issue. Candidate mechanisms (a C reference kind for table initializers and callback arguments, a fp( variable rule) need their own design and a measured precision. A new edge kind changes the graph and needs a golden re-bless with the drift attributed (CLAUDE.md, "Differential Scan").
  5. Wrong-link check. Any new rule must show wrong links are not added: a fp(x) name that matches an unrelated repo function is the first case to test.

Discrepancies found while checking the study's claims

  • The study's first summary named the protocol handler struct struct Curl_handler, from memory of older curl versions, and that was wrong for the study clone. At 3dde2fb68 the tables are struct Curl_protocol (lib/protocol.h:115) and struct Curl_scheme (lib/protocol.h:250). The names depend on the commit being scanned.
  • The study's first C call-site row (total 31,925; external 12,521, 39%) came from a first curl scan that still included tests/ and the Python and Perl test harness. The later scans, with test, doc and vendored directories removed, give total 22,994, scoped 11,211, unique 2,067, ambiguous 36, external 9,680 (42%); the two test-free scans agree. Quote the test-free row, and say which directories were removed (see the tooling issue filed from the same study).
  • The study's first summary cited 13 multi-function call cycles in curl, from the same first scan that included tests/. The test-free scan reports 11 (50 functions).

Remaining siblings (not filed here)

Labels and milestone

  • bug: the graph misses a class of edges the reference-free engine could resolve; no claim of a regression.
  • call-graph is the area label (no description in the repo label list). core-engine for the extractor and resolver.
  • Milestone "Compiler call-graph comparison" (chore(deps): bump actions/checkout from 4 to 6 #14), as the call-graph skills cite it.

Generated by Claude Code

Activity

  1. added
    bug
    core-engine
    on Nov 22, 2026
  2. squid-protocol commented on Nov 22, 2026

    @squid-protocol
    OwnerAuthor

    Cross-links. These four issues came out of one study (fix history vs call-graph structure; 30 repositories in C, Go and Java). Read them together:

    Order that makes sense: #8956 step 1 (hand-checked sample) tells us how far to trust the graph; #8957 and #8958 can land independently; #8955 should wait for the #8956 sample.


    Generated by Claude Code

  3. squid-protocol commented on Nov 22, 2026

    @squid-protocol
    OwnerAuthor

    Acceptance #1 & #2: Hand-checked sample on curl (01798a0)

    Scanned curl at 01798a0 with galaxyscope --db-only --offline (2,329 files mapped) and checked 20 dispatch call sites (10 cft->, 10 ->run->) and 10 table initializers (6 Curl_cftype, 4 Curl_protocol).

    20 Dispatch Call Sites

    Form Call site Enclosing function Member called Status Notes
    cft-> lib/vtls/vtls.c:948 ssl_cf_connect do_connect external in_cout=True, fcall_external (2 callers in file)
    cft-> lib/vtls/vtls.c:1083 ssl_cf_data_pending has_data_pending external in_cout=True, fcall_external
    cft-> lib/vtls/vtls.c:1233 ssl_cf_query query external in_cout=True, fcall_external
    cft-> lib/vtls/openssl.c:1902 ossl_shutdown is_alive external in_cout=True, fcall_external
    cft-> lib/vtls/wolfssl.c:1912 wssl_shutdown is_alive external in_cout=True, fcall_external
    cft-> lib/vquic/cf-quiche.c:1598 cf_quiche_query query external in_cout=True, fcall_external
    cft-> lib/vquic/cf-capsule.c:67 cf_capsule_connect do_connect external in_cout=True, fcall_external
    cft-> lib/socks.c:1194 socks_proxy_cf_connect do_connect external in_cout=True, fcall_external
    cft-> lib/http_proxy.c:477 http_proxy_cf_connect do_connect external in_cout=True, fcall_external
    cft-> lib/http2.c:563 http2_connisalive is_alive external in_cout=True, fcall_external
    ->run-> lib/url.c:499 Curl_conn_free disconnect external in_cout=True, fcall_external
    ->run-> lib/url.c:1483 setup_connection_internals setup_connection external in_cout=True, fcall_external
    ->run-> lib/url.c:2244 url_find_or_create_conn connect_it external in_cout=True, fcall_external
    ->run-> lib/url.c:2264 url_find_or_create_conn done external in_cout=True, fcall_external
    ->run-> lib/transfer.c:720 Curl_xfer_write_resp write_resp external in_cout=True, fcall_external
    ->run-> lib/transfer.c:755 Curl_xfer_write_resp_hd write_resp_hd external in_cout=True, fcall_external
    ->run-> lib/multi.c:966 Curl_attach_connection attach external in_cout=True, fcall_external
    ->run-> lib/multi.c:1817 multi_do do_it external in_cout=True, fcall_external
    ->run-> lib/multi.c:1910 protocol_connecting connecting external in_cout=True, fcall_external
    ->run-> lib/cshutdn.c:107 cshutdn_run_conn_handler disconnect external in_cout=True, fcall_external

    Summary by form:

    Form Linked External Absent Wrong
    cft-> (10) 0 10 0 0
    ->run-> (10) 0 10 0 0
    Total (20) 0 20 0 0

    10 Table Initializers

    Initializer File Sampled implementations (fcall_data incoming edge count across repo)
    Curl_cft_tcp lib/cf-socket.c:1921 cf_tcp_connect(0), cf_socket_send(0), cf_socket_recv(0), cf_socket_query(0)
    Curl_cft_udp lib/cf-socket.c:2136 cf_udp_connect(0), cf_socket_send(0), cf_socket_recv(0), cf_socket_query(0)
    Curl_cft_ssl lib/vtls/vtls.c:1269 ssl_cf_connect(1)*, ssl_cf_send(0), ssl_cf_recv(0), ssl_cf_query(0)
    Curl_cft_nghttp2 lib/http2.c:2813 cf_h2_connect(0), cf_h2_send(0), cf_h2_recv(0), cf_h2_is_alive(0)
    Curl_cft_http_proxy lib/http_proxy.c:621 http_proxy_cf_connect(0), cf_http_proxy_query(0)
    Curl_cft_socks_proxy lib/socks.c:1312 socks_proxy_cf_connect(0), socks_cf_query(0)
    Curl_protocol_tftp lib/tftp.c:1343 tftp_setup_connection(0), tftp_do(0), tftp_connect(1)*, tftp_done(0)
    Curl_protocol_smtp lib/smtp.c:1996 smtp_setup_connection(0), smtp_do(0), smtp_connect(0), smtp_disconnect(0)
    Curl_protocol_imap lib/imap.c:2310 imap_setup_connection(0), imap_do(0), imap_connect(0), imap_disconnect(0)
    Curl_protocol_ws lib/ws.c:2112 ws_setup_conn(0), Curl_http(0), Curl_http_done(1)*, Curl_http_write_resp(0)

    * The 3 implementations with in=1 (ssl_cf_connect, tftp_connect, Curl_http_done) each have 1 direct call elsewhere, not from the table initializer; 0/10 initializers emit any edge and 33/36 sampled implementations have func_fan_in = 0.

    Confirmed Mechanism

    Both (a) and (b) are confirmed:

    1. (a) Every sampled dispatch call site is extracted into calls_out_to under its struct-member name (do_connect, query, connect_it, do_it, etc.), which matches no repo function definition and lands in fcall_external (20/20 external, 0 wrong links).
    2. (b) C struct table initializers are not read as function references (reference_edges is disabled for C and CALLS_OUT_C_STYLE requires (), so 0/10 tables link to their implementations.

    Opening a docs PR to record this libclang blind spot in docs/graph_accuracy.md (Acceptance #3).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcall-graphcore-enginepriority: medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions