Skip to content

[SR-2755] False objc_autoreleaseReturnValue dependency building on Linux #45359

Closed
@swift-ci

Description

@swift-ci
Previous ID SR-2755
Radar None
Original Reporter gmilos (JIRA User)
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @slavapestov
Priority Medium

md5: 89cbd7095952971a44b28957ee5b5db8

relates to:

  • SR-5271 Don't emit objc_retainAutoreleasedReturnValue() on non-ObjC targets

Issue Description:

When building Swift code, which calls to a C API taking block with block return value, generates false objc_autoreleaseReturnValue dependency.

From the attached minimal reproduction:

sbs:/tmp/objc_autoreleaseReturnValue_bug$
cat CStuff/c-stuff.c
#include "c-stuff.h"

#ifdef DEFINE_AUTORELEASE_RETURN_VALUE
void *objc_autoreleaseReturnValue(void * a) {
return a;
}
#endif

void bar(SomeBlock b) {
b();
}
sbs:/tmp/objc_autoreleaseReturnValue_bug$
cat CStuff/c-stuff.h
#ifndef C_STUFF
#define C_STUFF

typedef void(^SomeOtherBlock)(void);
typedef SomeOtherBlock(^SomeBlock)(void);
void bar(SomeBlock b);

#endif
sbs:/tmp/objc_autoreleaseReturnValue_bug$
cat
CStuff/ libCStuff.so Makefile test.o test.swift
sbs:/tmp/objc_autoreleaseReturnValue_bug$
cat test.swift
import Dispatch
import CStuff

bar({ return {} })
sbs:/tmp/objc_autoreleaseReturnValue_bug$
make
swiftc -lswiftCore -lswiftSwiftOnoneSupport -o test test.o libCStuff.so
test.o:test.o:function TTRXFooGSqFT_TXFdCbaGSqbT_T**_: error: undefined reference to 'objc_autoreleaseReturnValue'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 1

The objc_autoreleaseReturnValue dependency doesn't exist on Linux. I was able to verify that the code builds and works when defining the symbol myself (simple identity function). This can be tested building with make clean && make CFLAGS=-DDEFINE_AUTORELEASE_RETURN_VALUE

Explicit Block_retain/Block_release should be used to manage return value lifecycle instead.

Metadata

Metadata

Assignees

Labels

IRGenLLVM IR generationLinuxPlatform: LinuxbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselflinker errorobjective-c interopFeature: Interoperability with Objective-Cswift 5.10

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions